diff options
author | Ian Fan <ianfan0@gmail.com> | 2018-09-11 16:03:05 +0100 |
---|---|---|
committer | Ian Fan <ianfan0@gmail.com> | 2018-09-11 16:46:07 +0100 |
commit | c770949a9fbcad8640103a3dc9d4b9e8917884f2 (patch) | |
tree | 8540bbd7c1cb810ed40a1d60c39129efae427d53 | |
parent | Merge pull request #2617 from wmww/cursor-enter-on-focus-change (diff) | |
download | sway-c770949a9fbcad8640103a3dc9d4b9e8917884f2.tar.gz sway-c770949a9fbcad8640103a3dc9d4b9e8917884f2.tar.zst sway-c770949a9fbcad8640103a3dc9d4b9e8917884f2.zip |
commands: when moving container, restore focus properly
-rw-r--r-- | sway/commands/move.c | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/sway/commands/move.c b/sway/commands/move.c index 2e9c00f8..3c8f1dcf 100644 --- a/sway/commands/move.c +++ b/sway/commands/move.c | |||
@@ -554,7 +554,10 @@ static struct cmd_results *cmd_move_container(int argc, char **argv) { | |||
554 | struct sway_workspace *new_output_last_ws = old_output == new_output ? | 554 | struct sway_workspace *new_output_last_ws = old_output == new_output ? |
555 | NULL : output_get_active_workspace(new_output); | 555 | NULL : output_get_active_workspace(new_output); |
556 | 556 | ||
557 | // move container, arrange windows and return focus | 557 | // save focus, in case it needs to be restored |
558 | struct sway_node *focus = seat_get_focus(seat); | ||
559 | |||
560 | // move container | ||
558 | if (container->scratchpad) { | 561 | if (container->scratchpad) { |
559 | root_scratchpad_remove_container(container); | 562 | root_scratchpad_remove_container(container); |
560 | } | 563 | } |
@@ -574,30 +577,37 @@ static struct cmd_results *cmd_move_container(int argc, char **argv) { | |||
574 | case N_ROOT: | 577 | case N_ROOT: |
575 | break; | 578 | break; |
576 | } | 579 | } |
580 | |||
581 | // restore focus on destination output back to its last active workspace | ||
577 | struct sway_workspace *new_workspace = | 582 | struct sway_workspace *new_workspace = |
578 | output_get_active_workspace(new_output); | 583 | output_get_active_workspace(new_output); |
579 | if (new_output_last_ws && new_output_last_ws != new_workspace) { | 584 | 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 = | 585 | struct sway_node *new_output_last_focus = |
582 | seat_get_focus_inactive(seat, &new_output_last_ws->node); | 586 | seat_get_focus_inactive(seat, &new_output_last_ws->node); |
583 | seat_set_focus_warp(seat, new_output_last_focus, false, false); | 587 | seat_set_focus_warp(seat, new_output_last_focus, false, false); |
584 | } | 588 | } |
585 | 589 | ||
586 | struct sway_node *focus = NULL; | 590 | // restore focus |
587 | if (old_parent) { | 591 | if (focus == &container->node) { |
588 | focus = seat_get_focus_inactive(seat, &old_parent->node); | 592 | focus = NULL; |
589 | } else if (old_ws) { | 593 | if (old_parent) { |
590 | focus = seat_get_focus_inactive(seat, &old_ws->node); | 594 | focus = seat_get_focus_inactive(seat, &old_parent->node); |
595 | } | ||
596 | if (!focus && old_ws) { | ||
597 | focus = seat_get_focus_inactive(seat, &old_ws->node); | ||
598 | } | ||
591 | } | 599 | } |
592 | seat_set_focus_warp(seat, focus, true, false); | 600 | seat_set_focus_warp(seat, focus, true, false); |
593 | 601 | ||
602 | // clean-up, destroying parents if the container was the last child | ||
594 | if (old_parent) { | 603 | if (old_parent) { |
595 | container_reap_empty(old_parent); | 604 | container_reap_empty(old_parent); |
596 | } else if (old_ws) { | 605 | } else if (old_ws) { |
597 | workspace_consider_destroy(old_ws); | 606 | workspace_consider_destroy(old_ws); |
598 | } | 607 | } |
599 | 608 | ||
600 | if (old_ws) { | 609 | // arrange windows |
610 | if (old_ws && !old_ws->node.destroying) { | ||
601 | arrange_workspace(old_ws); | 611 | arrange_workspace(old_ws); |
602 | } | 612 | } |
603 | arrange_node(node_get_parent(destination)); | 613 | arrange_node(node_get_parent(destination)); |