diff options
author | Daniel Kessler <sinani201@gmail.com> | 2017-01-13 16:06:10 -0800 |
---|---|---|
committer | Daniel Kessler <sinani201@gmail.com> | 2017-01-13 16:06:10 -0800 |
commit | eda4bad725b8a76accdb2a9c648efa046b88c0c0 (patch) | |
tree | 68f4595908ff4f33f27e3c30813835642845d290 /sway | |
parent | Merge pull request #1044 from ametisf/master (diff) | |
download | sway-eda4bad725b8a76accdb2a9c648efa046b88c0c0.tar.gz sway-eda4bad725b8a76accdb2a9c648efa046b88c0c0.tar.zst sway-eda4bad725b8a76accdb2a9c648efa046b88c0c0.zip |
Add output wrapping
This fixes issue #733. Now if the user focuses output right but is at
the rightmost monitor, the focus will wrap the the leftmost monitor.
This commit adds a new function, swayc_opposite_output, which selects
the opposite output given a position and a direction. Now, when calling
output_by_name, we first check if there is an adjacent output to switch
to. If that fails, we call swayc_opposite_output to handle wrapping.
Diffstat (limited to 'sway')
-rw-r--r-- | sway/output.c | 76 |
1 files changed, 71 insertions, 5 deletions
diff --git a/sway/output.c b/sway/output.c index b337b143..c0f29c5a 100644 --- a/sway/output.c +++ b/sway/output.c | |||
@@ -13,14 +13,29 @@ void output_get_scaled_size(wlc_handle handle, struct wlc_size *size) { | |||
13 | } | 13 | } |
14 | 14 | ||
15 | swayc_t *output_by_name(const char* name, const struct wlc_point *abs_pos) { | 15 | swayc_t *output_by_name(const char* name, const struct wlc_point *abs_pos) { |
16 | swayc_t *output = NULL; | ||
17 | // If there is no output directly next to the current one, use | ||
18 | // swayc_opposite_output to wrap. | ||
16 | if (strcasecmp(name, "left") == 0) { | 19 | if (strcasecmp(name, "left") == 0) { |
17 | return swayc_adjacent_output(NULL, MOVE_LEFT, abs_pos, true); | 20 | output = swayc_adjacent_output(NULL, MOVE_LEFT, abs_pos, true); |
21 | if (!output) { | ||
22 | output = swayc_opposite_output(MOVE_RIGHT, abs_pos); | ||
23 | } | ||
18 | } else if (strcasecmp(name, "right") == 0) { | 24 | } else if (strcasecmp(name, "right") == 0) { |
19 | return swayc_adjacent_output(NULL, MOVE_RIGHT, abs_pos, true); | 25 | output = swayc_adjacent_output(NULL, MOVE_RIGHT, abs_pos, true); |
26 | if (!output) { | ||
27 | output = swayc_opposite_output(MOVE_LEFT, abs_pos); | ||
28 | } | ||
20 | } else if (strcasecmp(name, "up") == 0) { | 29 | } else if (strcasecmp(name, "up") == 0) { |
21 | return swayc_adjacent_output(NULL, MOVE_UP, abs_pos, true); | 30 | output = swayc_adjacent_output(NULL, MOVE_UP, abs_pos, true); |
31 | if (!output) { | ||
32 | output = swayc_opposite_output(MOVE_DOWN, abs_pos); | ||
33 | } | ||
22 | } else if (strcasecmp(name, "down") == 0) { | 34 | } else if (strcasecmp(name, "down") == 0) { |
23 | return swayc_adjacent_output(NULL, MOVE_DOWN, abs_pos, true); | 35 | output = swayc_adjacent_output(NULL, MOVE_DOWN, abs_pos, true); |
36 | if (!output) { | ||
37 | output = swayc_opposite_output(MOVE_UP, abs_pos); | ||
38 | } | ||
24 | } else { | 39 | } else { |
25 | for(int i = 0; i < root_container.children->length; ++i) { | 40 | for(int i = 0; i < root_container.children->length; ++i) { |
26 | swayc_t *c = root_container.children->items[i]; | 41 | swayc_t *c = root_container.children->items[i]; |
@@ -29,7 +44,58 @@ swayc_t *output_by_name(const char* name, const struct wlc_point *abs_pos) { | |||
29 | } | 44 | } |
30 | } | 45 | } |
31 | } | 46 | } |
32 | return NULL; | 47 | return output; |
48 | } | ||
49 | |||
50 | swayc_t *swayc_opposite_output(enum movement_direction dir, | ||
51 | const struct wlc_point *abs_pos) { | ||
52 | |||
53 | // Search through all the outputs and pick the output whose edge covers the | ||
54 | // given position, and is at leftmost/rightmost/upmost/downmost side of the | ||
55 | // screen (decided by the direction given). | ||
56 | swayc_t *opposite = NULL; | ||
57 | char *dir_text = NULL; | ||
58 | switch(dir) { | ||
59 | case MOVE_LEFT: | ||
60 | case MOVE_RIGHT: ; | ||
61 | for (int i = 0; i < root_container.children->length; ++i) { | ||
62 | swayc_t *c = root_container.children->items[i]; | ||
63 | if (abs_pos->y >= c->y && abs_pos->y <= c->y + c->height) { | ||
64 | if (!opposite) { | ||
65 | opposite = c; | ||
66 | } else if ((dir == MOVE_LEFT && c->x < opposite->x) | ||
67 | || (dir == MOVE_RIGHT && c->x > opposite->x)) { | ||
68 | opposite = c; | ||
69 | } | ||
70 | } | ||
71 | } | ||
72 | dir_text = dir == MOVE_LEFT ? "leftmost" : "rightmost"; | ||
73 | break; | ||
74 | case MOVE_UP: | ||
75 | case MOVE_DOWN: ; | ||
76 | for (int i = 0; i < root_container.children->length; ++i) { | ||
77 | swayc_t *c = root_container.children->items[i]; | ||
78 | if (abs_pos->x >= c->x && abs_pos->x <= c->x + c->width) { | ||
79 | if (!opposite) { | ||
80 | opposite = c; | ||
81 | } else if ((dir == MOVE_UP && c->y < opposite->y) | ||
82 | || (dir == MOVE_DOWN && c->y > opposite->y)) { | ||
83 | opposite = c; | ||
84 | } | ||
85 | } | ||
86 | } | ||
87 | dir_text = dir == MOVE_UP ? "upmost" : "downmost"; | ||
88 | break; | ||
89 | default: | ||
90 | sway_abort("Function called with invalid argument."); | ||
91 | break; | ||
92 | } | ||
93 | if (opposite) { | ||
94 | sway_log(L_DEBUG, "%s (%.0fx%.0f+%.0f+%.0f) is %s from y-position %i", | ||
95 | opposite->name, opposite->width, opposite->height, opposite->x, opposite->y, | ||
96 | dir_text, abs_pos->y); | ||
97 | } | ||
98 | return opposite; | ||
33 | } | 99 | } |
34 | 100 | ||
35 | // Position is where on the edge (as absolute position) the adjacent output should be searched for. | 101 | // Position is where on the edge (as absolute position) the adjacent output should be searched for. |