From 865b30f13814beb798f49d6e2372cc44d8103b29 Mon Sep 17 00:00:00 2001 From: "S. Christoffer Eliesen" Date: Wed, 28 Oct 2015 00:22:52 +0100 Subject: container: Move container_under_pointer here from handlers. --- sway/handlers.c | 62 --------------------------------------------------------- 1 file changed, 62 deletions(-) (limited to 'sway/handlers.c') diff --git a/sway/handlers.c b/sway/handlers.c index 1c5abca6..cb342f69 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -24,68 +24,6 @@ // Event handled by sway and should not be sent to client #define EVENT_HANDLED true -static bool pointer_test(swayc_t *view, void *_origin) { - const struct mouse_origin *origin = _origin; - // Determine the output that the view is under - swayc_t *parent = swayc_parent_by_type(view, C_OUTPUT); - if (origin->x >= view->x && origin->y >= view->y - && origin->x < view->x + view->width && origin->y < view->y + view->height - && view->visible && parent == root_container.focused) { - return true; - } - return false; -} - -swayc_t *container_under_pointer(void) { - // root.output->workspace - if (!root_container.focused || !root_container.focused->focused) { - return NULL; - } - swayc_t *lookup = root_container.focused->focused; - // Case of empty workspace - if (lookup->children == 0) { - return NULL; - } - while (lookup->type != C_VIEW) { - int i; - int len; - // if tabbed/stacked go directly to focused container, otherwise search - // children - if (lookup->layout == L_TABBED || lookup->layout == L_STACKED) { - lookup = lookup->focused; - continue; - } - // if workspace, search floating - if (lookup->type == C_WORKSPACE) { - i = len = lookup->floating->length; - bool got_floating = false; - while (--i > -1) { - if (pointer_test(lookup->floating->items[i], &pointer_state.origin)) { - lookup = lookup->floating->items[i]; - got_floating = true; - break; - } - } - if (got_floating) { - continue; - } - } - // search children - len = lookup->children->length; - for (i = 0; i < len; ++i) { - if (pointer_test(lookup->children->items[i], &pointer_state.origin)) { - lookup = lookup->children->items[i]; - break; - } - } - // when border and titles are done, this could happen - if (i == len) { - break; - } - } - return lookup; -} - /* Handles */ static bool handle_output_created(wlc_handle output) { -- cgit v1.2.3 From 4799d07ac1bb08a770ee702eb3fd0ab4654f878a Mon Sep 17 00:00:00 2001 From: "S. Christoffer Eliesen" Date: Wed, 28 Oct 2015 00:41:28 +0100 Subject: 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(-) (limited to 'sway/handlers.c') 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) { -- cgit v1.2.3 From 5ba47d4a44b21500ed3af2670cb1c807b7fed850 Mon Sep 17 00:00:00 2001 From: "S. Christoffer Eliesen" Date: Thu, 29 Oct 2015 18:02:02 +0100 Subject: input_state: Remove mouse_origin (x&y). Query wlc instead. --- include/input_state.h | 5 ----- sway/container.c | 8 +++++--- sway/handlers.c | 4 ---- sway/input_state.c | 20 ++++++++++++-------- 4 files changed, 17 insertions(+), 20 deletions(-) (limited to 'sway/handlers.c') diff --git a/include/input_state.h b/include/input_state.h index 52759052..a1f238e1 100644 --- a/include/input_state.h +++ b/include/input_state.h @@ -48,11 +48,6 @@ extern struct pointer_state { struct pointer_button_state right; struct pointer_button_state scroll; - // pointer position - struct mouse_origin{ - int x, y; - } origin; - // change in pointer position struct { int x, y; diff --git a/sway/container.c b/sway/container.c index 4f9e2b5e..f3e2b3ae 100644 --- a/sway/container.c +++ b/sway/container.c @@ -510,7 +510,7 @@ swayc_t *swayc_active_workspace_for(swayc_t *cont) { } static bool pointer_test(swayc_t *view, void *_origin) { - const struct mouse_origin *origin = _origin; + const struct wlc_origin *origin = _origin; // Determine the output that the view is under swayc_t *parent = swayc_parent_by_type(view, C_OUTPUT); if (origin->x >= view->x && origin->y >= view->y @@ -531,6 +531,8 @@ swayc_t *container_under_pointer(void) { if (lookup->children == 0) { return NULL; } + struct wlc_origin origin; + wlc_pointer_get_origin(&origin); while (lookup->type != C_VIEW) { int i; int len; @@ -545,7 +547,7 @@ swayc_t *container_under_pointer(void) { i = len = lookup->floating->length; bool got_floating = false; while (--i > -1) { - if (pointer_test(lookup->floating->items[i], &pointer_state.origin)) { + if (pointer_test(lookup->floating->items[i], &origin)) { lookup = lookup->floating->items[i]; got_floating = true; break; @@ -558,7 +560,7 @@ swayc_t *container_under_pointer(void) { // search children len = lookup->children->length; for (i = 0; i < len; ++i) { - if (pointer_test(lookup->children->items[i], &pointer_state.origin)) { + if (pointer_test(lookup->children->items[i], &origin)) { lookup = lookup->children->items[i]; break; } diff --git a/sway/handlers.c b/sway/handlers.c index e1612dc1..510b4261 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -343,10 +343,6 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w // Update view pointer is on pointer_state.view = container_under_pointer(); - // Update pointer origin - pointer_state.origin.x = origin->x; - pointer_state.origin.y = origin->y; - // Update pointer_state switch (button) { case M_LEFT_CLICK: diff --git a/sway/input_state.c b/sway/input_state.c index ee3dc7cf..9bd8ad4d 100644 --- a/sway/input_state.c +++ b/sway/input_state.c @@ -163,10 +163,10 @@ static void reset_initial_sibling(void) { } 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; + struct wlc_origin origin; + wlc_pointer_get_origin(&origin); + pointer_state.delta.x = new_origin->x - origin.x; + pointer_state.delta.y = new_origin->y - origin.y; // Update view under pointer swayc_t *prev_view = pointer_state.view; @@ -214,8 +214,10 @@ static void pointer_mode_set_right(void) { int midway_x = initial.ptr->x + initial.ptr->width/2; int midway_y = initial.ptr->y + initial.ptr->height/2; - lock.left = pointer_state.origin.x > midway_x; - lock.top = pointer_state.origin.y > midway_y; + struct wlc_origin origin; + wlc_pointer_get_origin(&origin); + lock.left = origin.x > midway_x; + lock.top = origin.y > midway_y; if (initial.ptr->is_floating) { pointer_state.mode = M_RESIZING | M_FLOATING; @@ -277,8 +279,10 @@ void pointer_mode_update(void) { pointer_state.mode = 0; return; } - int dx = pointer_state.origin.x; - int dy = pointer_state.origin.y; + struct wlc_origin origin; + wlc_pointer_get_origin(&origin); + int dx = origin.x; + int dy = origin.y; switch (pointer_state.mode) { case M_FLOATING | M_DRAGGING: -- cgit v1.2.3