aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/move.c
diff options
context:
space:
mode:
authorLibravatar emersion <contact@emersion.fr>2018-09-12 09:20:47 +0200
committerLibravatar GitHub <noreply@github.com>2018-09-12 09:20:47 +0200
commitaf9e8f94cc0afb9f80e3902cbb83de78027cd737 (patch)
treeb59c19c355f2aa72c3ecd4fc88846fd215ec180f /sway/commands/move.c
parentMerge pull request #2624 from RedSoxFan/update-tex-in-cmd-client (diff)
parentcommands: when moving container, remove its gaps (diff)
downloadsway-af9e8f94cc0afb9f80e3902cbb83de78027cd737.tar.gz
sway-af9e8f94cc0afb9f80e3902cbb83de78027cd737.tar.zst
sway-af9e8f94cc0afb9f80e3902cbb83de78027cd737.zip
Merge pull request #2620 from ianyfan/commands
commands: when moving a container, restore focus properly
Diffstat (limited to 'sway/commands/move.c')
-rw-r--r--sway/commands/move.c27
1 files changed, 19 insertions, 8 deletions
diff --git a/sway/commands/move.c b/sway/commands/move.c
index b2cca5be..cd970983 100644
--- a/sway/commands/move.c
+++ b/sway/commands/move.c
@@ -231,6 +231,7 @@ static void container_move_to_container(struct sway_container *container,
231 struct sway_workspace *old_workspace = container->workspace; 231 struct sway_workspace *old_workspace = container->workspace;
232 232
233 container_detach(container); 233 container_detach(container);
234 container_remove_gaps(container);
234 container->width = container->height = 0; 235 container->width = container->height = 0;
235 container->saved_width = container->saved_height = 0; 236 container->saved_width = container->saved_height = 0;
236 237
@@ -554,7 +555,10 @@ static struct cmd_results *cmd_move_container(int argc, char **argv) {
554 struct sway_workspace *new_output_last_ws = old_output == new_output ? 555 struct sway_workspace *new_output_last_ws = old_output == new_output ?
555 NULL : output_get_active_workspace(new_output); 556 NULL : output_get_active_workspace(new_output);
556 557
557 // move container, arrange windows and return focus 558 // save focus, in case it needs to be restored
559 struct sway_node *focus = seat_get_focus(seat);
560
561 // move container
558 if (container->scratchpad) { 562 if (container->scratchpad) {
559 root_scratchpad_remove_container(container); 563 root_scratchpad_remove_container(container);
560 } 564 }
@@ -574,30 +578,37 @@ static struct cmd_results *cmd_move_container(int argc, char **argv) {
574 case N_ROOT: 578 case N_ROOT:
575 break; 579 break;
576 } 580 }
581
582 // restore focus on destination output back to its last active workspace
577 struct sway_workspace *new_workspace = 583 struct sway_workspace *new_workspace =
578 output_get_active_workspace(new_output); 584 output_get_active_workspace(new_output);
579 if (new_output_last_ws && new_output_last_ws != new_workspace) { 585 if (new_output_last_ws && new_output_last_ws != new_workspace) {
580 // change focus on destination output back to its last active workspace
581 struct sway_node *new_output_last_focus = 586 struct sway_node *new_output_last_focus =
582 seat_get_focus_inactive(seat, &new_output_last_ws->node); 587 seat_get_focus_inactive(seat, &new_output_last_ws->node);
583 seat_set_focus_warp(seat, new_output_last_focus, false, false); 588 seat_set_focus_warp(seat, new_output_last_focus, false, false);
584 } 589 }
585 590
586 struct sway_node *focus = NULL; 591 // restore focus
587 if (old_parent) { 592 if (focus == &container->node) {
588 focus = seat_get_focus_inactive(seat, &old_parent->node); 593 focus = NULL;
589 } else if (old_ws) { 594 if (old_parent) {
590 focus = seat_get_focus_inactive(seat, &old_ws->node); 595 focus = seat_get_focus_inactive(seat, &old_parent->node);
596 }
597 if (!focus && old_ws) {
598 focus = seat_get_focus_inactive(seat, &old_ws->node);
599 }
591 } 600 }
592 seat_set_focus_warp(seat, focus, true, false); 601 seat_set_focus_warp(seat, focus, true, false);
593 602
603 // clean-up, destroying parents if the container was the last child
594 if (old_parent) { 604 if (old_parent) {
595 container_reap_empty(old_parent); 605 container_reap_empty(old_parent);
596 } else if (old_ws) { 606 } else if (old_ws) {
597 workspace_consider_destroy(old_ws); 607 workspace_consider_destroy(old_ws);
598 } 608 }
599 609
600 if (old_ws) { 610 // arrange windows
611 if (old_ws && !old_ws->node.destroying) {
601 arrange_workspace(old_ws); 612 arrange_workspace(old_ws);
602 } 613 }
603 arrange_node(node_get_parent(destination)); 614 arrange_node(node_get_parent(destination));