diff options
Diffstat (limited to 'sway/handlers.c')
-rw-r--r-- | sway/handlers.c | 51 |
1 files changed, 24 insertions, 27 deletions
diff --git a/sway/handlers.c b/sway/handlers.c index f95683d0..98d4831f 100644 --- a/sway/handlers.c +++ b/sway/handlers.c | |||
@@ -28,15 +28,19 @@ static bool pointer_test(swayc_t *view, void *_origin) { | |||
28 | return false; | 28 | return false; |
29 | } | 29 | } |
30 | 30 | ||
31 | void focus_pointer(void) { | 31 | swayc_t *focus_pointer(void) { |
32 | swayc_t *focused = find_container(&root_container, pointer_test, &mouse_origin); | 32 | swayc_t *focused = get_focused_container(&root_container); |
33 | if (focused) { | 33 | if (!(wlc_view_get_state(focused->handle) & WLC_BIT_FULLSCREEN)) { |
34 | sway_log(L_DEBUG, "Switching focus to %p", focused); | 34 | swayc_t *pointer = find_container(&root_container, pointer_test, &mouse_origin); |
35 | unfocus_all(&root_container); | 35 | if (pointer && focused != pointer) { |
36 | focus_view(focused); | 36 | unfocus_all(&root_container); |
37 | } else { | 37 | focus_view(pointer); |
38 | focus_view(active_workspace); | 38 | } else if (!focused){ |
39 | focus_view(active_workspace); | ||
40 | } | ||
41 | focused = pointer; | ||
39 | } | 42 | } |
43 | return focused; | ||
40 | } | 44 | } |
41 | 45 | ||
42 | static bool handle_output_created(wlc_handle output) { | 46 | static bool handle_output_created(wlc_handle output) { |
@@ -82,16 +86,21 @@ static void handle_output_focused(wlc_handle output, bool focus) { | |||
82 | } | 86 | } |
83 | 87 | ||
84 | static bool handle_view_created(wlc_handle handle) { | 88 | static bool handle_view_created(wlc_handle handle) { |
85 | swayc_t *container = get_focused_container(&root_container); | 89 | swayc_t *focused = get_focused_container(&root_container); |
86 | swayc_t *view = new_view(container, handle); | 90 | swayc_t *view = new_view(focused, handle); |
87 | unfocus_all(&root_container); | ||
88 | if (view) { | 91 | if (view) { |
92 | unfocus_all(&root_container); | ||
89 | focus_view(view); | 93 | focus_view(view); |
90 | arrange_windows(view->parent, -1, -1); | 94 | arrange_windows(view->parent, -1, -1); |
91 | } else { //Unmanaged view | 95 | } else { //Unmanaged view |
92 | wlc_view_set_state(handle, WLC_BIT_ACTIVATED, true); | 96 | wlc_view_set_state(handle, WLC_BIT_ACTIVATED, true); |
93 | wlc_view_focus(handle); | 97 | wlc_view_focus(handle); |
94 | } | 98 | } |
99 | if (wlc_view_get_state(focused->handle) & WLC_BIT_FULLSCREEN) { | ||
100 | unfocus_all(&root_container); | ||
101 | focus_view(focused); | ||
102 | arrange_windows(focused, -1, -1); | ||
103 | } | ||
95 | return true; | 104 | return true; |
96 | } | 105 | } |
97 | 106 | ||
@@ -189,28 +198,16 @@ static bool handle_pointer_motion(wlc_handle view, uint32_t time, const struct w | |||
189 | if (!config->focus_follows_mouse) { | 198 | if (!config->focus_follows_mouse) { |
190 | return true; | 199 | return true; |
191 | } | 200 | } |
192 | swayc_t *c = find_container(&root_container, pointer_test, (void *)origin); | 201 | focus_pointer(); |
193 | swayc_t *focused = get_focused_container(&root_container); | ||
194 | if (c && c != focused) { | ||
195 | sway_log(L_DEBUG, "Switching focus to %p", c); | ||
196 | unfocus_all(&root_container); | ||
197 | focus_view(c); | ||
198 | } | ||
199 | return true; | 202 | return true; |
200 | } | 203 | } |
201 | 204 | ||
202 | static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct wlc_modifiers *modifiers, | 205 | static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct wlc_modifiers *modifiers, |
203 | uint32_t button, enum wlc_button_state state) { | 206 | uint32_t button, enum wlc_button_state state) { |
207 | swayc_t *focused = get_focused_container(&root_container); | ||
204 | if (state == WLC_BUTTON_STATE_PRESSED) { | 208 | if (state == WLC_BUTTON_STATE_PRESSED) { |
205 | swayc_t *c = find_container(&root_container, pointer_test, &mouse_origin); | 209 | swayc_t *pointer = focus_pointer(); |
206 | swayc_t *focused = get_focused_container(&root_container); | 210 | return !(pointer && pointer != focused); |
207 | if (c && c != focused) { | ||
208 | sway_log(L_DEBUG, "Switching focus to %p", c); | ||
209 | unfocus_all(&root_container); | ||
210 | focus_view(c); | ||
211 | return false; | ||
212 | } | ||
213 | return true; | ||
214 | } | 211 | } |
215 | return true; | 212 | return true; |
216 | } | 213 | } |