From 2d1bcf982ab6b26180c4a45e04f244592f4a7832 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 17 Jan 2019 11:08:27 +1000 Subject: pad: add LIBINPUT_EVENT_TABLET_PAD_KEY for pad keys The Wacom Cintiq 24HD and later tablets send specific key events for hardware/soft buttons. KEY_PROG1..KEY_PROG3 on earlier tablets, KEY_CONTROLPANEL, KEY_ONSCREEN_DISPLAY, and KEY_BUTTONCONFIG on later tablets. We ignore KEY_PROG1-3 because starting with kernel 5.4 older tablets will too use the better-named #defines. These differ from pad buttons as the key code in itself carries semantic information, so we should pass them on as-is instead of mapping them to meaningless 0-indexed buttons like we do on the other buttons. So let's add a new event, LIBINPUT_EVENT_TABLET_PAD_KEY and the associated functions to handle that case. Pad keys have a fixed hw-defined semantic meaning and are thus not part of a tablet mode group. Signed-off-by: Peter Hutterer --- src/evdev-tablet-pad.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src/evdev-tablet-pad.c') diff --git a/src/evdev-tablet-pad.c b/src/evdev-tablet-pad.c index 431972ae..97fc9717 100644 --- a/src/evdev-tablet-pad.c +++ b/src/evdev-tablet-pad.c @@ -392,6 +392,10 @@ pad_notify_button_mask(struct pad_dispatch *pad, button, state, group); + } else if (map_is_key(map)) { + uint32_t key = map_value(map); + + tablet_pad_notify_key(base, time, key, state); } else { abort(); } @@ -611,6 +615,26 @@ pad_init_buttons_from_kernel(struct pad_dispatch *pad, pad->nbuttons = map; } +static void +pad_init_keys(struct pad_dispatch *pad, struct evdev_device *device) +{ + unsigned int codes[] = { + KEY_BUTTONCONFIG, + KEY_ONSCREEN_KEYBOARD, + KEY_CONTROLPANEL, + }; + unsigned int *code; + + /* Wacom's keys are the only ones we know anything about */ + if (libevdev_get_id_vendor(device->evdev) != VENDOR_ID_WACOM) + return; + + ARRAY_FOR_EACH(codes, code) { + if (libevdev_has_event_code(device->evdev, EV_KEY, *code)) + map_set_key_map(pad->button_map[*code], *code); + } +} + static void pad_init_buttons(struct pad_dispatch *pad, struct evdev_device *device) @@ -623,6 +647,7 @@ pad_init_buttons(struct pad_dispatch *pad, if (!pad_init_buttons_from_libwacom(pad, device)) pad_init_buttons_from_kernel(pad, device); + pad_init_keys(pad, device); } static void @@ -718,6 +743,15 @@ evdev_tablet_pad_create(struct evdev_device *device) return &pad->base; } +int +evdev_device_tablet_pad_has_key(struct evdev_device *device, uint32_t code) +{ + if (!(device->seat_caps & EVDEV_DEVICE_TABLET_PAD)) + return -1; + + return libevdev_has_event_code(device->evdev, EV_KEY, code); +} + int evdev_device_tablet_pad_get_num_buttons(struct evdev_device *device) { -- cgit v1.2.1