aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/move.c
diff options
context:
space:
mode:
authorLibravatar Armin Preiml <apreiml@strohwolke.at>2018-08-25 09:11:20 +0200
committerLibravatar Armin Preiml <apreiml@strohwolke.at>2018-08-25 17:10:41 +0200
commit1a72149d88f52a2d5d8348dae8f0d6c3612e71e0 (patch)
treeb66217c5d841dd267bd4b9131d55c7d06b5b9e4a /sway/commands/move.c
parentMerge pull request #2510 from RyanDwyer/relocate-layout-functions (diff)
downloadsway-1a72149d88f52a2d5d8348dae8f0d6c3612e71e0.tar.gz
sway-1a72149d88f52a2d5d8348dae8f0d6c3612e71e0.tar.zst
sway-1a72149d88f52a2d5d8348dae8f0d6c3612e71e0.zip
Workspace move cycle
On move workspace to direction: Try the farthest on the opposite direction if no workspace is found at given direction.
Diffstat (limited to 'sway/commands/move.c')
-rw-r--r--sway/commands/move.c48
1 files changed, 38 insertions, 10 deletions
diff --git a/sway/commands/move.c b/sway/commands/move.c
index a4eedf7f..2744b354 100644
--- a/sway/commands/move.c
+++ b/sway/commands/move.c
@@ -26,7 +26,20 @@ static const char *expected_syntax =
26 "'move <container|window|workspace> [to] output <name|direction>' or " 26 "'move <container|window|workspace> [to] output <name|direction>' or "
27 "'move <container|window> [to] mark <mark>'"; 27 "'move <container|window> [to] mark <mark>'";
28 28
29static struct sway_container *output_in_direction(const char *direction, 29enum wlr_direction opposite_direction(enum wlr_direction d) {
30 switch (d) {
31 case WLR_DIRECTION_UP:
32 return WLR_DIRECTION_DOWN;
33 case WLR_DIRECTION_DOWN:
34 return WLR_DIRECTION_UP;
35 case WLR_DIRECTION_RIGHT:
36 return WLR_DIRECTION_LEFT;
37 default:
38 return WLR_DIRECTION_RIGHT;
39 }
40}
41
42static struct sway_container *output_in_direction(const char *direction_string,
30 struct wlr_output *reference, int ref_lx, int ref_ly) { 43 struct wlr_output *reference, int ref_lx, int ref_ly) {
31 struct { 44 struct {
32 char *name; 45 char *name;
@@ -37,19 +50,34 @@ static struct sway_container *output_in_direction(const char *direction,
37 { "left", WLR_DIRECTION_LEFT }, 50 { "left", WLR_DIRECTION_LEFT },
38 { "right", WLR_DIRECTION_RIGHT }, 51 { "right", WLR_DIRECTION_RIGHT },
39 }; 52 };
53
54 enum wlr_direction direction;
55
40 for (size_t i = 0; i < sizeof(names) / sizeof(names[0]); ++i) { 56 for (size_t i = 0; i < sizeof(names) / sizeof(names[0]); ++i) {
41 if (strcasecmp(names[i].name, direction) == 0) { 57 if (strcasecmp(names[i].name, direction_string) == 0) {
42 struct wlr_output *adjacent = wlr_output_layout_adjacent_output( 58 direction = names[i].direction;
43 root_container.sway_root->output_layout,
44 names[i].direction, reference, ref_lx, ref_ly);
45 if (adjacent) {
46 struct sway_output *sway_output = adjacent->data;
47 return sway_output->swayc;
48 }
49 break; 59 break;
50 } 60 }
51 } 61 }
52 return output_by_name(direction); 62
63 if (direction) {
64 struct wlr_output *target = wlr_output_layout_adjacent_output(
65 root_container.sway_root->output_layout,
66 direction, reference, ref_lx, ref_ly);
67
68 if (!target) {
69 target = wlr_output_layout_farthest_output(
70 root_container.sway_root->output_layout,
71 opposite_direction(direction), reference, ref_lx, ref_ly);
72 }
73
74 if (target) {
75 struct sway_output *sway_output = target->data;
76 return sway_output->swayc;
77 }
78 }
79
80 return output_by_name(direction_string);
53} 81}
54 82
55static void container_move_to(struct sway_container *container, 83static void container_move_to(struct sway_container *container,