summaryrefslogtreecommitdiff
path: root/test/test-pad.c
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2019-01-17 11:08:27 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2019-12-04 15:38:39 +1000
commit2d1bcf982ab6b26180c4a45e04f244592f4a7832 (patch)
treee2dfed37cba242d9845caa844e7e58f78c88ce4e /test/test-pad.c
parent27fda918d8a3aeb46e3884bffcf8b406ce496f07 (diff)
downloadlibinput-2d1bcf982ab6b26180c4a45e04f244592f4a7832.tar.gz
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 <peter.hutterer@who-t.net>
Diffstat (limited to 'test/test-pad.c')
-rw-r--r--test/test-pad.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/test/test-pad.c b/test/test-pad.c
index 6ba8925c..9eba7182 100644
--- a/test/test-pad.c
+++ b/test/test-pad.c
@@ -916,6 +916,72 @@ START_TEST(pad_mode_group_has_no_toggle)
}
END_TEST
+static bool
+pad_has_keys(struct litest_device *dev)
+{
+ struct libevdev *evdev = dev->evdev;
+
+ return (libevdev_has_event_code(evdev, EV_KEY, KEY_BUTTONCONFIG) ||
+ libevdev_has_event_code(evdev, EV_KEY, KEY_ONSCREEN_KEYBOARD) ||
+ libevdev_has_event_code(evdev, EV_KEY, KEY_CONTROLPANEL));
+}
+
+static void
+pad_key_down(struct litest_device *dev, unsigned int which)
+{
+ litest_event(dev, EV_ABS, ABS_MISC, 15);
+ litest_event(dev, EV_KEY, which, 1);
+ litest_event(dev, EV_SYN, SYN_REPORT, 0);
+}
+
+static void
+pad_key_up(struct litest_device *dev, unsigned int which)
+{
+ litest_event(dev, EV_ABS, ABS_MISC, 0);
+ litest_event(dev, EV_KEY, which, 0);
+ litest_event(dev, EV_SYN, SYN_REPORT, 0);
+}
+
+START_TEST(pad_keys)
+{
+ struct litest_device *dev = litest_current_device();
+ struct libinput *li = dev->libinput;
+ unsigned int key;
+
+ if (!pad_has_keys(dev))
+ return;
+
+ litest_drain_events(li);
+
+ key = KEY_BUTTONCONFIG;
+ pad_key_down(dev, key);
+ libinput_dispatch(li);
+ litest_assert_pad_key_event(li, key, LIBINPUT_KEY_STATE_PRESSED);
+
+ pad_key_up(dev, key);
+ libinput_dispatch(li);
+ litest_assert_pad_key_event(li, key, LIBINPUT_KEY_STATE_RELEASED);
+
+ key = KEY_ONSCREEN_KEYBOARD;
+ pad_key_down(dev, key);
+ libinput_dispatch(li);
+ litest_assert_pad_key_event(li, key, LIBINPUT_KEY_STATE_PRESSED);
+
+ pad_key_up(dev, key);
+ libinput_dispatch(li);
+ litest_assert_pad_key_event(li, key, LIBINPUT_KEY_STATE_RELEASED);
+
+ key = KEY_CONTROLPANEL;
+ pad_key_down(dev, key);
+ libinput_dispatch(li);
+ litest_assert_pad_key_event(li, key, LIBINPUT_KEY_STATE_PRESSED);
+
+ pad_key_up(dev, key);
+ libinput_dispatch(li);
+ litest_assert_pad_key_event(li, key, LIBINPUT_KEY_STATE_RELEASED);
+}
+END_TEST
+
TEST_COLLECTION(tablet_pad)
{
litest_add("pad:cap", pad_cap, LITEST_TABLET_PAD, LITEST_ANY);
@@ -950,4 +1016,6 @@ TEST_COLLECTION(tablet_pad)
litest_add("pad:modes", pad_mode_group_has, LITEST_TABLET_PAD, LITEST_ANY);
litest_add("pad:modes", pad_mode_group_has_invalid, LITEST_TABLET_PAD, LITEST_ANY);
litest_add("pad:modes", pad_mode_group_has_no_toggle, LITEST_TABLET_PAD, LITEST_ANY);
+
+ litest_add("pad:keys", pad_keys, LITEST_TABLET_PAD, LITEST_ANY);
}