Skip to content

Commit

Permalink
Only reconfigure input mappings on output change
Browse files Browse the repository at this point in the history
Fully reconfiguring all input devices on output change takes a
loooong time. Let's just reconfigure what we need: only mappings
depend on outputs.
  • Loading branch information
emersion authored and kennylevinsen committed Nov 16, 2023
1 parent caa92dd commit 7036769
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 5 deletions.
2 changes: 2 additions & 0 deletions include/sway/input/input-manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ void input_manager_apply_input_config(struct input_config *input_config);

void input_manager_configure_all_inputs(void);

void input_manager_configure_all_input_mappings(void);

void input_manager_reset_input(struct sway_input_device *input_device);

void input_manager_reset_all_inputs(void);
Expand Down
3 changes: 3 additions & 0 deletions include/sway/input/seat.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ void seat_add_device(struct sway_seat *seat,
void seat_configure_device(struct sway_seat *seat,
struct sway_input_device *device);

void seat_configure_device_mapping(struct sway_seat *seat,
struct sway_input_device *input_device);

void seat_reset_device(struct sway_seat *seat,
struct sway_input_device *input_device);

Expand Down
2 changes: 1 addition & 1 deletion sway/config/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ bool apply_output_config(struct output_config *oc, struct sway_output *output) {
// Reconfigure all devices, since input config may have been applied before
// this output came online, and some config items (like map_to_output) are
// dependent on an output being present.
input_manager_configure_all_inputs();
input_manager_configure_all_input_mappings();
// Reconfigure the cursor images, since the scale may have changed.
input_manager_configure_xcursor();
return true;
Expand Down
10 changes: 10 additions & 0 deletions sway/input/input-manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,16 @@ void input_manager_configure_all_inputs(void) {
}
}

void input_manager_configure_all_input_mappings(void) {
struct sway_input_device *input_device;
wl_list_for_each(input_device, &server.input->devices, link) {
struct sway_seat *seat;
wl_list_for_each(seat, &server.input->seats, link) {
seat_configure_device_mapping(seat, input_device);
}
}
}

void input_manager_apply_input_config(struct input_config *input_config) {
struct sway_input_device *input_device = NULL;
bool wildcard = strcmp(input_config->identifier, "*") == 0;
Expand Down
24 changes: 21 additions & 3 deletions sway/input/seat.c
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,15 @@ static void seat_apply_input_mapping(struct sway_seat *seat,
struct input_config *ic =
input_device_get_config(sway_device->input_device);

switch (sway_device->input_device->wlr_device->type) {
case WLR_INPUT_DEVICE_POINTER:
case WLR_INPUT_DEVICE_TOUCH:
case WLR_INPUT_DEVICE_TABLET_TOOL:
break;
default:
return; // these devices don't support mappings
}

sway_log(SWAY_DEBUG, "Applying input mapping to %s",
sway_device->input_device->identifier);

Expand Down Expand Up @@ -799,7 +808,6 @@ static void seat_configure_pointer(struct sway_seat *seat,
}
wlr_cursor_attach_input_device(seat->cursor->cursor,
sway_device->input_device->wlr_device);
seat_apply_input_mapping(seat, sway_device);
wl_event_source_timer_update(
seat->cursor->hide_source, cursor_get_timeout(seat->cursor));
}
Expand Down Expand Up @@ -841,7 +849,6 @@ static void seat_configure_touch(struct sway_seat *seat,
struct sway_seat_device *sway_device) {
wlr_cursor_attach_input_device(seat->cursor->cursor,
sway_device->input_device->wlr_device);
seat_apply_input_mapping(seat, sway_device);
}

static void seat_configure_tablet_tool(struct sway_seat *seat,
Expand All @@ -852,7 +859,6 @@ static void seat_configure_tablet_tool(struct sway_seat *seat,
sway_configure_tablet(sway_device->tablet);
wlr_cursor_attach_input_device(seat->cursor->cursor,
sway_device->input_device->wlr_device);
seat_apply_input_mapping(seat, sway_device);
}

static void seat_configure_tablet_pad(struct sway_seat *seat,
Expand Down Expand Up @@ -909,6 +915,18 @@ void seat_configure_device(struct sway_seat *seat,
seat_configure_tablet_pad(seat, seat_device);
break;
}

seat_apply_input_mapping(seat, seat_device);
}

void seat_configure_device_mapping(struct sway_seat *seat,
struct sway_input_device *input_device) {
struct sway_seat_device *seat_device = seat_get_device(seat, input_device);
if (!seat_device) {
return;
}

seat_apply_input_mapping(seat, seat_device);
}

void seat_reset_device(struct sway_seat *seat,
Expand Down
2 changes: 1 addition & 1 deletion sway/tree/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ void output_disable(struct sway_output *output) {
// Reconfigure all devices, since devices with map_to_output directives for
// an output that goes offline should stop sending events as long as the
// output remains offline.
input_manager_configure_all_inputs();
input_manager_configure_all_input_mappings();
}

void output_begin_destroy(struct sway_output *output) {
Expand Down

0 comments on commit 7036769

Please sign in to comment.