This removes the artificial 3 keyboard limit. If you have more internal
keyboards than that, something is wrong in your setup but that shouldn't stop
us from working. Or more specificially: this can happen easily when running
tests so let's not fail the test suite because we created a few hundred
keyboards.

We'll still throw out a log message though.

Signed-off-by: Peter Hutterer <[email protected]>
---
 src/evdev-fallback.c    | 23 +++++++--------------
 src/evdev-fallback.h    |  6 ------
 src/evdev-mt-touchpad.c | 55 ++++++++++++++++++++++++-------------------------
 src/evdev-mt-touchpad.h |  5 +----
 src/evdev.h             | 15 ++++++++++++++
 5 files changed, 50 insertions(+), 54 deletions(-)

diff --git a/src/evdev-fallback.c b/src/evdev-fallback.c
index acc5d38a..7dad0fce 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 ca48f133..15766a7c 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 02b75531..b1543dae 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;
-       }
-
-       if (!found)
-               evdev_log_bug_libinput(touchpad,
+       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;
+               }
+       }
+
+       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 230ed88d..90c20325 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 0a7de392..0d325fad 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 */
-- 
2.14.3

_______________________________________________
wayland-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/wayland-devel

Reply via email to