diff options
Diffstat (limited to 'sway/handlers.c')
-rw-r--r-- | sway/handlers.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/sway/handlers.c b/sway/handlers.c index f1098835..0c0fb85f 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -83,3 +83,43 @@ bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifiers } return ret; } + +bool pointer_test(swayc_t *view, void *_origin) { + const struct wlc_origin *origin = _origin; + if (view->type == C_VIEW && origin->x >= view->x && origin->y >= view->y + && origin->x < view->x + view->width && origin->y < view->y + view->height) { + return true; + } + return false; +} + +struct wlc_origin mouse_origin; + +bool handle_pointer_motion(wlc_handle view, uint32_t time, const struct wlc_origin *origin) { + mouse_origin = *origin; + if (!config->focus_follows_mouse) { + return true; + } + swayc_t *c = find_container(&root_container, pointer_test, (void *)origin); + swayc_t *focused = get_focused_container(&root_container); + if (c && c != focused) { + sway_log(L_DEBUG, "Switching focus to %p", c); + focus_view(c); + } + return true; +} + +bool handle_pointer_button(wlc_handle view, uint32_t time, const struct wlc_modifiers *modifiers, + uint32_t button, enum wlc_button_state state) { + if (state == WLC_BUTTON_STATE_PRESSED) { + swayc_t *c = find_container(&root_container, pointer_test, &mouse_origin); + swayc_t *focused = get_focused_container(&root_container); + if (c && c != focused) { + sway_log(L_DEBUG, "Switching focus to %p", c); + focus_view(c); + return false; + } + return true; + } + return true; +} |