Skip to content

Commit

Permalink
seat: Avoid sending redundant keymaps on reload
Browse files Browse the repository at this point in the history
When we reload the config, we reset every input device and re-apply
configuration from the config file. This means that the keyboard keymap
is updated at least once during config reload, more if the config file
contains keyboard configuration.

When they keyboard keymap changes and is updated through wlr_seat, the
keymap ends up sent to every keyboard bound in every client, seemingly
multiple times. On an x230 of mine with a keyboard layout set in the
config file, I see 42 keymap events sent to foot on config reload.

Reduce events from keyboard configurations by skipping all but the
currently active keyboard for the seat, and by clearing the active
keyboard during input manager device reset. After this change, I only
see a single just-in-time keymap event.

Fixes: swaywm/sway#6654
  • Loading branch information
kennylevinsen authored and Ronan Pigott committed Dec 4, 2022
1 parent 6b3245a commit e1b268a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
8 changes: 7 additions & 1 deletion sway/input/input-manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,13 @@ void input_manager_reset_input(struct sway_input_device *input_device) {
}

void input_manager_reset_all_inputs(void) {
// Set the active keyboard to NULL to avoid spamming configuration updates
// for all keyboard devices.
struct sway_seat *seat;
wl_list_for_each(seat, &server.input->seats, link) {
wlr_seat_set_keyboard(seat->wlr_seat, NULL);
}

struct sway_input_device *input_device = NULL;
wl_list_for_each(input_device, &server.input->devices, link) {
input_manager_reset_input(input_device);
Expand All @@ -601,7 +608,6 @@ void input_manager_reset_all_inputs(void) {
// If there is at least one keyboard using the default keymap, repeat delay,
// and repeat rate, then it is possible that there is a keyboard group that
// need their keyboard disarmed.
struct sway_seat *seat;
wl_list_for_each(seat, &server.input->seats, link) {
struct sway_keyboard_group *group;
wl_list_for_each(group, &seat->keyboard_groups, link) {
Expand Down
3 changes: 0 additions & 3 deletions sway/input/keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -1070,9 +1070,6 @@ void sway_keyboard_configure(struct sway_keyboard *keyboard) {
}
}

struct wlr_seat *seat = keyboard->seat_device->sway_seat->wlr_seat;
wlr_seat_set_keyboard(seat, keyboard->wlr);

wl_list_remove(&keyboard->keyboard_key.link);
wl_signal_add(&keyboard->wlr->events.key, &keyboard->keyboard_key);
keyboard->keyboard_key.notify = handle_keyboard_key;
Expand Down
11 changes: 9 additions & 2 deletions sway/input/seat.c
Original file line number Diff line number Diff line change
Expand Up @@ -823,8 +823,15 @@ static void seat_configure_keyboard(struct sway_seat *seat,
sway_keyboard_create(seat, seat_device);
}
sway_keyboard_configure(seat_device->keyboard);
wlr_seat_set_keyboard(seat->wlr_seat,
wlr_keyboard_from_input_device(seat_device->input_device->wlr_device));

// We only need to update the current keyboard, as the rest will be updated
// as they are activated.
struct wlr_keyboard *wlr_keyboard =
wlr_keyboard_from_input_device(seat_device->input_device->wlr_device);
struct wlr_keyboard *current_keyboard = seat->wlr_seat->keyboard_state.keyboard;
if (wlr_keyboard != current_keyboard) {
return;
}

// force notify reenter to pick up the new configuration. This reuses
// the current focused surface to avoid breaking input grabs.
Expand Down

0 comments on commit e1b268a

Please sign in to comment.