From 7036769bea886ab1f9d627785f14cea9e25b16f7 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Thu, 16 Nov 2023 14:56:46 +0100 Subject: [PATCH] Only reconfigure input mappings on output change Fully reconfiguring all input devices on output change takes a loooong time. Let's just reconfigure what we need: only mappings depend on outputs. --- include/sway/input/input-manager.h | 2 ++ include/sway/input/seat.h | 3 +++ sway/config/output.c | 2 +- sway/input/input-manager.c | 10 ++++++++++ sway/input/seat.c | 24 +++++++++++++++++++++--- sway/tree/output.c | 2 +- 6 files changed, 38 insertions(+), 5 deletions(-) diff --git a/include/sway/input/input-manager.h b/include/sway/input/input-manager.h index b651e3dd..6652d60c 100644 --- a/include/sway/input/input-manager.h +++ b/include/sway/input/input-manager.h @@ -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); diff --git a/include/sway/input/seat.h b/include/sway/input/seat.h index 35a96ace..97e81c19 100644 --- a/include/sway/input/seat.h +++ b/include/sway/input/seat.h @@ -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); diff --git a/sway/config/output.c b/sway/config/output.c index eefde22b..3316085a 100644 --- a/sway/config/output.c +++ b/sway/config/output.c @@ -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; diff --git a/sway/input/input-manager.c b/sway/input/input-manager.c index db82bb4c..5300919a 100644 --- a/sway/input/input-manager.c +++ b/sway/input/input-manager.c @@ -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; diff --git a/sway/input/seat.c b/sway/input/seat.c index bafdbcf3..f73946b1 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -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); @@ -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)); } @@ -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, @@ -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, @@ -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, diff --git a/sway/tree/output.c b/sway/tree/output.c index 0960f413..4aa3a7fe 100644 --- a/sway/tree/output.c +++ b/sway/tree/output.c @@ -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) {