summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2017-01-13 19:16:38 -0500
committerLibravatar GitHub <noreply@github.com>2017-01-13 19:16:38 -0500
commit0001b00706bfdaa185a9fd6823ff947c14aa3b5f (patch)
tree68f4595908ff4f33f27e3c30813835642845d290
parentMerge pull request #1044 from ametisf/master (diff)
parentAdd output wrapping (diff)
downloadsway-0001b00706bfdaa185a9fd6823ff947c14aa3b5f.tar.gz
sway-0001b00706bfdaa185a9fd6823ff947c14aa3b5f.tar.zst
sway-0001b00706bfdaa185a9fd6823ff947c14aa3b5f.zip
Merge pull request #1048 from dkess/proper-output-wrapping
Add output wrapping
-rw-r--r--include/sway/output.h1
-rw-r--r--sway/output.c76
2 files changed, 72 insertions, 5 deletions
diff --git a/include/sway/output.h b/include/sway/output.h
index e8afd5ed..e1bdd3f0 100644
--- a/include/sway/output.h
+++ b/include/sway/output.h
@@ -7,6 +7,7 @@
7// Position is absolute coordinates on the edge where the adjacent output 7// Position is absolute coordinates on the edge where the adjacent output
8// should be searched for. 8// should be searched for.
9swayc_t *output_by_name(const char* name, const struct wlc_point *abs_pos); 9swayc_t *output_by_name(const char* name, const struct wlc_point *abs_pos);
10swayc_t *swayc_opposite_output(enum movement_direction dir, const struct wlc_point *abs_pos);
10swayc_t *swayc_adjacent_output(swayc_t *output, enum movement_direction dir, const struct wlc_point *abs_pos, bool pick_closest); 11swayc_t *swayc_adjacent_output(swayc_t *output, enum movement_direction dir, const struct wlc_point *abs_pos, bool pick_closest);
11 12
12// Place absolute coordinates for given container into given wlc_point. 13// Place absolute coordinates for given container into given wlc_point.
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
15swayc_t *output_by_name(const char* name, const struct wlc_point *abs_pos) { 15swayc_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
50swayc_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.