diff options
-rw-r--r-- | common/util.c | 16 | ||||
-rw-r--r-- | include/util.h | 2 | ||||
-rw-r--r-- | sway/commands/focus.c | 11 | ||||
-rw-r--r-- | sway/commands/move.c | 13 |
4 files changed, 29 insertions, 13 deletions
diff --git a/common/util.c b/common/util.c index 78d46a2a..f4588b57 100644 --- a/common/util.c +++ b/common/util.c | |||
@@ -1,4 +1,5 @@ | |||
1 | #define _XOPEN_SOURCE 700 | 1 | #define _XOPEN_SOURCE 700 |
2 | #include <assert.h> | ||
2 | #include <sys/types.h> | 3 | #include <sys/types.h> |
3 | #include <sys/stat.h> | 4 | #include <sys/stat.h> |
4 | #include <unistd.h> | 5 | #include <unistd.h> |
@@ -138,3 +139,18 @@ bool parse_boolean(const char *boolean, bool current) { | |||
138 | // All other values are false to match i3 | 139 | // All other values are false to match i3 |
139 | return false; | 140 | return false; |
140 | } | 141 | } |
142 | |||
143 | enum wlr_direction opposite_direction(enum wlr_direction d) { | ||
144 | switch (d) { | ||
145 | case WLR_DIRECTION_UP: | ||
146 | return WLR_DIRECTION_DOWN; | ||
147 | case WLR_DIRECTION_DOWN: | ||
148 | return WLR_DIRECTION_UP; | ||
149 | case WLR_DIRECTION_RIGHT: | ||
150 | return WLR_DIRECTION_LEFT; | ||
151 | case WLR_DIRECTION_LEFT: | ||
152 | return WLR_DIRECTION_RIGHT; | ||
153 | } | ||
154 | assert(false); | ||
155 | return 0; | ||
156 | } | ||
diff --git a/include/util.h b/include/util.h index 56ca2eb8..f143d0c0 100644 --- a/include/util.h +++ b/include/util.h | |||
@@ -59,4 +59,6 @@ uint32_t parse_color(const char *color); | |||
59 | */ | 59 | */ |
60 | bool parse_boolean(const char *boolean, bool current); | 60 | bool parse_boolean(const char *boolean, bool current); |
61 | 61 | ||
62 | enum wlr_direction opposite_direction(enum wlr_direction d); | ||
63 | |||
62 | #endif | 64 | #endif |
diff --git a/sway/commands/focus.c b/sway/commands/focus.c index 521b2427..cef92144 100644 --- a/sway/commands/focus.c +++ b/sway/commands/focus.c | |||
@@ -196,6 +196,17 @@ static struct cmd_results *focus_output(struct sway_seat *seat, | |||
196 | } | 196 | } |
197 | struct sway_workspace *ws = seat_get_focused_workspace(seat); | 197 | struct sway_workspace *ws = seat_get_focused_workspace(seat); |
198 | output = output_get_in_direction(ws->output, direction); | 198 | output = output_get_in_direction(ws->output, direction); |
199 | |||
200 | if (!output) { | ||
201 | int center_lx = ws->output->lx + ws->output->width / 2; | ||
202 | int center_ly = ws->output->ly + ws->output->height / 2; | ||
203 | struct wlr_output *target = wlr_output_layout_farthest_output( | ||
204 | root->output_layout, opposite_direction(direction), | ||
205 | ws->output->wlr_output, center_lx, center_ly); | ||
206 | if (target) { | ||
207 | output = output_from_wlr_output(target); | ||
208 | } | ||
209 | } | ||
199 | } | 210 | } |
200 | 211 | ||
201 | free(identifier); | 212 | free(identifier); |
diff --git a/sway/commands/move.c b/sway/commands/move.c index 30c198e4..9035e3e2 100644 --- a/sway/commands/move.c +++ b/sway/commands/move.c | |||
@@ -27,19 +27,6 @@ static const char *expected_syntax = | |||
27 | "'move <container|window|workspace> [to] output <name|direction>' or " | 27 | "'move <container|window|workspace> [to] output <name|direction>' or " |
28 | "'move <container|window> [to] mark <mark>'"; | 28 | "'move <container|window> [to] mark <mark>'"; |
29 | 29 | ||
30 | enum wlr_direction opposite_direction(enum wlr_direction d) { | ||
31 | switch (d) { | ||
32 | case WLR_DIRECTION_UP: | ||
33 | return WLR_DIRECTION_DOWN; | ||
34 | case WLR_DIRECTION_DOWN: | ||
35 | return WLR_DIRECTION_UP; | ||
36 | case WLR_DIRECTION_RIGHT: | ||
37 | return WLR_DIRECTION_LEFT; | ||
38 | default: | ||
39 | return WLR_DIRECTION_RIGHT; | ||
40 | } | ||
41 | } | ||
42 | |||
43 | static struct sway_output *output_in_direction(const char *direction_string, | 30 | static struct sway_output *output_in_direction(const char *direction_string, |
44 | struct sway_output *reference, int ref_lx, int ref_ly) { | 31 | struct sway_output *reference, int ref_lx, int ref_ly) { |
45 | struct { | 32 | struct { |