Commit d376db06 authored by Peter Hutterer's avatar Peter Hutterer

touchpad: make the dwt paired keyboard list a struct list

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's avatarPeter Hutterer <peter.hutterer@who-t.net>
parent bcbc8736
......@@ -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) {
......
......@@ -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;
......
......@@ -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;
......
......@@ -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)];
......
......@@ -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 */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment