mirror of
https://github.com/swaywm/sway.git
synced 2025-01-01 18:06:47 +01:00
Merge pull request #263 from sce/floating_enable_disable
cmd_floating: Support `enable` and `disable` commands too.
This commit is contained in:
commit
4c34674255
2 changed files with 66 additions and 55 deletions
|
@ -38,8 +38,8 @@ Commands
|
||||||
**exit**::
|
**exit**::
|
||||||
Exit sway and end your Wayland session.
|
Exit sway and end your Wayland session.
|
||||||
|
|
||||||
**floating** toggle::
|
**floating** <enable|disable|toggle>::
|
||||||
Toggles the "floating" status of the focused view.
|
Make focused view floating, non-floating, or the opposite of what it is now.
|
||||||
|
|
||||||
**floating_modifier** <modifier>::
|
**floating_modifier** <modifier>::
|
||||||
When the _modifier_ key is held down, you may use left click to drag floating
|
When the _modifier_ key is held down, you may use left click to drag floating
|
||||||
|
|
|
@ -306,15 +306,26 @@ static struct cmd_results *cmd_floating(int argc, char **argv) {
|
||||||
if ((error = checkarg(argc, "floating", EXPECTED_EQUAL_TO, 1))) {
|
if ((error = checkarg(argc, "floating", EXPECTED_EQUAL_TO, 1))) {
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcasecmp(argv[0], "toggle") == 0) {
|
|
||||||
swayc_t *view = get_focused_container(&root_container);
|
swayc_t *view = get_focused_container(&root_container);
|
||||||
|
bool wants_floating;
|
||||||
|
if (strcasecmp(argv[0], "enable") == 0) {
|
||||||
|
wants_floating = true;
|
||||||
|
} else if (strcasecmp(argv[0], "disable") == 0) {
|
||||||
|
wants_floating = false;
|
||||||
|
} else if (strcasecmp(argv[0], "toggle") == 0) {
|
||||||
|
wants_floating = !view->is_floating;
|
||||||
|
} else {
|
||||||
|
return cmd_results_new(CMD_FAILURE, "floating",
|
||||||
|
"Expected 'floating <enable|disable|toggle>");
|
||||||
|
}
|
||||||
|
|
||||||
// Prevent running floating commands on things like workspaces
|
// Prevent running floating commands on things like workspaces
|
||||||
if (view->type != C_VIEW) {
|
if (view->type != C_VIEW) {
|
||||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Change from nonfloating to floating
|
// Change from nonfloating to floating
|
||||||
if (!view->is_floating) {
|
if (!view->is_floating && wants_floating) {
|
||||||
// Remove view from its current location
|
// Remove view from its current location
|
||||||
destroy_container(remove_child(view));
|
destroy_container(remove_child(view));
|
||||||
|
|
||||||
|
@ -329,7 +340,8 @@ static struct cmd_results *cmd_floating(int argc, char **argv) {
|
||||||
view->height = view->desired_height;
|
view->height = view->desired_height;
|
||||||
}
|
}
|
||||||
arrange_windows(swayc_active_workspace(), -1, -1);
|
arrange_windows(swayc_active_workspace(), -1, -1);
|
||||||
} else {
|
|
||||||
|
} else if (view->is_floating && !wants_floating) {
|
||||||
// Delete the view from the floating list and unset its is_floating flag
|
// 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
|
// Using length-1 as the index is safe because the view must be the currently
|
||||||
// focused floating output
|
// focused floating output
|
||||||
|
@ -359,7 +371,6 @@ static struct cmd_results *cmd_floating(int argc, char **argv) {
|
||||||
remove_view_from_scratchpad(view);
|
remove_view_from_scratchpad(view);
|
||||||
}
|
}
|
||||||
set_focused_container(view);
|
set_focused_container(view);
|
||||||
}
|
|
||||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue