summaryrefslogtreecommitdiffstats
path: root/sway
diff options
context:
space:
mode:
authorLibravatar S. Christoffer Eliesen <christoffer@eliesen.no>2015-11-24 20:00:39 +0100
committerLibravatar S. Christoffer Eliesen <christoffer@eliesen.no>2015-11-27 17:09:19 +0100
commitd9770cc24381b145aeee79d104d28a4052a191a6 (patch)
treee680d1beeef8f8ff6889f863503bc3da11b10bf6 /sway
parentFix swaygrab memory leak (diff)
downloadsway-d9770cc24381b145aeee79d104d28a4052a191a6.tar.gz
sway-d9770cc24381b145aeee79d104d28a4052a191a6.tar.zst
sway-d9770cc24381b145aeee79d104d28a4052a191a6.zip
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`.
Diffstat (limited to 'sway')
-rw-r--r--sway/commands.c105
1 files changed, 58 insertions, 47 deletions
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