aboutsummaryrefslogtreecommitdiff
path: root/sway/handlers.c
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2015-08-09 09:23:10 -0400
committerDrew DeVault <sir@cmpwn.com>2015-08-09 09:23:10 -0400
commitf97a48d5b75fd80a578af14f19d0b1d954f82fdd (patch)
treec99dcdd46754915d18445281d2778ea61be05f3b /sway/handlers.c
parent086691016e7cbe9794b73c174eaefa77e2d56498 (diff)
Implement focus_follows_mouse
Diffstat (limited to 'sway/handlers.c')
-rw-r--r--sway/handlers.c40
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;
+}