aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Simon Ser <contact@emersion.fr>2023-12-30 20:22:01 +0100
committerLibravatar Kenny Levinsen <kl@kl.wtf>2024-01-02 14:07:35 +0100
commit95265fba59bce77ed52a74fcc21abf7f668c01b2 (patch)
treebe79909a28e9fb2c015978fe400f0188293d1e51
parentRemove wlr_presentation in sway_server struct (diff)
downloadsway-95265fba59bce77ed52a74fcc21abf7f668c01b2.tar.gz
sway-95265fba59bce77ed52a74fcc21abf7f668c01b2.tar.zst
sway-95265fba59bce77ed52a74fcc21abf7f668c01b2.zip
input: reconfigure send_events on output hotplug
Closes: https://github.com/swaywm/sway/issues/7890
-rw-r--r--include/sway/input/libinput.h3
-rw-r--r--sway/input/input-manager.c7
-rw-r--r--sway/input/libinput.c54
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
5bool sway_input_configure_libinput_device(struct sway_input_device *device); 5bool sway_input_configure_libinput_device(struct sway_input_device *device);
6 6
7void sway_input_configure_libinput_device_send_events(
8 struct sway_input_device *device);
9
7void sway_input_reset_libinput_device(struct sway_input_device *device); 10void sway_input_reset_libinput_device(struct sway_input_device *device);
8 11
9bool sway_libinput_device_is_builtin(struct sway_input_device *device); 12bool 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 4febc333..c1bbdde0 100644
--- a/sway/input/input-manager.c
+++ b/sway/input/input-manager.c
@@ -534,6 +534,13 @@ void input_manager_configure_all_input_mappings(void) {
534 wl_list_for_each(seat, &server.input->seats, link) { 534 wl_list_for_each(seat, &server.input->seats, link) {
535 seat_configure_device_mapping(seat, input_device); 535 seat_configure_device_mapping(seat, input_device);
536 } 536 }
537
538#if WLR_HAS_LIBINPUT_BACKEND
539 // Input devices mapped to unavailable outputs get their libinput
540 // send_events setting switched to false. We need to re-enable this
541 // when the output appears.
542 sway_input_configure_libinput_device_send_events(input_device);
543#endif
537 } 544 }
538} 545}
539 546
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
222bool sway_input_configure_libinput_device(struct sway_input_device *input_device) { 222static 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
242bool 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
309void 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
307void sway_input_reset_libinput_device(struct sway_input_device *input_device) { 325void 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;