summaryrefslogtreecommitdiffstats
path: root/sway/output.c
diff options
context:
space:
mode:
authorLibravatar S. Christoffer Eliesen <christoffer@eliesen.no>2015-10-25 01:20:00 +0200
committerLibravatar S. Christoffer Eliesen <christoffer@eliesen.no>2015-10-25 13:14:23 +0100
commitc6bb23b7ddd6393c3d4a621bd2c610922a933867 (patch)
tree10ce75aaa4e756b151d75ff564c141b60d9d72be /sway/output.c
parentUpdate set_origin to match wlc changes (diff)
downloadsway-c6bb23b7ddd6393c3d4a621bd2c610922a933867.tar.gz
sway-c6bb23b7ddd6393c3d4a621bd2c610922a933867.tar.zst
sway-c6bb23b7ddd6393c3d4a621bd2c610922a933867.zip
sway/output: Create, move code from handlers.c here.
Diffstat (limited to 'sway/output.c')
-rw-r--r--sway/output.c95
1 files changed, 95 insertions, 0 deletions
diff --git a/sway/output.c b/sway/output.c
new file mode 100644
index 00000000..39c933f8
--- /dev/null
+++ b/sway/output.c
@@ -0,0 +1,95 @@
1#include <strings.h>
2#include "output.h"
3#include "log.h"
4
5swayc_t *output_by_name(const char* name) {
6 if (strcasecmp(name, "left") == 0) {
7 return swayc_adjacent_output(NULL, MOVE_LEFT);
8 }
9 else if (strcasecmp(name, "right") == 0) {
10 return swayc_adjacent_output(NULL, MOVE_RIGHT);
11 }
12 else if (strcasecmp(name, "up") == 0) {
13 return swayc_adjacent_output(NULL, MOVE_UP);
14 }
15 else if (strcasecmp(name, "down") == 0) {
16 return swayc_adjacent_output(NULL, MOVE_DOWN);
17 }
18 else {
19 for(int i = 0; i < root_container.children->length; ++i) {
20 swayc_t *c = root_container.children->items[i];
21 if (c->type == C_OUTPUT && strcasecmp(c->name, name) == 0) {
22 return c;
23 }
24 }
25 }
26 return NULL;
27}
28
29swayc_t *swayc_adjacent_output(swayc_t *output, enum movement_direction dir) {
30 // TODO: This implementation is naïve: We assume all outputs are
31 // perfectly aligned (ie. only a single output per edge which covers
32 // the whole edge).
33 if (!output) {
34 output = swayc_active_output();
35 }
36 swayc_t *adjacent = NULL;
37 switch(dir) {
38 case MOVE_LEFT:
39 for(int i = 0; i < root_container.children->length; ++i) {
40 swayc_t *c = root_container.children->items[i];
41 if (c == output || c->type != C_OUTPUT) {
42 continue;
43 }
44 if (c->y == output->y && c->x + c->width == output->x) {
45 sway_log(L_DEBUG, "%s is left of current output %s", c->name, output->name);
46 adjacent = c;
47 break;
48 }
49 }
50 break;
51 case MOVE_RIGHT:
52 for(int i = 0; i < root_container.children->length; ++i) {
53 swayc_t *c = root_container.children->items[i];
54 if (c == output || c->type != C_OUTPUT) {
55 continue;
56 }
57 if (c->y == output->y && output->x + output->width == c->x) {
58 sway_log(L_DEBUG, "%s is right of current output %s", c->name, output->name);
59 adjacent = c;
60 break;
61 }
62 }
63 break;
64 case MOVE_UP:
65 for(int i = 0; i < root_container.children->length; ++i) {
66 swayc_t *c = root_container.children->items[i];
67 if (c == output || c->type != C_OUTPUT) {
68 continue;
69 }
70 if (output->x == c->x && c->y + c->height == output->y) {
71 sway_log(L_DEBUG, "%s is above current output %s", c->name, output->name);
72 adjacent = c;
73 break;
74 }
75 }
76 break;
77 case MOVE_DOWN:
78 for(int i = 0; i < root_container.children->length; ++i) {
79 swayc_t *c = root_container.children->items[i];
80 if (c == output || c->type != C_OUTPUT) {
81 continue;
82 }
83 if (output->x == c->x && output->y + output->height == c->y) {
84 sway_log(L_DEBUG, "%s is below current output %s", c->name, output->name);
85 adjacent = c;
86 break;
87 }
88 }
89 break;
90 default:
91 sway_abort("Function called with invalid argument.");
92 break;
93 }
94 return adjacent;
95}