diff options
author | 2015-10-25 01:20:00 +0200 | |
---|---|---|
committer | 2015-10-25 13:14:23 +0100 | |
commit | c6bb23b7ddd6393c3d4a621bd2c610922a933867 (patch) | |
tree | 10ce75aaa4e756b151d75ff564c141b60d9d72be /sway | |
parent | Update set_origin to match wlc changes (diff) | |
download | sway-c6bb23b7ddd6393c3d4a621bd2c610922a933867.tar.gz sway-c6bb23b7ddd6393c3d4a621bd2c610922a933867.tar.zst sway-c6bb23b7ddd6393c3d4a621bd2c610922a933867.zip |
sway/output: Create, move code from handlers.c here.
Diffstat (limited to 'sway')
-rw-r--r-- | sway/handlers.c | 61 | ||||
-rw-r--r-- | sway/output.c | 95 |
2 files changed, 110 insertions, 46 deletions
diff --git a/sway/handlers.c b/sway/handlers.c index c0b775db..c777e692 100644 --- a/sway/handlers.c +++ b/sway/handlers.c | |||
@@ -13,6 +13,7 @@ | |||
13 | #include "stringop.h" | 13 | #include "stringop.h" |
14 | #include "workspace.h" | 14 | #include "workspace.h" |
15 | #include "container.h" | 15 | #include "container.h" |
16 | #include "output.h" | ||
16 | #include "focus.h" | 17 | #include "focus.h" |
17 | #include "input_state.h" | 18 | #include "input_state.h" |
18 | #include "resize.h" | 19 | #include "resize.h" |
@@ -364,62 +365,30 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct | |||
364 | // don't do the switch if the pointer is in a mode. | 365 | // don't do the switch if the pointer is in a mode. |
365 | if (config->seamless_mouse && !pointer_state.mode && | 366 | if (config->seamless_mouse && !pointer_state.mode && |
366 | !pointer_state.left.held && !pointer_state.right.held && !pointer_state.scroll.held) { | 367 | !pointer_state.left.held && !pointer_state.right.held && !pointer_state.scroll.held) { |
367 | swayc_t *output = swayc_active_output(); | ||
368 | 368 | ||
369 | // TODO: This implementation is naïve: We assume all outputs are | 369 | swayc_t *output = swayc_active_output(), *adjacent = NULL; |
370 | // perfectly aligned (ie. only a single output per edge which covers | ||
371 | // the whole edge). | ||
372 | if (origin->x == 0) { // Left edge | 370 | if (origin->x == 0) { // Left edge |
373 | for(int i = 0; i < root_container.children->length; ++i) { | 371 | if ((adjacent = swayc_adjacent_output(output, MOVE_LEFT))) { |
374 | swayc_t *c = root_container.children->items[i]; | 372 | if (workspace_switch(adjacent)) { |
375 | if (c == output || c->type != C_OUTPUT) { | 373 | new_origin.x = adjacent->width; |
376 | continue; | ||
377 | } | ||
378 | if (c->y == output->y && c->x + c->width == output->x) { | ||
379 | sway_log(L_DEBUG, "%s is right of %s", output->name, c->name); | ||
380 | if (workspace_switch(c)) { | ||
381 | new_origin.x = c->width; | ||
382 | } | ||
383 | } | 374 | } |
384 | } | 375 | } |
385 | } else if ((double)origin->x == output->width) { // Right edge | 376 | } else if ((double)origin->x == output->width) { // Right edge |
386 | for(int i = 0; i < root_container.children->length; ++i) { | 377 | if ((adjacent = swayc_adjacent_output(output, MOVE_RIGHT))) { |
387 | swayc_t *c = root_container.children->items[i]; | 378 | if (workspace_switch(adjacent)) { |
388 | if (c == output || c->type != C_OUTPUT) { | 379 | new_origin.x = 0; |
389 | continue; | ||
390 | } | ||
391 | if (c->y == output->y && output->x + output->width == c->x) { | ||
392 | sway_log(L_DEBUG, "%s is left of %s", output->name, c->name); | ||
393 | if (workspace_switch(c)) { | ||
394 | new_origin.x = 0; | ||
395 | } | ||
396 | } | 380 | } |
397 | } | 381 | } |
398 | } | 382 | } else if (origin->y == 0) { // Top edge |
399 | if (origin->y == 0) { // Top edge | 383 | if ((adjacent = swayc_adjacent_output(output, MOVE_UP))) { |
400 | for(int i = 0; i < root_container.children->length; ++i) { | 384 | if (workspace_switch(adjacent)) { |
401 | swayc_t *c = root_container.children->items[i]; | 385 | new_origin.y = adjacent->height; |
402 | if (c == output || c->type != C_OUTPUT) { | ||
403 | continue; | ||
404 | } | ||
405 | if (output->x == c->x && c->y + c->height == output->y) { | ||
406 | sway_log(L_DEBUG, "%s is below %s", output->name, c->name); | ||
407 | if (workspace_switch(c)) { | ||
408 | new_origin.y = c->height; | ||
409 | } | ||
410 | } | 386 | } |
411 | } | 387 | } |
412 | } else if ((double)origin->y == output->height) { // Bottom edge | 388 | } else if ((double)origin->y == output->height) { // Bottom edge |
413 | for(int i = 0; i < root_container.children->length; ++i) { | 389 | if ((adjacent = swayc_adjacent_output(output, MOVE_DOWN))) { |
414 | swayc_t *c = root_container.children->items[i]; | 390 | if (workspace_switch(adjacent)) { |
415 | if (c == output || c->type != C_OUTPUT) { | 391 | new_origin.y = 0; |
416 | continue; | ||
417 | } | ||
418 | if (output->x == c->x && output->y + output->height == c->y) { | ||
419 | sway_log(L_DEBUG, "%s is above %s", output->name, c->name); | ||
420 | if (workspace_switch(c)) { | ||
421 | new_origin.y = 0; | ||
422 | } | ||
423 | } | 392 | } |
424 | } | 393 | } |
425 | } | 394 | } |
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 | |||
5 | swayc_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 | |||
29 | swayc_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 | } | ||