summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar taiyu <taiyu.len@gmail.com>2015-08-15 15:20:07 -0700
committerLibravatar taiyu <taiyu.len@gmail.com>2015-08-15 15:20:07 -0700
commit3a21ba020fd0f0628a128070b72f0cf7a6b64a57 (patch)
tree5a2229d9e33968aba41c4bd4cd76dd1d11a41ab9
parentMerge branch 'master' of https://github.com/SirCmpwn/sway (diff)
downloadsway-3a21ba020fd0f0628a128070b72f0cf7a6b64a57.tar.gz
sway-3a21ba020fd0f0628a128070b72f0cf7a6b64a57.tar.zst
sway-3a21ba020fd0f0628a128070b72f0cf7a6b64a57.zip
made better, reduced code duplication
-rw-r--r--sway/handlers.c43
-rw-r--r--sway/handlers.h4
2 files changed, 18 insertions, 29 deletions
diff --git a/sway/handlers.c b/sway/handlers.c
index b02cd988..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
31void focus_pointer(void) { 31swayc_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
42static bool handle_output_created(wlc_handle output) { 46static bool handle_output_created(wlc_handle output) {
@@ -194,31 +198,16 @@ static bool handle_pointer_motion(wlc_handle view, uint32_t time, const struct w
194 if (!config->focus_follows_mouse) { 198 if (!config->focus_follows_mouse) {
195 return true; 199 return true;
196 } 200 }
197 swayc_t *focused = get_focused_container(&root_container); 201 focus_pointer();
198 if (!(wlc_view_get_state(focused->handle) & WLC_BIT_FULLSCREEN)) {
199 swayc_t *c = find_container(&root_container, pointer_test, (void *)origin);
200 if (c && c != focused) {
201 sway_log(L_DEBUG, "Switching focus to %p", c);
202 unfocus_all(&root_container);
203 focus_view(c);
204 }
205 }
206 return true; 202 return true;
207} 203}
208 204
209static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct wlc_modifiers *modifiers, 205static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct wlc_modifiers *modifiers,
210 uint32_t button, enum wlc_button_state state) { 206 uint32_t button, enum wlc_button_state state) {
211 swayc_t *focused = get_focused_container(&root_container); 207 swayc_t *focused = get_focused_container(&root_container);
212 if (state == WLC_BUTTON_STATE_PRESSED 208 if (state == WLC_BUTTON_STATE_PRESSED) {
213 && !(wlc_view_get_state(focused->handle) & WLC_BIT_FULLSCREEN)) { 209 swayc_t *pointer = focus_pointer();
214 swayc_t *c = find_container(&root_container, pointer_test, &mouse_origin); 210 return !(pointer && pointer != focused);
215 if (c && c != focused) {
216 sway_log(L_DEBUG, "Switching focus to %p", c);
217 unfocus_all(&root_container);
218 focus_view(c);
219 return false;
220 }
221 return true;
222 } 211 }
223 return true; 212 return true;
224} 213}
diff --git a/sway/handlers.h b/sway/handlers.h
index b8b171c3..d1742cce 100644
--- a/sway/handlers.h
+++ b/sway/handlers.h
@@ -6,7 +6,7 @@
6 6
7extern struct wlc_interface interface; 7extern struct wlc_interface interface;
8 8
9//set focus to current pointer location 9//set focus to current pointer location and return focused container
10void focus_pointer(void); 10swayc_t *focus_pointer(void);
11 11
12#endif 12#endif