diff options
-rw-r--r-- | include/input_state.h | 2 | ||||
-rw-r--r-- | sway/handlers.c | 22 | ||||
-rw-r--r-- | sway/input_state.c | 24 |
3 files changed, 27 insertions, 21 deletions
diff --git a/include/input_state.h b/include/input_state.h index d87ae18c..dd5d71a8 100644 --- a/include/input_state.h +++ b/include/input_state.h | |||
@@ -65,6 +65,8 @@ extern struct pointer_state { | |||
65 | int mode; | 65 | int mode; |
66 | } pointer_state; | 66 | } pointer_state; |
67 | 67 | ||
68 | void pointer_position_set(struct wlc_origin *new_origin, bool force_focus); | ||
69 | |||
68 | // on button release unset mode depending on the button. | 70 | // on button release unset mode depending on the button. |
69 | // on button press set mode conditionally depending on the button | 71 | // on button press set mode conditionally depending on the button |
70 | void pointer_mode_set(uint32_t button, bool condition); | 72 | void pointer_mode_set(uint32_t button, bool condition); |
diff --git a/sway/handlers.c b/sway/handlers.c index cb342f69..e1612dc1 100644 --- a/sway/handlers.c +++ b/sway/handlers.c | |||
@@ -332,27 +332,7 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct | |||
332 | } | 332 | } |
333 | } | 333 | } |
334 | 334 | ||
335 | // Update pointer origin | 335 | pointer_position_set(&new_origin, false); |
336 | pointer_state.delta.x = origin->x - pointer_state.origin.x; | ||
337 | pointer_state.delta.y = origin->y - pointer_state.origin.y; | ||
338 | pointer_state.origin.x = origin->x; | ||
339 | pointer_state.origin.y = origin->y; | ||
340 | |||
341 | // Update view under pointer | ||
342 | swayc_t *prev_view = pointer_state.view; | ||
343 | pointer_state.view = container_under_pointer(); | ||
344 | |||
345 | // If pointer is in a mode, update it | ||
346 | if (pointer_state.mode) { | ||
347 | pointer_mode_update(); | ||
348 | } | ||
349 | // Otherwise change focus if config is set an | ||
350 | else if (prev_view != pointer_state.view && config->focus_follows_mouse) { | ||
351 | if (pointer_state.view && pointer_state.view->type == C_VIEW) { | ||
352 | set_focused_container(pointer_state.view); | ||
353 | } | ||
354 | } | ||
355 | wlc_pointer_set_origin(&new_origin); | ||
356 | return EVENT_PASSTHROUGH; | 336 | return EVENT_PASSTHROUGH; |
357 | } | 337 | } |
358 | 338 | ||
diff --git a/sway/input_state.c b/sway/input_state.c index 2743a9ea..bd46a5ac 100644 --- a/sway/input_state.c +++ b/sway/input_state.c | |||
@@ -2,6 +2,7 @@ | |||
2 | #include <stdbool.h> | 2 | #include <stdbool.h> |
3 | #include <ctype.h> | 3 | #include <ctype.h> |
4 | #include "log.h" | 4 | #include "log.h" |
5 | #include "config.h" | ||
5 | 6 | ||
6 | #include "input_state.h" | 7 | #include "input_state.h" |
7 | 8 | ||
@@ -161,6 +162,29 @@ static void reset_initial_sibling(void) { | |||
161 | pointer_state.mode = 0; | 162 | pointer_state.mode = 0; |
162 | } | 163 | } |
163 | 164 | ||
165 | void pointer_position_set(struct wlc_origin *new_origin, bool force_focus) { | ||
166 | pointer_state.delta.x = new_origin->x - pointer_state.origin.x; | ||
167 | pointer_state.delta.y = new_origin->y - pointer_state.origin.y; | ||
168 | pointer_state.origin.x = new_origin->x; | ||
169 | pointer_state.origin.y = new_origin->y; | ||
170 | |||
171 | // Update view under pointer | ||
172 | swayc_t *prev_view = pointer_state.view; | ||
173 | pointer_state.view = container_under_pointer(); | ||
174 | |||
175 | // If pointer is in a mode, update it | ||
176 | if (pointer_state.mode) { | ||
177 | pointer_mode_update(); | ||
178 | // Otherwise change focus if config is set | ||
179 | } else if (force_focus || (prev_view != pointer_state.view && config->focus_follows_mouse)) { | ||
180 | if (pointer_state.view && pointer_state.view->type == C_VIEW) { | ||
181 | set_focused_container(pointer_state.view); | ||
182 | } | ||
183 | } | ||
184 | |||
185 | wlc_pointer_set_origin(new_origin); | ||
186 | } | ||
187 | |||
164 | // Mode set left/right click | 188 | // Mode set left/right click |
165 | 189 | ||
166 | static void pointer_mode_set_left(void) { | 190 | static void pointer_mode_set_left(void) { |