aboutsummaryrefslogtreecommitdiff
path: root/sway/commands
diff options
context:
space:
mode:
authorIan Fan <ianfan0@gmail.com>2018-09-11 16:03:05 +0100
committerIan Fan <ianfan0@gmail.com>2018-09-11 16:46:07 +0100
commitc770949a9fbcad8640103a3dc9d4b9e8917884f2 (patch)
tree8540bbd7c1cb810ed40a1d60c39129efae427d53 /sway/commands
parent822b45f4836c9a22af5a283e2aea6e4ecd514c22 (diff)
downloadsway-c770949a9fbcad8640103a3dc9d4b9e8917884f2.tar.xz
commands: when moving container, restore focus properly
Diffstat (limited to 'sway/commands')
-rw-r--r--sway/commands/move.c26
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) {
struct sway_workspace *new_output_last_ws = old_output == new_output ?
NULL : output_get_active_workspace(new_output);
- // move container, arrange windows and return focus
+ // save focus, in case it needs to be restored
+ struct sway_node *focus = seat_get_focus(seat);
+
+ // move container
if (container->scratchpad) {
root_scratchpad_remove_container(container);
}
@@ -574,30 +577,37 @@ static struct cmd_results *cmd_move_container(int argc, char **argv) {
case N_ROOT:
break;
}
+
+ // restore focus on destination output back to its last active workspace
struct sway_workspace *new_workspace =
output_get_active_workspace(new_output);
if (new_output_last_ws && new_output_last_ws != new_workspace) {
- // change focus on destination output back to its last active workspace
struct sway_node *new_output_last_focus =
seat_get_focus_inactive(seat, &new_output_last_ws->node);
seat_set_focus_warp(seat, new_output_last_focus, false, false);
}
- struct sway_node *focus = NULL;
- if (old_parent) {
- focus = seat_get_focus_inactive(seat, &old_parent->node);
- } else if (old_ws) {
- focus = seat_get_focus_inactive(seat, &old_ws->node);
+ // restore focus
+ if (focus == &container->node) {
+ focus = NULL;
+ if (old_parent) {
+ focus = seat_get_focus_inactive(seat, &old_parent->node);
+ }
+ if (!focus && old_ws) {
+ focus = seat_get_focus_inactive(seat, &old_ws->node);
+ }
}
seat_set_focus_warp(seat, focus, true, false);
+ // clean-up, destroying parents if the container was the last child
if (old_parent) {
container_reap_empty(old_parent);
} else if (old_ws) {
workspace_consider_destroy(old_ws);
}
- if (old_ws) {
+ // arrange windows
+ if (old_ws && !old_ws->node.destroying) {
arrange_workspace(old_ws);
}
arrange_node(node_get_parent(destination));