diff options
author | Ian Fan <ianfan0@gmail.com> | 2018-08-28 00:46:44 +0100 |
---|---|---|
committer | Ian Fan <ianfan0@gmail.com> | 2018-08-28 15:08:46 +0100 |
commit | bc30f2d5283863792331965148617977995ad662 (patch) | |
tree | 7f599a6c1507d670145fe89f77b5a6291487ff8e /sway/commands/move.c | |
parent | Merge pull request #2511 from RyanDwyer/refactor-arrange (diff) | |
download | sway-bc30f2d5283863792331965148617977995ad662.tar.gz sway-bc30f2d5283863792331965148617977995ad662.tar.zst sway-bc30f2d5283863792331965148617977995ad662.zip |
commands: fix moving container to different output
When moving a container to an inactive workspace on a different output, this will change the focus on the destination output back to its last active workspace
Diffstat (limited to 'sway/commands/move.c')
-rw-r--r-- | sway/commands/move.c | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/sway/commands/move.c b/sway/commands/move.c index 7b7cb8f3..4426f24e 100644 --- a/sway/commands/move.c +++ b/sway/commands/move.c | |||
@@ -529,8 +529,10 @@ static struct cmd_results *cmd_move_container(struct sway_container *current, | |||
529 | argv++; | 529 | argv++; |
530 | } | 530 | } |
531 | 531 | ||
532 | struct sway_seat *seat = config->handler_context.seat; | ||
532 | struct sway_container *old_parent = current->parent; | 533 | struct sway_container *old_parent = current->parent; |
533 | struct sway_container *old_ws = container_parent(current, C_WORKSPACE); | 534 | struct sway_container *old_ws = container_parent(current, C_WORKSPACE); |
535 | struct sway_container *old_output = container_parent(current, C_OUTPUT); | ||
534 | struct sway_container *destination = NULL; | 536 | struct sway_container *destination = NULL; |
535 | 537 | ||
536 | // determine destination | 538 | // determine destination |
@@ -586,9 +588,7 @@ static struct cmd_results *cmd_move_container(struct sway_container *current, | |||
586 | // We have to create the workspace, but if the container is | 588 | // We have to create the workspace, but if the container is |
587 | // sticky and the workspace is going to be created on the same | 589 | // sticky and the workspace is going to be created on the same |
588 | // output, we'll bail out first. | 590 | // output, we'll bail out first. |
589 | if (container_is_floating(current) && current->is_sticky) { | 591 | if (current->is_sticky) { |
590 | struct sway_container *old_output = | ||
591 | container_parent(current, C_OUTPUT); | ||
592 | struct sway_container *new_output = | 592 | struct sway_container *new_output = |
593 | workspace_get_initial_output(ws_name); | 593 | workspace_get_initial_output(ws_name); |
594 | if (old_output == new_output) { | 594 | if (old_output == new_output) { |
@@ -601,17 +601,15 @@ static struct cmd_results *cmd_move_container(struct sway_container *current, | |||
601 | ws = workspace_create(NULL, ws_name); | 601 | ws = workspace_create(NULL, ws_name); |
602 | } | 602 | } |
603 | free(ws_name); | 603 | free(ws_name); |
604 | destination = seat_get_focus_inactive(config->handler_context.seat, ws); | 604 | destination = seat_get_focus_inactive(seat, ws); |
605 | } else if (strcasecmp(argv[1], "output") == 0) { | 605 | } else if (strcasecmp(argv[1], "output") == 0) { |
606 | struct sway_container *source = container_parent(current, C_OUTPUT); | ||
607 | struct sway_container *dest_output = output_in_direction(argv[2], | 606 | struct sway_container *dest_output = output_in_direction(argv[2], |
608 | source->sway_output->wlr_output, current->x, current->y); | 607 | old_output->sway_output->wlr_output, current->x, current->y); |
609 | if (!dest_output) { | 608 | if (!dest_output) { |
610 | return cmd_results_new(CMD_FAILURE, "move workspace", | 609 | return cmd_results_new(CMD_FAILURE, "move workspace", |
611 | "Can't find output with name/direction '%s'", argv[2]); | 610 | "Can't find output with name/direction '%s'", argv[2]); |
612 | } | 611 | } |
613 | destination = seat_get_focus_inactive( | 612 | destination = seat_get_focus_inactive(seat, dest_output); |
614 | config->handler_context.seat, dest_output); | ||
615 | if (!destination) { | 613 | if (!destination) { |
616 | // We've never been to this output before | 614 | // We've never been to this output before |
617 | destination = dest_output->children->items[0]; | 615 | destination = dest_output->children->items[0]; |
@@ -627,21 +625,28 @@ static struct cmd_results *cmd_move_container(struct sway_container *current, | |||
627 | return cmd_results_new(CMD_INVALID, "move", expected_syntax); | 625 | return cmd_results_new(CMD_INVALID, "move", expected_syntax); |
628 | } | 626 | } |
629 | 627 | ||
630 | if (container_is_floating(current) && current->is_sticky) { | 628 | struct sway_container *new_output = destination->type == C_OUTPUT ? |
631 | struct sway_container *old_output = container_parent(current, C_OUTPUT); | 629 | destination : container_parent(destination, C_OUTPUT); |
632 | struct sway_container *new_output = destination->type == C_OUTPUT ? | 630 | if (current->is_sticky && old_output == new_output) { |
633 | destination : container_parent(destination, C_OUTPUT); | 631 | return cmd_results_new(CMD_FAILURE, "move", "Can't move sticky " |
634 | if (old_output == new_output) { | 632 | "container to another workspace on the same output"); |
635 | return cmd_results_new(CMD_FAILURE, "move", "Can't move sticky " | ||
636 | "container to another workspace on the same output"); | ||
637 | } | ||
638 | } | 633 | } |
639 | 634 | ||
635 | struct sway_container *new_output_last_ws = old_output == new_output ? | ||
636 | NULL : seat_get_active_child(seat, new_output); | ||
637 | struct sway_container *new_workspace = destination->type == C_WORKSPACE ? | ||
638 | destination : container_parent(destination, C_WORKSPACE); | ||
639 | |||
640 | // move container, arrange windows and return focus | 640 | // move container, arrange windows and return focus |
641 | container_move_to(current, destination); | 641 | container_move_to(current, destination); |
642 | struct sway_container *focus = | 642 | if (new_output_last_ws && new_output_last_ws != new_workspace) { |
643 | seat_get_focus_inactive(config->handler_context.seat, old_parent); | 643 | // change focus on destination output back to its last active workspace |
644 | seat_set_focus_warp(config->handler_context.seat, focus, true, false); | 644 | struct sway_container *new_output_last_focus = |
645 | seat_get_focus_inactive(seat, new_output_last_ws); | ||
646 | seat_set_focus_warp(seat, new_output_last_focus, false, false); | ||
647 | } | ||
648 | struct sway_container *focus = seat_get_focus_inactive(seat, old_parent); | ||
649 | seat_set_focus_warp(seat, focus, true, false); | ||
645 | container_reap_empty(old_parent); | 650 | container_reap_empty(old_parent); |
646 | container_reap_empty(destination->parent); | 651 | container_reap_empty(destination->parent); |
647 | 652 | ||