mirror of
https://github.com/swaywm/sway.git
synced 2026-04-28 06:46:26 -04:00
extracted view_set_floating
This commit is contained in:
parent
eac0920f49
commit
4e0a3b9c72
3 changed files with 72 additions and 50 deletions
|
|
@ -30,4 +30,6 @@ swayc_t *get_swayc_in_direction(swayc_t *container, enum movement_direction dir)
|
||||||
|
|
||||||
void recursive_resize(swayc_t *container, double amount, enum wlc_resize_edge edge);
|
void recursive_resize(swayc_t *container, double amount, enum wlc_resize_edge edge);
|
||||||
|
|
||||||
|
void view_set_floating(swayc_t *view, bool floating);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -197,58 +197,26 @@ static bool cmd_floating(struct sway_config *config, int argc, char **argv) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcasecmp(argv[0], "toggle") == 0) {
|
|
||||||
swayc_t *view = get_focused_container(&root_container);
|
swayc_t *view = get_focused_container(&root_container);
|
||||||
// Prevent running floating commands on things like workspaces
|
|
||||||
if (view->type != C_VIEW) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
// Change from nonfloating to floating
|
|
||||||
if (!view->is_floating) {
|
|
||||||
// Remove view from its current location
|
|
||||||
destroy_container(remove_child(view));
|
|
||||||
|
|
||||||
// and move it into workspace floating
|
bool floating;
|
||||||
add_floating(swayc_active_workspace(),view);
|
if (strcasecmp(argv[0], "toggle") != 0) {
|
||||||
view->x = (swayc_active_workspace()->width - view->width)/2;
|
floating = !view->is_floating;
|
||||||
view->y = (swayc_active_workspace()->height - view->height)/2;
|
|
||||||
if (view->desired_width != -1) {
|
|
||||||
view->width = view->desired_width;
|
|
||||||
}
|
}
|
||||||
if (view->desired_height != -1) {
|
else if (strcasecmp(argv[0], "enable") != 0) {
|
||||||
view->height = view->desired_height;
|
floating = true;
|
||||||
}
|
}
|
||||||
arrange_windows(swayc_active_workspace(), -1, -1);
|
else if (strcasecmp(argv[0], "disable") != 0) {
|
||||||
} else {
|
floating = false;
|
||||||
// Delete the view from the floating list and unset its is_floating flag
|
|
||||||
// Using length-1 as the index is safe because the view must be the currently
|
|
||||||
// focused floating output
|
|
||||||
remove_child(view);
|
|
||||||
view->is_floating = false;
|
|
||||||
// Get the properly focused container, and add in the view there
|
|
||||||
swayc_t *focused = container_under_pointer();
|
|
||||||
// If focused is null, it's because the currently focused container is a workspace
|
|
||||||
if (focused == NULL) {
|
|
||||||
focused = swayc_active_workspace();
|
|
||||||
}
|
}
|
||||||
set_focused_container(focused);
|
|
||||||
|
|
||||||
sway_log(L_DEBUG, "Non-floating focused container is %p", focused);
|
|
||||||
|
|
||||||
// Case of focused workspace, just create as child of it
|
|
||||||
if (focused->type == C_WORKSPACE) {
|
|
||||||
add_child(focused, view);
|
|
||||||
}
|
|
||||||
// Regular case, create as sibling of current container
|
|
||||||
else {
|
else {
|
||||||
add_sibling(focused, view);
|
sway_log(L_ERROR, "floating - unknown token '%s', expected one of toggle, enable or disable", argv[0]);
|
||||||
}
|
return false;
|
||||||
// Refocus on the view once its been put back into the layout
|
|
||||||
view->width = view->height = 0;
|
|
||||||
arrange_windows(swayc_active_workspace(), -1, -1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Change from non-floating to floating or vice versa
|
||||||
|
view_set_floating(view, floating);
|
||||||
set_focused_container(view);
|
set_focused_container(view);
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
#include "container.h"
|
#include "container.h"
|
||||||
#include "workspace.h"
|
#include "workspace.h"
|
||||||
#include "focus.h"
|
#include "focus.h"
|
||||||
|
#include "handlers.h"
|
||||||
|
|
||||||
swayc_t root_container;
|
swayc_t root_container;
|
||||||
int min_sane_h = 60;
|
int min_sane_h = 60;
|
||||||
|
|
@ -412,3 +413,54 @@ void recursive_resize(swayc_t *container, double amount, enum wlc_resize_edge ed
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void view_set_floating(swayc_t *view, bool floating) {
|
||||||
|
// Prevent running floating commands on things like workspaces
|
||||||
|
if (view->type != C_VIEW) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (floating) {
|
||||||
|
// Remove view from its current location
|
||||||
|
destroy_container(remove_child(view));
|
||||||
|
|
||||||
|
// and move it into workspace floating
|
||||||
|
add_floating(swayc_active_workspace(),view);
|
||||||
|
view->x = (swayc_active_workspace()->width - view->width)/2;
|
||||||
|
view->y = (swayc_active_workspace()->height - view->height)/2;
|
||||||
|
if (view->desired_width != -1) {
|
||||||
|
view->width = view->desired_width;
|
||||||
|
}
|
||||||
|
if (view->desired_height != -1) {
|
||||||
|
view->height = view->desired_height;
|
||||||
|
}
|
||||||
|
arrange_windows(swayc_active_workspace(), -1, -1);
|
||||||
|
} else {
|
||||||
|
// Delete the view from the floating list and unset its is_floating flag
|
||||||
|
// Using length-1 as the index is safe because the view must be the currently
|
||||||
|
// focused floating output
|
||||||
|
remove_child(view);
|
||||||
|
view->is_floating = false;
|
||||||
|
// Get the properly focused container, and add in the view there
|
||||||
|
swayc_t *focused = container_under_pointer();
|
||||||
|
// If focused is null, it's because the currently focused container is a workspace
|
||||||
|
if (focused == NULL) {
|
||||||
|
focused = swayc_active_workspace();
|
||||||
|
}
|
||||||
|
set_focused_container(focused);
|
||||||
|
|
||||||
|
sway_log(L_DEBUG, "Non-floating focused container is %p", focused);
|
||||||
|
|
||||||
|
// Case of focused workspace, just create as child of it
|
||||||
|
if (focused->type == C_WORKSPACE) {
|
||||||
|
add_child(focused, view);
|
||||||
|
}
|
||||||
|
// Regular case, create as sibling of current container
|
||||||
|
else {
|
||||||
|
add_sibling(focused, view);
|
||||||
|
}
|
||||||
|
// Refocus on the view once its been put back into the layout
|
||||||
|
view->width = view->height = 0;
|
||||||
|
arrange_windows(swayc_active_workspace(), -1, -1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue