diff options
Diffstat (limited to 'sway/handlers.c')
-rw-r--r-- | sway/handlers.c | 84 |
1 files changed, 65 insertions, 19 deletions
diff --git a/sway/handlers.c b/sway/handlers.c index 48c6cbf7..393a2181 100644 --- a/sway/handlers.c +++ b/sway/handlers.c | |||
@@ -9,14 +9,53 @@ | |||
9 | #include "commands.h" | 9 | #include "commands.h" |
10 | #include "handlers.h" | 10 | #include "handlers.h" |
11 | #include "stringop.h" | 11 | #include "stringop.h" |
12 | #include "workspace.h" | ||
13 | |||
14 | static struct wlc_origin mouse_origin; | ||
15 | |||
16 | static bool pointer_test(swayc_t *view, void *_origin) { | ||
17 | const struct wlc_origin *origin = _origin; | ||
18 | if (view->type == C_VIEW && origin->x >= view->x && origin->y >= view->y | ||
19 | && origin->x < view->x + view->width && origin->y < view->y + view->height | ||
20 | && view->visible) { | ||
21 | return true; | ||
22 | } | ||
23 | return false; | ||
24 | } | ||
25 | |||
26 | void focus_pointer(void) { | ||
27 | swayc_t *focused = find_container(&root_container, pointer_test, &mouse_origin); | ||
28 | if (focused) { | ||
29 | sway_log(L_DEBUG, "Switching focus to %p", focused); | ||
30 | unfocus_all(&root_container); | ||
31 | focus_view(focused); | ||
32 | } else { | ||
33 | focus_view(active_workspace); | ||
34 | } | ||
35 | } | ||
12 | 36 | ||
13 | static bool handle_output_created(wlc_handle output) { | 37 | static bool handle_output_created(wlc_handle output) { |
14 | add_output(output); | 38 | swayc_t *op = new_output(output); |
39 | |||
40 | //Switch to workspace if we need to | ||
41 | if (active_workspace == NULL) { | ||
42 | swayc_t *ws = op->children->items[0]; | ||
43 | workspace_switch(ws); | ||
44 | } | ||
15 | return true; | 45 | return true; |
16 | } | 46 | } |
17 | 47 | ||
18 | static void handle_output_destroyed(wlc_handle output) { | 48 | static void handle_output_destroyed(wlc_handle output) { |
19 | destroy_output(output); | 49 | int i; |
50 | list_t *list = root_container.children; | ||
51 | for (i = 0; i < list->length; ++i) { | ||
52 | if (((swayc_t *)list->items[i])->handle == output) { | ||
53 | break; | ||
54 | } | ||
55 | } | ||
56 | if (i < list->length) { | ||
57 | destroy_output(list->items[i]); | ||
58 | } | ||
20 | } | 59 | } |
21 | 60 | ||
22 | static void handle_output_resolution_change(wlc_handle output, const struct wlc_size *from, const struct wlc_size *to) { | 61 | static void handle_output_resolution_change(wlc_handle output, const struct wlc_size *from, const struct wlc_size *to) { |
@@ -37,14 +76,33 @@ static void handle_output_focused(wlc_handle output, bool focus) { | |||
37 | } | 76 | } |
38 | } | 77 | } |
39 | 78 | ||
40 | static bool handle_view_created(wlc_handle view) { | 79 | static bool handle_view_created(wlc_handle handle) { |
41 | add_view(view); | 80 | swayc_t *container = get_focused_container(&root_container); |
81 | swayc_t *view = new_view(container, handle); | ||
82 | unfocus_all(&root_container); | ||
83 | if (view) { | ||
84 | focus_view(view); | ||
85 | arrange_windows(view->parent, -1, -1); | ||
86 | } else { //Unmanaged view | ||
87 | wlc_view_set_state(handle, WLC_BIT_ACTIVATED, true); | ||
88 | wlc_view_focus(handle); | ||
89 | } | ||
42 | return true; | 90 | return true; |
43 | } | 91 | } |
44 | 92 | ||
45 | static void handle_view_destroyed(wlc_handle view) { | 93 | static void handle_view_destroyed(wlc_handle handle) { |
46 | sway_log(L_DEBUG, "Destroying window %d", view); | 94 | sway_log(L_DEBUG, "Destroying window %d", handle); |
47 | destroy_view(get_swayc_for_handle(view, &root_container)); | 95 | swayc_t *view = get_swayc_for_handle(handle, &root_container); |
96 | swayc_t *parent; | ||
97 | swayc_t *focused = get_focused_container(&root_container); | ||
98 | |||
99 | if (view) { | ||
100 | parent = destroy_view(view); | ||
101 | arrange_windows(parent, -1, -1); | ||
102 | } | ||
103 | if (!focused || focused == view) { | ||
104 | focus_pointer(); | ||
105 | } | ||
48 | } | 106 | } |
49 | 107 | ||
50 | static void handle_view_focus(wlc_handle view, bool focus) { | 108 | static void handle_view_focus(wlc_handle view, bool focus) { |
@@ -121,18 +179,6 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier | |||
121 | return cmd_success; | 179 | return cmd_success; |
122 | } | 180 | } |
123 | 181 | ||
124 | bool pointer_test(swayc_t *view, void *_origin) { | ||
125 | const struct wlc_origin *origin = _origin; | ||
126 | if (view->type == C_VIEW && origin->x >= view->x && origin->y >= view->y | ||
127 | && origin->x < view->x + view->width && origin->y < view->y + view->height | ||
128 | && view->visible) { | ||
129 | return true; | ||
130 | } | ||
131 | return false; | ||
132 | } | ||
133 | |||
134 | struct wlc_origin mouse_origin; | ||
135 | |||
136 | static bool handle_pointer_motion(wlc_handle view, uint32_t time, const struct wlc_origin *origin) { | 182 | static bool handle_pointer_motion(wlc_handle view, uint32_t time, const struct wlc_origin *origin) { |
137 | mouse_origin = *origin; | 183 | mouse_origin = *origin; |
138 | if (!config->focus_follows_mouse) { | 184 | if (!config->focus_follows_mouse) { |