diff options
author | Brian Ashworth <RedSoxFan@users.noreply.github.com> | 2018-08-25 11:19:17 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-25 11:19:17 -0400 |
commit | ed147aed30d89fdd1e4493adcdf821b414eab224 (patch) | |
tree | b66217c5d841dd267bd4b9131d55c7d06b5b9e4a | |
parent | Merge pull request #2510 from RyanDwyer/relocate-layout-functions (diff) | |
parent | Workspace move cycle (diff) | |
download | sway-ed147aed30d89fdd1e4493adcdf821b414eab224.tar.gz sway-ed147aed30d89fdd1e4493adcdf821b414eab224.tar.zst sway-ed147aed30d89fdd1e4493adcdf821b414eab224.zip |
Merge pull request #2512 from apreiml/workspace_move_wrap
Workspace move cycle
-rw-r--r-- | sway/commands/move.c | 48 |
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 | ||
29 | static struct sway_container *output_in_direction(const char *direction, | 29 | enum 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 | |||
42 | static 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 | ||
55 | static void container_move_to(struct sway_container *container, | 83 | static void container_move_to(struct sway_container *container, |