diff options
author | Drew DeVault <sir@cmpwn.com> | 2015-11-27 09:22:22 -0700 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2015-11-27 09:22:22 -0700 |
commit | 4c3467425567044b4043d034432d78d445b8c641 (patch) | |
tree | e680d1beeef8f8ff6889f863503bc3da11b10bf6 | |
parent | Fix swaygrab memory leak (diff) | |
parent | cmd_floating: Support `enable` and `disable` commands too. (diff) | |
download | sway-4c3467425567044b4043d034432d78d445b8c641.tar.gz sway-4c3467425567044b4043d034432d78d445b8c641.tar.zst sway-4c3467425567044b4043d034432d78d445b8c641.zip |
Merge pull request #263 from sce/floating_enable_disable
cmd_floating: Support `enable` and `disable` commands too.
-rw-r--r-- | sway.5.txt | 4 | ||||
-rw-r--r-- | sway/commands.c | 105 |
2 files changed, 60 insertions, 49 deletions
@@ -38,8 +38,8 @@ Commands | |||
38 | **exit**:: | 38 | **exit**:: |
39 | Exit sway and end your Wayland session. | 39 | Exit sway and end your Wayland session. |
40 | 40 | ||
41 | **floating** toggle:: | 41 | **floating** <enable|disable|toggle>:: |
42 | Toggles the "floating" status of the focused view. | 42 | Make focused view floating, non-floating, or the opposite of what it is now. |
43 | 43 | ||
44 | **floating_modifier** <modifier>:: | 44 | **floating_modifier** <modifier>:: |
45 | When the _modifier_ key is held down, you may use left click to drag floating | 45 | When the _modifier_ key is held down, you may use left click to drag floating |
diff --git a/sway/commands.c b/sway/commands.c index c63aa320..f1dbc09e 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -306,60 +306,71 @@ static struct cmd_results *cmd_floating(int argc, char **argv) { | |||
306 | if ((error = checkarg(argc, "floating", EXPECTED_EQUAL_TO, 1))) { | 306 | if ((error = checkarg(argc, "floating", EXPECTED_EQUAL_TO, 1))) { |
307 | return error; | 307 | return error; |
308 | } | 308 | } |
309 | swayc_t *view = get_focused_container(&root_container); | ||
310 | bool wants_floating; | ||
311 | if (strcasecmp(argv[0], "enable") == 0) { | ||
312 | wants_floating = true; | ||
313 | } else if (strcasecmp(argv[0], "disable") == 0) { | ||
314 | wants_floating = false; | ||
315 | } else if (strcasecmp(argv[0], "toggle") == 0) { | ||
316 | wants_floating = !view->is_floating; | ||
317 | } else { | ||
318 | return cmd_results_new(CMD_FAILURE, "floating", | ||
319 | "Expected 'floating <enable|disable|toggle>"); | ||
320 | } | ||
309 | 321 | ||
310 | if (strcasecmp(argv[0], "toggle") == 0) { | 322 | // Prevent running floating commands on things like workspaces |
311 | swayc_t *view = get_focused_container(&root_container); | 323 | if (view->type != C_VIEW) { |
312 | // Prevent running floating commands on things like workspaces | 324 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
313 | if (view->type != C_VIEW) { | 325 | } |
314 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 326 | |
327 | // Change from nonfloating to floating | ||
328 | if (!view->is_floating && wants_floating) { | ||
329 | // Remove view from its current location | ||
330 | destroy_container(remove_child(view)); | ||
331 | |||
332 | // and move it into workspace floating | ||
333 | add_floating(swayc_active_workspace(), view); | ||
334 | view->x = (swayc_active_workspace()->width - view->width)/2; | ||
335 | view->y = (swayc_active_workspace()->height - view->height)/2; | ||
336 | if (view->desired_width != -1) { | ||
337 | view->width = view->desired_width; | ||
315 | } | 338 | } |
316 | // Change from nonfloating to floating | 339 | if (view->desired_height != -1) { |
317 | if (!view->is_floating) { | 340 | view->height = view->desired_height; |
318 | // Remove view from its current location | 341 | } |
319 | destroy_container(remove_child(view)); | 342 | arrange_windows(swayc_active_workspace(), -1, -1); |
320 | 343 | ||
321 | // and move it into workspace floating | 344 | } else if (view->is_floating && !wants_floating) { |
322 | add_floating(swayc_active_workspace(), view); | 345 | // Delete the view from the floating list and unset its is_floating flag |
323 | view->x = (swayc_active_workspace()->width - view->width)/2; | 346 | // Using length-1 as the index is safe because the view must be the currently |
324 | view->y = (swayc_active_workspace()->height - view->height)/2; | 347 | // focused floating output |
325 | if (view->desired_width != -1) { | 348 | remove_child(view); |
326 | view->width = view->desired_width; | 349 | view->is_floating = false; |
327 | } | 350 | // Get the properly focused container, and add in the view there |
328 | if (view->desired_height != -1) { | 351 | swayc_t *focused = container_under_pointer(); |
329 | view->height = view->desired_height; | 352 | // If focused is null, it's because the currently focused container is a workspace |
330 | } | 353 | if (focused == NULL) { |
331 | arrange_windows(swayc_active_workspace(), -1, -1); | 354 | focused = swayc_active_workspace(); |
332 | } else { | 355 | } |
333 | // Delete the view from the floating list and unset its is_floating flag | 356 | set_focused_container(focused); |
334 | // Using length-1 as the index is safe because the view must be the currently | ||
335 | // focused floating output | ||
336 | remove_child(view); | ||
337 | view->is_floating = false; | ||
338 | // Get the properly focused container, and add in the view there | ||
339 | swayc_t *focused = container_under_pointer(); | ||
340 | // If focused is null, it's because the currently focused container is a workspace | ||
341 | if (focused == NULL) { | ||
342 | focused = swayc_active_workspace(); | ||
343 | } | ||
344 | set_focused_container(focused); | ||
345 | 357 | ||
346 | sway_log(L_DEBUG, "Non-floating focused container is %p", focused); | 358 | sway_log(L_DEBUG, "Non-floating focused container is %p", focused); |
347 | 359 | ||
348 | // Case of focused workspace, just create as child of it | 360 | // Case of focused workspace, just create as child of it |
349 | if (focused->type == C_WORKSPACE) { | 361 | if (focused->type == C_WORKSPACE) { |
350 | add_child(focused, view); | 362 | add_child(focused, view); |
351 | } | ||
352 | // Regular case, create as sibling of current container | ||
353 | else { | ||
354 | add_sibling(focused, view); | ||
355 | } | ||
356 | // Refocus on the view once its been put back into the layout | ||
357 | view->width = view->height = 0; | ||
358 | arrange_windows(swayc_active_workspace(), -1, -1); | ||
359 | remove_view_from_scratchpad(view); | ||
360 | } | 363 | } |
361 | set_focused_container(view); | 364 | // Regular case, create as sibling of current container |
365 | else { | ||
366 | add_sibling(focused, view); | ||
367 | } | ||
368 | // Refocus on the view once its been put back into the layout | ||
369 | view->width = view->height = 0; | ||
370 | arrange_windows(swayc_active_workspace(), -1, -1); | ||
371 | remove_view_from_scratchpad(view); | ||
362 | } | 372 | } |
373 | set_focused_container(view); | ||
363 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 374 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
364 | } | 375 | } |
365 | 376 | ||