diff --git a/src/evdev-fallback.c b/src/evdev-fallback.c index acc5d38a1cb507f06b51e87b2f7fbe41ba71eb9f..7dad0fcee478f12e888f39acc67b77cf2c3d0df6 100644 --- a/src/evdev-fallback.c +++ b/src/evdev-fallback.c @@ -636,7 +636,7 @@ fallback_lid_keyboard_event(uint64_t time, static void fallback_lid_toggle_keyboard_listener(struct fallback_dispatch *dispatch, - struct paired_keyboard *kbd, + struct evdev_paired_keyboard *kbd, bool is_closed) { assert(kbd->device); @@ -658,7 +658,7 @@ static void fallback_lid_toggle_keyboard_listeners(struct fallback_dispatch *dispatch, bool is_closed) { - struct paired_keyboard *kbd; + struct evdev_paired_keyboard *kbd; list_for_each(kbd, &dispatch->lid.paired_keyboard_list, link) { if (!kbd->device) @@ -1006,20 +1006,11 @@ fallback_interface_suspend(struct evdev_dispatch *evdev_dispatch, fallback_return_to_neutral_state(dispatch, device); } -static void -fallback_paired_keyboard_destroy(struct paired_keyboard *kbd) -{ - kbd->device = NULL; - libinput_device_remove_event_listener(&kbd->listener); - list_remove(&kbd->link); - free(kbd); -} - static void fallback_interface_remove(struct evdev_dispatch *evdev_dispatch) { struct fallback_dispatch *dispatch = fallback_dispatch(evdev_dispatch); - struct paired_keyboard *kbd, *tmp; + struct evdev_paired_keyboard *kbd, *tmp; libinput_device_remove_event_listener(&dispatch->tablet_mode.other.listener); @@ -1027,7 +1018,7 @@ fallback_interface_remove(struct evdev_dispatch *evdev_dispatch) tmp, &dispatch->lid.paired_keyboard_list, link) { - fallback_paired_keyboard_destroy(kbd); + evdev_paired_keyboard_destroy(kbd); } } @@ -1104,7 +1095,7 @@ fallback_lid_pair_keyboard(struct evdev_device *lid_switch, { struct fallback_dispatch *dispatch = fallback_dispatch(lid_switch->dispatch); - struct paired_keyboard *kbd; + struct evdev_paired_keyboard *kbd; size_t count = 0; if ((keyboard->tags & EVDEV_TAG_KEYBOARD) == 0 || @@ -1238,7 +1229,7 @@ fallback_interface_device_removed(struct evdev_device *device, { struct fallback_dispatch *dispatch = fallback_dispatch(device->dispatch); - struct paired_keyboard *kbd, *tmp; + struct evdev_paired_keyboard *kbd, *tmp; list_for_each_safe(kbd, tmp, @@ -1250,7 +1241,7 @@ fallback_interface_device_removed(struct evdev_device *device, if (kbd->device != removed_device) continue; - fallback_paired_keyboard_destroy(kbd); + evdev_paired_keyboard_destroy(kbd); } if (removed_device == dispatch->tablet_mode.other.sw_device) { diff --git a/src/evdev-fallback.h b/src/evdev-fallback.h index ca48f1333fe0ce59ca81ce18286b2feee2ed5afa..15766a7c2c6e113b085cdbde8bc2dd1e8bfd92cc 100644 --- a/src/evdev-fallback.h +++ b/src/evdev-fallback.h @@ -45,12 +45,6 @@ enum debounce_state { DEBOUNCE_STATE_DISABLED = 999, }; -struct paired_keyboard { - struct list link; - struct evdev_device *device; - struct libinput_event_listener listener; -}; - struct fallback_dispatch { struct evdev_dispatch base; struct evdev_device *device; diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c index 02b755316c92d19068076c3575bee4707ff732e0..b1543dae6f0359e5afb1d820d2dd518bf8c12117 100644 --- a/src/evdev-mt-touchpad.c +++ b/src/evdev-mt-touchpad.c @@ -1756,7 +1756,7 @@ tp_interface_process(struct evdev_dispatch *dispatch, static void tp_remove_sendevents(struct tp_dispatch *tp) { - struct paired_keyboard *kbd; + struct evdev_paired_keyboard *kbd; libinput_timer_cancel(&tp->palm.trackpoint_timer); libinput_timer_cancel(&tp->dwt.keyboard_timer); @@ -1766,9 +1766,8 @@ tp_remove_sendevents(struct tp_dispatch *tp) libinput_device_remove_event_listener( &tp->palm.trackpoint_listener); - ARRAY_FOR_EACH(tp->dwt.paired_keyboard, kbd) { - if (kbd->device) - libinput_device_remove_event_listener(&kbd->listener); + list_for_each(kbd, &tp->dwt.paired_keyboard_list, link) { + libinput_device_remove_event_listener(&kbd->listener); } if (tp->lid_switch.lid_switch) @@ -2135,8 +2134,8 @@ tp_dwt_pair_keyboard(struct evdev_device *touchpad, struct evdev_device *keyboard) { struct tp_dispatch *tp = (struct tp_dispatch*)touchpad->dispatch; - struct paired_keyboard *kbd; - bool found = false; + struct evdev_paired_keyboard *kbd; + size_t count = 0; if ((keyboard->tags & EVDEV_TAG_KEYBOARD) == 0) return; @@ -2144,25 +2143,25 @@ tp_dwt_pair_keyboard(struct evdev_device *touchpad, if (!tp_want_dwt(touchpad, keyboard)) return; - ARRAY_FOR_EACH(tp->dwt.paired_keyboard, kbd) { - if (kbd->device) - continue; - - found = true; - libinput_device_add_event_listener(&keyboard->base, - &kbd->listener, - tp_keyboard_event, tp); - kbd->device = keyboard; - evdev_log_debug(touchpad, - "palm: dwt activated with %s<->%s\n", - touchpad->devname, - keyboard->devname); - break; + list_for_each(kbd, &tp->dwt.paired_keyboard_list, link) { + count++; + if (count > 3) { + evdev_log_info(touchpad, + "too many internal keyboards for dwt\n"); + break; + } } - if (!found) - evdev_log_bug_libinput(touchpad, - "too many internal keyboards for dwt\n"); + kbd = zalloc(sizeof(*kbd)); + kbd->device = keyboard; + libinput_device_add_event_listener(&keyboard->base, + &kbd->listener, + tp_keyboard_event, tp); + list_insert(&tp->dwt.paired_keyboard_list, &kbd->link); + evdev_log_debug(touchpad, + "palm: dwt activated with %s<->%s\n", + touchpad->devname, + keyboard->devname); } static void @@ -2320,7 +2319,7 @@ tp_interface_device_removed(struct evdev_device *device, struct evdev_device *removed_device) { struct tp_dispatch *tp = (struct tp_dispatch*)device->dispatch; - struct paired_keyboard *kbd; + struct evdev_paired_keyboard *kbd, *tmp; if (removed_device == tp->buttons.trackpoint) { /* Clear any pending releases for the trackpoint */ @@ -2334,10 +2333,9 @@ tp_interface_device_removed(struct evdev_device *device, tp->buttons.trackpoint = NULL; } - ARRAY_FOR_EACH(tp->dwt.paired_keyboard, kbd) { + list_for_each_safe(kbd, tmp, &tp->dwt.paired_keyboard_list, link) { if (kbd->device == removed_device) { - libinput_device_remove_event_listener(&kbd->listener); - kbd->device = NULL; + evdev_paired_keyboard_destroy(kbd); tp->dwt.keyboard_active = false; } } @@ -3301,6 +3299,7 @@ tp_init(struct tp_dispatch *tp, tp->base.dispatch_type = DISPATCH_TOUCHPAD; tp->base.interface = &tp_interface; tp->device = device; + list_init(&tp->dwt.paired_keyboard_list); if (!tp_pass_sanity_check(tp, device)) return false; diff --git a/src/evdev-mt-touchpad.h b/src/evdev-mt-touchpad.h index 230ed88d26b8190a64630039e6b004f14ee73297..90c20325b58624afc749d8d54b9ed56905f5598f 100644 --- a/src/evdev-mt-touchpad.h +++ b/src/evdev-mt-touchpad.h @@ -417,10 +417,7 @@ struct tp_dispatch { * physical device, so we don't care about per-keyboard * key/modifier masks. */ - struct paired_keyboard { - struct evdev_device *device; - struct libinput_event_listener listener; - } paired_keyboard[3]; + struct list paired_keyboard_list; unsigned long key_mask[NLONGS(KEY_CNT)]; unsigned long mod_mask[NLONGS(KEY_CNT)]; diff --git a/src/evdev.h b/src/evdev.h index 0a7de392099c45d8f6a1765ab5f6a6c8dc086cc8..0d325fadaa703d5663cd9fcaebbdc143bd07debe 100644 --- a/src/evdev.h +++ b/src/evdev.h @@ -933,4 +933,19 @@ evdev_device_check_abs_axis_range(struct evdev_device *device, } } +struct evdev_paired_keyboard { + struct list link; + struct evdev_device *device; + struct libinput_event_listener listener; +}; + +static inline void +evdev_paired_keyboard_destroy(struct evdev_paired_keyboard *kbd) +{ + kbd->device = NULL; + libinput_device_remove_event_listener(&kbd->listener); + list_remove(&kbd->link); + free(kbd); +} + #endif /* EVDEV_H */