diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2017-09-20 14:40:59 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2017-09-25 15:34:45 +1000 |
commit | 84d49ee49cc30927debb4104af42a92738837ada (patch) | |
tree | da0c932a04a8a68b95adf82d097b5cd736ec3a06 /test/test-switch.c | |
parent | 350ce2b3f197aed662ad8671ef3a482a2ea15291 (diff) |
fallback: suspend internal keyboards and trackpoints on tablet-mode switch
Because on some devices the keyboard is where the fingers are holding the
device when in tablet mode.
https://bugs.freedesktop.org/show_bug.cgi?id=102729
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'test/test-switch.c')
-rw-r--r-- | test/test-switch.c | 159 |
1 files changed, 159 insertions, 0 deletions
diff --git a/test/test-switch.c b/test/test-switch.c index c306305b..3a499bf7 100644 --- a/test/test-switch.c +++ b/test/test-switch.c @@ -864,6 +864,161 @@ START_TEST(tablet_mode_disable_touchpad_on_init) } END_TEST +START_TEST(tablet_mode_disable_keyboard) +{ + struct litest_device *sw = litest_current_device(); + struct litest_device *keyboard; + struct libinput *li = sw->libinput; + + if (!switch_has_tablet_mode(sw)) + return; + + keyboard = litest_add_device(li, LITEST_KEYBOARD); + litest_drain_events(li); + + litest_keyboard_key(keyboard, KEY_A, true); + litest_keyboard_key(keyboard, KEY_A, false); + litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY); + + litest_switch_action(sw, + LIBINPUT_SWITCH_TABLET_MODE, + LIBINPUT_SWITCH_STATE_ON); + litest_drain_events(li); + + litest_keyboard_key(keyboard, KEY_A, true); + litest_keyboard_key(keyboard, KEY_A, false); + litest_assert_empty_queue(li); + + litest_switch_action(sw, + LIBINPUT_SWITCH_TABLET_MODE, + LIBINPUT_SWITCH_STATE_OFF); + litest_assert_only_typed_events(li, LIBINPUT_EVENT_SWITCH_TOGGLE); + + litest_keyboard_key(keyboard, KEY_A, true); + litest_keyboard_key(keyboard, KEY_A, false); + litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY); + + litest_delete_device(keyboard); +} +END_TEST + +START_TEST(tablet_mode_disable_keyboard_on_init) +{ + struct litest_device *sw = litest_current_device(); + struct litest_device *keyboard; + struct libinput *li = sw->libinput; + + if (!switch_has_tablet_mode(sw)) + return; + + litest_switch_action(sw, + LIBINPUT_SWITCH_TABLET_MODE, + LIBINPUT_SWITCH_STATE_ON); + litest_drain_events(li); + + /* keyboard comes with switch already on - no events */ + keyboard = litest_add_device(li, LITEST_KEYBOARD); + litest_drain_events(li); + + litest_keyboard_key(keyboard, KEY_A, true); + litest_keyboard_key(keyboard, KEY_A, false); + litest_assert_empty_queue(li); + + litest_switch_action(sw, + LIBINPUT_SWITCH_TABLET_MODE, + LIBINPUT_SWITCH_STATE_OFF); + litest_assert_only_typed_events(li, LIBINPUT_EVENT_SWITCH_TOGGLE); + + litest_keyboard_key(keyboard, KEY_A, true); + litest_keyboard_key(keyboard, KEY_A, false); + litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY); + + litest_delete_device(keyboard); +} +END_TEST + +START_TEST(tablet_mode_disable_trackpoint) +{ + struct litest_device *sw = litest_current_device(); + struct litest_device *trackpoint; + struct libinput *li = sw->libinput; + + if (!switch_has_tablet_mode(sw)) + return; + + trackpoint = litest_add_device(li, LITEST_TRACKPOINT); + litest_drain_events(li); + + litest_event(trackpoint, EV_REL, REL_Y, -1); + litest_event(trackpoint, EV_SYN, SYN_REPORT, 0); + litest_event(trackpoint, EV_REL, REL_Y, -1); + litest_event(trackpoint, EV_SYN, SYN_REPORT, 0); + litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); + + litest_switch_action(sw, + LIBINPUT_SWITCH_TABLET_MODE, + LIBINPUT_SWITCH_STATE_ON); + litest_drain_events(li); + + litest_event(trackpoint, EV_REL, REL_Y, -1); + litest_event(trackpoint, EV_SYN, SYN_REPORT, 0); + litest_event(trackpoint, EV_REL, REL_Y, -1); + litest_event(trackpoint, EV_SYN, SYN_REPORT, 0); + litest_assert_empty_queue(li); + + litest_switch_action(sw, + LIBINPUT_SWITCH_TABLET_MODE, + LIBINPUT_SWITCH_STATE_OFF); + litest_assert_only_typed_events(li, LIBINPUT_EVENT_SWITCH_TOGGLE); + + litest_event(trackpoint, EV_REL, REL_Y, -1); + litest_event(trackpoint, EV_SYN, SYN_REPORT, 0); + litest_event(trackpoint, EV_REL, REL_Y, -1); + litest_event(trackpoint, EV_SYN, SYN_REPORT, 0); + litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); + + litest_delete_device(trackpoint); +} +END_TEST +START_TEST(tablet_mode_disable_trackpoint_on_init) +{ + struct litest_device *sw = litest_current_device(); + struct litest_device *trackpoint; + struct libinput *li = sw->libinput; + + if (!switch_has_tablet_mode(sw)) + return; + + litest_switch_action(sw, + LIBINPUT_SWITCH_TABLET_MODE, + LIBINPUT_SWITCH_STATE_ON); + litest_drain_events(li); + + /* trackpoint comes with switch already on - no events */ + trackpoint = litest_add_device(li, LITEST_TRACKPOINT); + litest_drain_events(li); + + litest_event(trackpoint, EV_REL, REL_Y, -1); + litest_event(trackpoint, EV_SYN, SYN_REPORT, 0); + litest_event(trackpoint, EV_REL, REL_Y, -1); + litest_event(trackpoint, EV_SYN, SYN_REPORT, 0); + litest_assert_empty_queue(li); + + litest_switch_action(sw, + LIBINPUT_SWITCH_TABLET_MODE, + LIBINPUT_SWITCH_STATE_OFF); + litest_assert_only_typed_events(li, LIBINPUT_EVENT_SWITCH_TOGGLE); + + litest_event(trackpoint, EV_REL, REL_Y, -1); + litest_event(trackpoint, EV_SYN, SYN_REPORT, 0); + litest_event(trackpoint, EV_REL, REL_Y, -1); + litest_event(trackpoint, EV_SYN, SYN_REPORT, 0); + litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); + + litest_delete_device(trackpoint); +} +END_TEST + void litest_setup_tests_lid(void) { @@ -896,4 +1051,8 @@ litest_setup_tests_lid(void) litest_add_for_device("lid:keypress", lid_key_press, LITEST_GPIO_KEYS); litest_add("tablet-mode:touchpad", tablet_mode_disable_touchpad_on_init, LITEST_SWITCH, LITEST_ANY); + litest_add("tablet-mode:keyboard", tablet_mode_disable_keyboard, LITEST_SWITCH, LITEST_ANY); + litest_add("tablet-mode:keyboard", tablet_mode_disable_keyboard_on_init, LITEST_SWITCH, LITEST_ANY); + litest_add("tablet-mode:trackpoint", tablet_mode_disable_trackpoint, LITEST_SWITCH, LITEST_ANY); + litest_add("tablet-mode:trackpoint", tablet_mode_disable_trackpoint_on_init, LITEST_SWITCH, LITEST_ANY); } |