cmd_floating: Support `enable` and `disable` commands too.

This is especially relevant in combination with `for_window`, e.g.:
`for_window [title="Terminal"] floating enable`.
master
S. Christoffer Eliesen 9 years ago
parent 04bd9386fe
commit d9770cc243

@ -38,8 +38,8 @@ Commands
**exit**::
Exit sway and end your Wayland session.
**floating** toggle::
Toggles the "floating" status of the focused view.
**floating** <enable|disable|toggle>::
Make focused view floating, non-floating, or the opposite of what it is now.
**floating_modifier** <modifier>::
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))) {
return error;
}
if (strcasecmp(argv[0], "toggle") == 0) {
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
if (view->type != C_VIEW) {
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
// Change from nonfloating to floating
if (!view->is_floating) {
if (!view->is_floating && wants_floating) {
// Remove view from its current location
destroy_container(remove_child(view));
@ -329,7 +340,8 @@ static struct cmd_results *cmd_floating(int argc, char **argv) {
view->height = view->desired_height;
}
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
// Using length-1 as the index is safe because the view must be the currently
// focused floating output
@ -359,7 +371,6 @@ static struct cmd_results *cmd_floating(int argc, char **argv) {
remove_view_from_scratchpad(view);
}
set_focused_container(view);
}
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}

Loading…
Cancel
Save