Skip to content

Commit

Permalink
input: Propagate modifiers to clients with only pointer focus
Browse files Browse the repository at this point in the history
When focus_follows_mouse is off, it is possible to hover and/or scroll
windows without giving them keyboard focus.  However, attempts to use
Ctrl+scroll on such clients will not work correctly because the keyboard
modifiers are not available.  This patch propagates modifier state to
the client with pointer focus when it gains focus and when the state
changes.

This depends on https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/4523.

https://gitlab.freedesktop.org/wayland/wayland/-/merge_requests/259
discusses permitting this behavior at the protocol level.
  • Loading branch information
danieldg committed Jan 24, 2024
1 parent a4e8533 commit 5242a93
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 4 additions & 1 deletion sway/input/keyboard.c
Expand Up @@ -659,10 +659,13 @@ static void handle_modifier_event(struct sway_keyboard *keyboard) {
wlr_input_method_keyboard_grab_v2_send_modifiers(kb_grab,
&keyboard->wlr->modifiers);
} else {
struct wlr_seat *wlr_seat = keyboard->seat_device->sway_seat->wlr_seat;
struct sway_seat *seat = keyboard->seat_device->sway_seat;
struct wlr_seat *wlr_seat = seat->wlr_seat;
wlr_seat_set_keyboard(wlr_seat, keyboard->wlr);
wlr_seat_keyboard_notify_modifiers(wlr_seat,
&keyboard->wlr->modifiers);
wlr_seat_client_notify_modifiers(wlr_seat,
wlr_seat->pointer_state.focused_client);
}

uint32_t modifiers = wlr_keyboard_get_modifiers(keyboard->wlr);
Expand Down
13 changes: 13 additions & 0 deletions sway/input/seatop_default.c
Expand Up @@ -609,15 +609,28 @@ static void handle_pointer_motion(struct sway_seat *seat, uint32_t time_msec) {
double sx, sy;
struct sway_node *node = node_at_coords(seat,
cursor->cursor->x, cursor->cursor->y, &surface, &sx, &sy);
struct wlr_seat_client *prev_focus_seat_client;
struct wlr_seat_client *curr_focus_seat_client;
struct wl_client *prev_focus_client;
struct wl_client *curr_focus_client;

if (config->focus_follows_mouse != FOLLOWS_NO) {
check_focus_follows_mouse(seat, e, node);
}

if (surface) {
if (seat_is_input_allowed(seat, surface)) {
prev_focus_seat_client = seat->wlr_seat->pointer_state.focused_client;
prev_focus_client = prev_focus_seat_client ? prev_focus_seat_client->client : NULL;

wlr_seat_pointer_notify_enter(seat->wlr_seat, surface, sx, sy);
wlr_seat_pointer_notify_motion(seat->wlr_seat, time_msec, sx, sy);

curr_focus_seat_client = seat->wlr_seat->pointer_state.focused_client;
curr_focus_client = curr_focus_seat_client ? curr_focus_seat_client->client : NULL;

if (prev_focus_client != curr_focus_client)
wlr_seat_client_notify_modifiers(seat->wlr_seat, curr_focus_seat_client);
}
} else {
cursor_update_image(cursor, node);
Expand Down

0 comments on commit 5242a93

Please sign in to comment.