mirror of
https://github.com/swaywm/sway.git
synced 2025-11-08 13:29:50 -05:00
Implement focus_follows_mouse
This commit is contained in:
parent
086691016e
commit
f97a48d5b7
8 changed files with 118 additions and 26 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue