From 4799d07ac1bb08a770ee702eb3fd0ab4654f878a Mon Sep 17 00:00:00 2001 From: "S. Christoffer Eliesen" Date: Wed, 28 Oct 2015 00:41:28 +0100 Subject: [PATCH] input_state: Extract 'pointer_position_set' function from handlers. --- include/input_state.h | 2 ++ sway/handlers.c | 22 +--------------------- 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 { int mode; } pointer_state; +void pointer_position_set(struct wlc_origin *new_origin, bool force_focus); + // on button release unset mode depending on the button. // on button press set mode conditionally depending on the button 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 } } - // Update pointer origin - pointer_state.delta.x = origin->x - pointer_state.origin.x; - pointer_state.delta.y = origin->y - pointer_state.origin.y; - pointer_state.origin.x = origin->x; - pointer_state.origin.y = origin->y; - - // Update view under pointer - swayc_t *prev_view = pointer_state.view; - pointer_state.view = container_under_pointer(); - - // If pointer is in a mode, update it - if (pointer_state.mode) { - pointer_mode_update(); - } - // Otherwise change focus if config is set an - else if (prev_view != pointer_state.view && config->focus_follows_mouse) { - if (pointer_state.view && pointer_state.view->type == C_VIEW) { - set_focused_container(pointer_state.view); - } - } - wlc_pointer_set_origin(&new_origin); + pointer_position_set(&new_origin, false); return EVENT_PASSTHROUGH; } 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 @@ #include #include #include "log.h" +#include "config.h" #include "input_state.h" @@ -161,6 +162,29 @@ static void reset_initial_sibling(void) { pointer_state.mode = 0; } +void pointer_position_set(struct wlc_origin *new_origin, bool force_focus) { + pointer_state.delta.x = new_origin->x - pointer_state.origin.x; + pointer_state.delta.y = new_origin->y - pointer_state.origin.y; + pointer_state.origin.x = new_origin->x; + pointer_state.origin.y = new_origin->y; + + // Update view under pointer + swayc_t *prev_view = pointer_state.view; + pointer_state.view = container_under_pointer(); + + // If pointer is in a mode, update it + if (pointer_state.mode) { + pointer_mode_update(); + // Otherwise change focus if config is set + } else if (force_focus || (prev_view != pointer_state.view && config->focus_follows_mouse)) { + if (pointer_state.view && pointer_state.view->type == C_VIEW) { + set_focused_container(pointer_state.view); + } + } + + wlc_pointer_set_origin(new_origin); +} + // Mode set left/right click static void pointer_mode_set_left(void) {