diff options
author | Simon Ser <contact@emersion.fr> | 2023-12-30 20:22:01 +0100 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2024-01-26 15:14:37 +0100 |
commit | 37fce86c32fc30314f927ca3d2daef697293a9f6 (patch) | |
tree | 0c05b87907484424a347b56afeb3770716e00421 | |
parent | output: Destroy when output layout is destroyed (diff) | |
download | sway-37fce86c32fc30314f927ca3d2daef697293a9f6.tar.gz sway-37fce86c32fc30314f927ca3d2daef697293a9f6.tar.zst sway-37fce86c32fc30314f927ca3d2daef697293a9f6.zip |
input: reconfigure send_events on output hotplug
Closes: https://github.com/swaywm/sway/issues/7890
(cherry picked from commit 95265fba59bce77ed52a74fcc21abf7f668c01b2)
-rw-r--r-- | include/sway/input/libinput.h | 3 | ||||
-rw-r--r-- | sway/input/input-manager.c | 7 | ||||
-rw-r--r-- | sway/input/libinput.c | 54 |
3 files changed, 46 insertions, 18 deletions
diff --git a/include/sway/input/libinput.h b/include/sway/input/libinput.h index e4b1acc3..1f84a8e3 100644 --- a/include/sway/input/libinput.h +++ b/include/sway/input/libinput.h | |||
@@ -4,6 +4,9 @@ | |||
4 | 4 | ||
5 | bool sway_input_configure_libinput_device(struct sway_input_device *device); | 5 | bool sway_input_configure_libinput_device(struct sway_input_device *device); |
6 | 6 | ||
7 | void sway_input_configure_libinput_device_send_events( | ||
8 | struct sway_input_device *device); | ||
9 | |||
7 | void sway_input_reset_libinput_device(struct sway_input_device *device); | 10 | void sway_input_reset_libinput_device(struct sway_input_device *device); |
8 | 11 | ||
9 | bool sway_libinput_device_is_builtin(struct sway_input_device *device); | 12 | bool sway_libinput_device_is_builtin(struct sway_input_device *device); |
diff --git a/sway/input/input-manager.c b/sway/input/input-manager.c index dcaeb056..288fddc4 100644 --- a/sway/input/input-manager.c +++ b/sway/input/input-manager.c | |||
@@ -571,6 +571,13 @@ void input_manager_configure_all_input_mappings(void) { | |||
571 | wl_list_for_each(seat, &server.input->seats, link) { | 571 | wl_list_for_each(seat, &server.input->seats, link) { |
572 | seat_configure_device_mapping(seat, input_device); | 572 | seat_configure_device_mapping(seat, input_device); |
573 | } | 573 | } |
574 | |||
575 | #if WLR_HAS_LIBINPUT_BACKEND | ||
576 | // Input devices mapped to unavailable outputs get their libinput | ||
577 | // send_events setting switched to false. We need to re-enable this | ||
578 | // when the output appears. | ||
579 | sway_input_configure_libinput_device_send_events(input_device); | ||
580 | #endif | ||
574 | } | 581 | } |
575 | } | 582 | } |
576 | 583 | ||
diff --git a/sway/input/libinput.c b/sway/input/libinput.c index 43875634..0266c7a9 100644 --- a/sway/input/libinput.c +++ b/sway/input/libinput.c | |||
@@ -219,36 +219,38 @@ static bool set_calibration_matrix(struct libinput_device *dev, float mat[6]) { | |||
219 | return changed; | 219 | return changed; |
220 | } | 220 | } |
221 | 221 | ||
222 | bool sway_input_configure_libinput_device(struct sway_input_device *input_device) { | 222 | static bool configure_send_events(struct libinput_device *device, |
223 | struct input_config *ic = input_device_get_config(input_device); | 223 | struct input_config *ic) { |
224 | if (!ic || !wlr_input_device_is_libinput(input_device->wlr_device)) { | ||
225 | return false; | ||
226 | } | ||
227 | |||
228 | struct libinput_device *device = | ||
229 | wlr_libinput_get_device_handle(input_device->wlr_device); | ||
230 | sway_log(SWAY_DEBUG, "sway_input_configure_libinput_device('%s' on '%s')", | ||
231 | ic->identifier, input_device->identifier); | ||
232 | |||
233 | bool changed = false; | ||
234 | if (ic->mapped_to_output && | 224 | if (ic->mapped_to_output && |
235 | strcmp("*", ic->mapped_to_output) != 0 && | 225 | strcmp("*", ic->mapped_to_output) != 0 && |
236 | !output_by_name_or_id(ic->mapped_to_output)) { | 226 | !output_by_name_or_id(ic->mapped_to_output)) { |
237 | sway_log(SWAY_DEBUG, | 227 | sway_log(SWAY_DEBUG, |
238 | "%s '%s' is mapped to offline output '%s'; disabling input", | 228 | "%s '%s' is mapped to offline output '%s'; disabling input", |
239 | ic->input_type, ic->identifier, ic->mapped_to_output); | 229 | ic->input_type, ic->identifier, ic->mapped_to_output); |
240 | changed |= set_send_events(device, | 230 | return set_send_events(device, LIBINPUT_CONFIG_SEND_EVENTS_DISABLED); |
241 | LIBINPUT_CONFIG_SEND_EVENTS_DISABLED); | ||
242 | } else if (ic->send_events != INT_MIN) { | 231 | } else if (ic->send_events != INT_MIN) { |
243 | changed |= set_send_events(device, ic->send_events); | 232 | return set_send_events(device, ic->send_events); |
244 | } else { | 233 | } else { |
245 | // Have to reset to the default mode here, otherwise if ic->send_events | 234 | // Have to reset to the default mode here, otherwise if ic->send_events |
246 | // is unset and a mapped output just came online after being disabled, | 235 | // is unset and a mapped output just came online after being disabled, |
247 | // we'd remain stuck sending no events. | 236 | // we'd remain stuck sending no events. |
248 | changed |= set_send_events(device, | 237 | return set_send_events(device, |
249 | libinput_device_config_send_events_get_default_mode(device)); | 238 | libinput_device_config_send_events_get_default_mode(device)); |
250 | } | 239 | } |
240 | } | ||
241 | |||
242 | bool sway_input_configure_libinput_device(struct sway_input_device *input_device) { | ||
243 | struct input_config *ic = input_device_get_config(input_device); | ||
244 | if (!ic || !wlr_input_device_is_libinput(input_device->wlr_device)) { | ||
245 | return false; | ||
246 | } | ||
251 | 247 | ||
248 | struct libinput_device *device = | ||
249 | wlr_libinput_get_device_handle(input_device->wlr_device); | ||
250 | sway_log(SWAY_DEBUG, "sway_input_configure_libinput_device('%s' on '%s')", | ||
251 | ic->identifier, input_device->identifier); | ||
252 | |||
253 | bool changed = configure_send_events(device, ic); | ||
252 | if (ic->tap != INT_MIN) { | 254 | if (ic->tap != INT_MIN) { |
253 | changed |= set_tap(device, ic->tap); | 255 | changed |= set_tap(device, ic->tap); |
254 | } | 256 | } |
@@ -304,6 +306,22 @@ bool sway_input_configure_libinput_device(struct sway_input_device *input_device | |||
304 | return changed; | 306 | return changed; |
305 | } | 307 | } |
306 | 308 | ||
309 | void sway_input_configure_libinput_device_send_events( | ||
310 | struct sway_input_device *input_device) { | ||
311 | struct input_config *ic = input_device_get_config(input_device); | ||
312 | if (!ic || !wlr_input_device_is_libinput(input_device->wlr_device)) { | ||
313 | return; | ||
314 | } | ||
315 | |||
316 | struct libinput_device *device = | ||
317 | wlr_libinput_get_device_handle(input_device->wlr_device); | ||
318 | bool changed = configure_send_events(device, ic); | ||
319 | |||
320 | if (changed) { | ||
321 | ipc_event_input("libinput_config", input_device); | ||
322 | } | ||
323 | } | ||
324 | |||
307 | void sway_input_reset_libinput_device(struct sway_input_device *input_device) { | 325 | void sway_input_reset_libinput_device(struct sway_input_device *input_device) { |
308 | if (!wlr_input_device_is_libinput(input_device->wlr_device)) { | 326 | if (!wlr_input_device_is_libinput(input_device->wlr_device)) { |
309 | return; | 327 | return; |