diff options
author | S. Christoffer Eliesen <christoffer@eliesen.no> | 2015-10-28 00:22:52 +0100 |
---|---|---|
committer | S. Christoffer Eliesen <christoffer@eliesen.no> | 2015-10-29 16:37:19 +0100 |
commit | 865b30f13814beb798f49d6e2372cc44d8103b29 (patch) | |
tree | 7047b1bbfe38f581f46cc6a92a75320631e8ee35 | |
parent | Merge pull request #211 from sce/fix_get_swayc_in_direction (diff) | |
download | sway-865b30f13814beb798f49d6e2372cc44d8103b29.tar.gz sway-865b30f13814beb798f49d6e2372cc44d8103b29.tar.zst sway-865b30f13814beb798f49d6e2372cc44d8103b29.zip |
container: Move container_under_pointer here from handlers.
-rw-r--r-- | include/container.h | 4 | ||||
-rw-r--r-- | include/handlers.h | 4 | ||||
-rw-r--r-- | sway/container.c | 63 | ||||
-rw-r--r-- | sway/handlers.c | 62 |
4 files changed, 67 insertions, 66 deletions
diff --git a/include/container.h b/include/container.h index ae9a9fc5..e1ecca92 100644 --- a/include/container.h +++ b/include/container.h | |||
@@ -5,6 +5,8 @@ typedef struct sway_container swayc_t; | |||
5 | 5 | ||
6 | #include "layout.h" | 6 | #include "layout.h" |
7 | 7 | ||
8 | extern struct wlc_origin mouse_origin; | ||
9 | |||
8 | enum swayc_types{ | 10 | enum swayc_types{ |
9 | C_ROOT, | 11 | C_ROOT, |
10 | C_OUTPUT, | 12 | C_OUTPUT, |
@@ -98,6 +100,8 @@ swayc_t *swayc_by_name(const char *name); | |||
98 | swayc_t *swayc_active_output(void); | 100 | swayc_t *swayc_active_output(void); |
99 | swayc_t *swayc_active_workspace(void); | 101 | swayc_t *swayc_active_workspace(void); |
100 | swayc_t *swayc_active_workspace_for(swayc_t *view); | 102 | swayc_t *swayc_active_workspace_for(swayc_t *view); |
103 | // set focus to current pointer location and return focused container | ||
104 | swayc_t *container_under_pointer(void); | ||
101 | 105 | ||
102 | // Container information | 106 | // Container information |
103 | 107 | ||
diff --git a/include/handlers.h b/include/handlers.h index 4c71f953..d7f6ffdd 100644 --- a/include/handlers.h +++ b/include/handlers.h | |||
@@ -5,10 +5,6 @@ | |||
5 | #include <wlc/wlc.h> | 5 | #include <wlc/wlc.h> |
6 | 6 | ||
7 | extern struct wlc_interface interface; | 7 | extern struct wlc_interface interface; |
8 | extern struct wlc_origin mouse_origin; | ||
9 | extern uint32_t keys_pressed[32]; | 8 | extern uint32_t keys_pressed[32]; |
10 | 9 | ||
11 | // set focus to current pointer location and return focused container | ||
12 | swayc_t *container_under_pointer(void); | ||
13 | |||
14 | #endif | 10 | #endif |
diff --git a/sway/container.c b/sway/container.c index 6c4206fb..4f9e2b5e 100644 --- a/sway/container.c +++ b/sway/container.c | |||
@@ -8,6 +8,7 @@ | |||
8 | #include "workspace.h" | 8 | #include "workspace.h" |
9 | #include "focus.h" | 9 | #include "focus.h" |
10 | #include "layout.h" | 10 | #include "layout.h" |
11 | #include "input_state.h" | ||
11 | #include "log.h" | 12 | #include "log.h" |
12 | 13 | ||
13 | #define ASSERT_NONNULL(PTR) \ | 14 | #define ASSERT_NONNULL(PTR) \ |
@@ -508,6 +509,68 @@ swayc_t *swayc_active_workspace_for(swayc_t *cont) { | |||
508 | } | 509 | } |
509 | } | 510 | } |
510 | 511 | ||
512 | static bool pointer_test(swayc_t *view, void *_origin) { | ||
513 | const struct mouse_origin *origin = _origin; | ||
514 | // Determine the output that the view is under | ||
515 | swayc_t *parent = swayc_parent_by_type(view, C_OUTPUT); | ||
516 | if (origin->x >= view->x && origin->y >= view->y | ||
517 | && origin->x < view->x + view->width && origin->y < view->y + view->height | ||
518 | && view->visible && parent == root_container.focused) { | ||
519 | return true; | ||
520 | } | ||
521 | return false; | ||
522 | } | ||
523 | |||
524 | swayc_t *container_under_pointer(void) { | ||
525 | // root.output->workspace | ||
526 | if (!root_container.focused || !root_container.focused->focused) { | ||
527 | return NULL; | ||
528 | } | ||
529 | swayc_t *lookup = root_container.focused->focused; | ||
530 | // Case of empty workspace | ||
531 | if (lookup->children == 0) { | ||
532 | return NULL; | ||
533 | } | ||
534 | while (lookup->type != C_VIEW) { | ||
535 | int i; | ||
536 | int len; | ||
537 | // if tabbed/stacked go directly to focused container, otherwise search | ||
538 | // children | ||
539 | if (lookup->layout == L_TABBED || lookup->layout == L_STACKED) { | ||
540 | lookup = lookup->focused; | ||
541 | continue; | ||
542 | } | ||
543 | // if workspace, search floating | ||
544 | if (lookup->type == C_WORKSPACE) { | ||
545 | i = len = lookup->floating->length; | ||
546 | bool got_floating = false; | ||
547 | while (--i > -1) { | ||
548 | if (pointer_test(lookup->floating->items[i], &pointer_state.origin)) { | ||
549 | lookup = lookup->floating->items[i]; | ||
550 | got_floating = true; | ||
551 | break; | ||
552 | } | ||
553 | } | ||
554 | if (got_floating) { | ||
555 | continue; | ||
556 | } | ||
557 | } | ||
558 | // search children | ||
559 | len = lookup->children->length; | ||
560 | for (i = 0; i < len; ++i) { | ||
561 | if (pointer_test(lookup->children->items[i], &pointer_state.origin)) { | ||
562 | lookup = lookup->children->items[i]; | ||
563 | break; | ||
564 | } | ||
565 | } | ||
566 | // when border and titles are done, this could happen | ||
567 | if (i == len) { | ||
568 | break; | ||
569 | } | ||
570 | } | ||
571 | return lookup; | ||
572 | } | ||
573 | |||
511 | // Container information | 574 | // Container information |
512 | 575 | ||
513 | bool swayc_is_fullscreen(swayc_t *view) { | 576 | bool swayc_is_fullscreen(swayc_t *view) { |
diff --git a/sway/handlers.c b/sway/handlers.c index 1c5abca6..cb342f69 100644 --- a/sway/handlers.c +++ b/sway/handlers.c | |||
@@ -24,68 +24,6 @@ | |||
24 | // Event handled by sway and should not be sent to client | 24 | // Event handled by sway and should not be sent to client |
25 | #define EVENT_HANDLED true | 25 | #define EVENT_HANDLED true |
26 | 26 | ||
27 | static bool pointer_test(swayc_t *view, void *_origin) { | ||
28 | const struct mouse_origin *origin = _origin; | ||
29 | // Determine the output that the view is under | ||
30 | swayc_t *parent = swayc_parent_by_type(view, C_OUTPUT); | ||
31 | if (origin->x >= view->x && origin->y >= view->y | ||
32 | && origin->x < view->x + view->width && origin->y < view->y + view->height | ||
33 | && view->visible && parent == root_container.focused) { | ||
34 | return true; | ||
35 | } | ||
36 | return false; | ||
37 | } | ||
38 | |||
39 | swayc_t *container_under_pointer(void) { | ||
40 | // root.output->workspace | ||
41 | if (!root_container.focused || !root_container.focused->focused) { | ||
42 | return NULL; | ||
43 | } | ||
44 | swayc_t *lookup = root_container.focused->focused; | ||
45 | // Case of empty workspace | ||
46 | if (lookup->children == 0) { | ||
47 | return NULL; | ||
48 | } | ||
49 | while (lookup->type != C_VIEW) { | ||
50 | int i; | ||
51 | int len; | ||
52 | // if tabbed/stacked go directly to focused container, otherwise search | ||
53 | // children | ||
54 | if (lookup->layout == L_TABBED || lookup->layout == L_STACKED) { | ||
55 | lookup = lookup->focused; | ||
56 | continue; | ||
57 | } | ||
58 | // if workspace, search floating | ||
59 | if (lookup->type == C_WORKSPACE) { | ||
60 | i = len = lookup->floating->length; | ||
61 | bool got_floating = false; | ||
62 | while (--i > -1) { | ||
63 | if (pointer_test(lookup->floating->items[i], &pointer_state.origin)) { | ||
64 | lookup = lookup->floating->items[i]; | ||
65 | got_floating = true; | ||
66 | break; | ||
67 | } | ||
68 | } | ||
69 | if (got_floating) { | ||
70 | continue; | ||
71 | } | ||
72 | } | ||
73 | // search children | ||
74 | len = lookup->children->length; | ||
75 | for (i = 0; i < len; ++i) { | ||
76 | if (pointer_test(lookup->children->items[i], &pointer_state.origin)) { | ||
77 | lookup = lookup->children->items[i]; | ||
78 | break; | ||
79 | } | ||
80 | } | ||
81 | // when border and titles are done, this could happen | ||
82 | if (i == len) { | ||
83 | break; | ||
84 | } | ||
85 | } | ||
86 | return lookup; | ||
87 | } | ||
88 | |||
89 | /* Handles */ | 27 | /* Handles */ |
90 | 28 | ||
91 | static bool handle_output_created(wlc_handle output) { | 29 | static bool handle_output_created(wlc_handle output) { |