| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417 |
- /*
- * Copyright © 2017 James Ye <jye836@gmail.com>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
- #include <config.h>
- #include <fcntl.h>
- #include <libevdev/libevdev.h>
- #include <libinput.h>
- #include "libinput-util.h"
- #include "litest.h"
- static inline bool
- switch_has_lid(struct litest_device *dev)
- {
- return libinput_device_switch_has_switch(dev->libinput_device,
- LIBINPUT_SWITCH_LID) > 0;
- }
- static inline bool
- switch_has_tablet_mode(struct litest_device *dev)
- {
- return libinput_device_switch_has_switch(dev->libinput_device,
- LIBINPUT_SWITCH_TABLET_MODE) > 0;
- }
- START_TEST(switch_has_cap)
- {
- struct litest_device *dev = litest_current_device();
- /* Need to check for this specific device here because the
- * unreliable tablet mode switch removes the capability too */
- if (dev->which == LITEST_TABLET_MODE_UNRELIABLE) {
- litest_assert(
- !libinput_device_has_capability(dev->libinput_device,
- LIBINPUT_DEVICE_CAP_SWITCH));
- return LITEST_NOT_APPLICABLE;
- }
- litest_assert(libinput_device_has_capability(dev->libinput_device,
- LIBINPUT_DEVICE_CAP_SWITCH));
- }
- END_TEST
- START_TEST(switch_has_lid_switch)
- {
- struct litest_device *dev = litest_current_device();
- if (!libevdev_has_event_code(dev->evdev, EV_SW, SW_LID))
- return LITEST_NOT_APPLICABLE;
- litest_assert_int_eq(libinput_device_switch_has_switch(dev->libinput_device,
- LIBINPUT_SWITCH_LID),
- 1);
- }
- END_TEST
- static bool
- tablet_mode_switch_is_reliable(struct litest_device *dev)
- {
- bool is_unreliable = false;
- quirks_get_bool(dev->quirks,
- QUIRK_MODEL_TABLET_MODE_SWITCH_UNRELIABLE,
- &is_unreliable);
- return !is_unreliable;
- }
- START_TEST(switch_has_tablet_mode_switch)
- {
- struct litest_device *dev = litest_current_device();
- int has_switch;
- if (!libevdev_has_event_code(dev->evdev, EV_SW, SW_TABLET_MODE))
- return LITEST_NOT_APPLICABLE;
- has_switch = libinput_device_switch_has_switch(dev->libinput_device,
- LIBINPUT_SWITCH_TABLET_MODE);
- if (!tablet_mode_switch_is_reliable(dev))
- litest_assert_int_ne(has_switch, 1);
- else
- litest_assert_int_eq(has_switch, 1);
- }
- END_TEST
- START_TEST(switch_has_keypad_slide_switch)
- {
- struct litest_device *dev = litest_current_device();
- if (!libevdev_has_event_code(dev->evdev, EV_SW, SW_KEYPAD_SLIDE))
- return LITEST_NOT_APPLICABLE;
- litest_assert_int_eq(
- libinput_device_switch_has_switch(dev->libinput_device,
- LIBINPUT_SWITCH_KEYPAD_SLIDE),
- 1);
- }
- END_TEST
- START_TEST(switch_toggle)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput *li = dev->libinput;
- struct libinput_event *event;
- enum libinput_switch sw = litest_test_param_get_i32(test_env->params, "switch");
- litest_drain_events(li);
- litest_grab_device(dev);
- litest_switch_action(dev, sw, LIBINPUT_SWITCH_STATE_ON);
- litest_dispatch(li);
- if (libinput_device_switch_has_switch(dev->libinput_device, sw) > 0) {
- event = libinput_get_event(li);
- litest_is_switch_event(event, sw, LIBINPUT_SWITCH_STATE_ON);
- libinput_event_destroy(event);
- } else {
- litest_assert_empty_queue(li);
- }
- litest_switch_action(dev, sw, LIBINPUT_SWITCH_STATE_OFF);
- litest_dispatch(li);
- if (libinput_device_switch_has_switch(dev->libinput_device, sw) > 0) {
- event = libinput_get_event(li);
- litest_is_switch_event(event, sw, LIBINPUT_SWITCH_STATE_OFF);
- libinput_event_destroy(event);
- }
- litest_assert_empty_queue(li);
- litest_ungrab_device(dev);
- }
- END_TEST
- START_TEST(switch_toggle_double)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput *li = dev->libinput;
- struct libinput_event *event;
- enum libinput_switch sw = litest_test_param_get_i32(test_env->params, "switch");
- if (libinput_device_switch_has_switch(dev->libinput_device, sw) <= 0)
- return LITEST_NOT_APPLICABLE;
- litest_drain_events(li);
- litest_grab_device(dev);
- litest_switch_action(dev, sw, LIBINPUT_SWITCH_STATE_ON);
- litest_dispatch(li);
- event = libinput_get_event(li);
- litest_is_switch_event(event, sw, LIBINPUT_SWITCH_STATE_ON);
- libinput_event_destroy(event);
- /* This will be filtered by the kernel, so this test is a bit
- * useless */
- litest_switch_action(dev, sw, LIBINPUT_SWITCH_STATE_ON);
- litest_dispatch(li);
- litest_assert_empty_queue(li);
- litest_ungrab_device(dev);
- }
- END_TEST
- static bool
- lid_switch_is_reliable(struct litest_device *dev)
- {
- char *prop;
- bool is_reliable = false;
- if (quirks_get_string(dev->quirks, QUIRK_ATTR_LID_SWITCH_RELIABILITY, &prop)) {
- is_reliable = streq(prop, "reliable");
- }
- return is_reliable;
- }
- START_TEST(switch_down_on_init)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput_event *event;
- enum libinput_switch sw = litest_test_param_get_i32(test_env->params, "switch");
- if (libinput_device_switch_has_switch(dev->libinput_device, sw) <= 0)
- return LITEST_NOT_APPLICABLE;
- if (sw == LIBINPUT_SWITCH_LID && !lid_switch_is_reliable(dev))
- return LITEST_NOT_APPLICABLE;
- litest_grab_device(dev);
- litest_switch_action(dev, sw, LIBINPUT_SWITCH_STATE_ON);
- litest_ungrab_device(dev);
- /* need separate context to test */
- _litest_context_destroy_ struct libinput *li = litest_create_context();
- libinput_path_add_device(li, libevdev_uinput_get_devnode(dev->uinput));
- litest_dispatch(li);
- litest_wait_for_event_of_type(li, LIBINPUT_EVENT_SWITCH_TOGGLE);
- event = libinput_get_event(li);
- litest_is_switch_event(event, sw, LIBINPUT_SWITCH_STATE_ON);
- libinput_event_destroy(event);
- while ((event = libinput_get_event(li))) {
- litest_assert_enum_ne(libinput_event_get_type(event),
- LIBINPUT_EVENT_SWITCH_TOGGLE);
- libinput_event_destroy(event);
- }
- litest_switch_action(dev, sw, LIBINPUT_SWITCH_STATE_OFF);
- litest_dispatch(li);
- event = libinput_get_event(li);
- litest_is_switch_event(event, sw, LIBINPUT_SWITCH_STATE_OFF);
- libinput_event_destroy(event);
- litest_assert_empty_queue(li);
- }
- END_TEST
- START_TEST(switch_not_down_on_init)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput_event *event;
- enum libinput_switch sw = LIBINPUT_SWITCH_LID;
- if (libinput_device_switch_has_switch(dev->libinput_device, sw) <= 0)
- return LITEST_NOT_APPLICABLE;
- if (sw == LIBINPUT_SWITCH_LID && lid_switch_is_reliable(dev))
- return LITEST_NOT_APPLICABLE;
- litest_grab_device(dev);
- litest_switch_action(dev, sw, LIBINPUT_SWITCH_STATE_ON);
- litest_ungrab_device(dev);
- /* need separate context to test */
- _litest_context_destroy_ struct libinput *li = litest_create_context();
- libinput_path_add_device(li, libevdev_uinput_get_devnode(dev->uinput));
- litest_dispatch(li);
- while ((event = libinput_get_event(li)) != NULL) {
- litest_assert_enum_ne(libinput_event_get_type(event),
- LIBINPUT_EVENT_SWITCH_TOGGLE);
- libinput_event_destroy(event);
- }
- litest_switch_action(dev, sw, LIBINPUT_SWITCH_STATE_OFF);
- litest_assert_empty_queue(li);
- }
- END_TEST
- static inline struct litest_device *
- switch_init_paired_touchpad(struct libinput *li)
- {
- enum litest_device_type which = LITEST_SYNAPTICS_I2C;
- return litest_add_device(li, which);
- }
- START_TEST(switch_disable_touchpad)
- {
- struct litest_device *sw = litest_current_device();
- struct litest_device *touchpad;
- struct libinput *li = sw->libinput;
- enum libinput_switch which =
- litest_test_param_get_i32(test_env->params, "switch");
- if (libinput_device_switch_has_switch(sw->libinput_device, which) <= 0)
- return LITEST_NOT_APPLICABLE;
- touchpad = switch_init_paired_touchpad(li);
- litest_disable_tap(touchpad->libinput_device);
- litest_disable_hold_gestures(touchpad->libinput_device);
- litest_drain_events(li);
- litest_grab_device(sw);
- /* switch is on - no events */
- litest_switch_action(sw, which, LIBINPUT_SWITCH_STATE_ON);
- litest_assert_only_typed_events(li, LIBINPUT_EVENT_SWITCH_TOGGLE);
- litest_touch_down(touchpad, 0, 50, 50);
- litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10);
- litest_touch_up(touchpad, 0);
- litest_assert_empty_queue(li);
- /* switch is off - motion events */
- litest_switch_action(sw, which, LIBINPUT_SWITCH_STATE_OFF);
- litest_assert_only_typed_events(li, LIBINPUT_EVENT_SWITCH_TOGGLE);
- litest_touch_down(touchpad, 0, 50, 50);
- litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10);
- litest_touch_up(touchpad, 0);
- litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
- litest_device_destroy(touchpad);
- litest_ungrab_device(sw);
- }
- END_TEST
- START_TEST(switch_disable_touchpad_during_touch)
- {
- struct litest_device *sw = litest_current_device();
- struct litest_device *touchpad;
- struct libinput *li = sw->libinput;
- enum libinput_switch which =
- litest_test_param_get_i32(test_env->params, "switch");
- if (libinput_device_switch_has_switch(sw->libinput_device, which) <= 0)
- return LITEST_NOT_APPLICABLE;
- touchpad = switch_init_paired_touchpad(li);
- litest_disable_tap(touchpad->libinput_device);
- litest_disable_hold_gestures(touchpad->libinput_device);
- litest_drain_events(li);
- litest_touch_down(touchpad, 0, 50, 50);
- litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 5);
- litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
- litest_grab_device(sw);
- litest_switch_action(sw, which, LIBINPUT_SWITCH_STATE_ON);
- litest_assert_only_typed_events(li, LIBINPUT_EVENT_SWITCH_TOGGLE);
- litest_ungrab_device(sw);
- litest_touch_move_to(touchpad, 0, 70, 50, 50, 50, 5);
- litest_touch_up(touchpad, 0);
- litest_assert_empty_queue(li);
- litest_device_destroy(touchpad);
- }
- END_TEST
- START_TEST(switch_disable_touchpad_edge_scroll)
- {
- struct litest_device *sw = litest_current_device();
- struct litest_device *touchpad;
- struct libinput *li = sw->libinput;
- enum libinput_switch which =
- litest_test_param_get_i32(test_env->params, "switch");
- if (libinput_device_switch_has_switch(sw->libinput_device, which) <= 0)
- return LITEST_NOT_APPLICABLE;
- touchpad = switch_init_paired_touchpad(li);
- litest_enable_edge_scroll(touchpad);
- litest_drain_events(li);
- litest_grab_device(sw);
- litest_switch_action(sw, which, LIBINPUT_SWITCH_STATE_ON);
- litest_assert_only_typed_events(li, LIBINPUT_EVENT_SWITCH_TOGGLE);
- litest_ungrab_device(sw);
- litest_touch_down(touchpad, 0, 99, 20);
- litest_dispatch(li);
- litest_timeout_edgescroll(li);
- litest_dispatch(li);
- litest_assert_empty_queue(li);
- litest_touch_move_to(touchpad, 0, 99, 20, 99, 80, 60);
- litest_dispatch(li);
- litest_assert_empty_queue(li);
- litest_touch_move_to(touchpad, 0, 99, 80, 99, 20, 60);
- litest_touch_up(touchpad, 0);
- litest_dispatch(li);
- litest_assert_empty_queue(li);
- litest_device_destroy(touchpad);
- }
- END_TEST
- START_TEST(switch_disable_touchpad_edge_scroll_interrupt)
- {
- struct litest_device *sw = litest_current_device();
- struct litest_device *touchpad;
- struct libinput *li = sw->libinput;
- struct libinput_event *event;
- enum libinput_switch which =
- litest_test_param_get_i32(test_env->params, "switch");
- if (libinput_device_switch_has_switch(sw->libinput_device, which) <= 0)
- return LITEST_NOT_APPLICABLE;
- touchpad = switch_init_paired_touchpad(li);
- litest_enable_edge_scroll(touchpad);
- litest_drain_events(li);
- litest_touch_down(touchpad, 0, 99, 20);
- litest_dispatch(li);
- litest_timeout_edgescroll(li);
- litest_touch_move_to(touchpad, 0, 99, 20, 99, 30, 10);
- litest_dispatch(li);
- litest_assert_only_axis_events(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER);
- litest_grab_device(sw);
- litest_switch_action(sw, which, LIBINPUT_SWITCH_STATE_ON);
- litest_ungrab_device(sw);
- litest_dispatch(li);
- litest_assert_axis_end_sequence(li,
- LIBINPUT_EVENT_POINTER_SCROLL_FINGER,
- LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL,
- LIBINPUT_POINTER_AXIS_SOURCE_FINGER);
- event = libinput_get_event(li);
- litest_is_switch_event(event, which, LIBINPUT_SWITCH_STATE_ON);
- libinput_event_destroy(event);
- litest_device_destroy(touchpad);
- }
- END_TEST
- START_TEST(switch_disable_touchpad_already_open)
- {
- struct litest_device *sw = litest_current_device();
- struct litest_device *touchpad;
- struct libinput *li = sw->libinput;
- enum libinput_switch which =
- litest_test_param_get_i32(test_env->params, "switch");
- if (libinput_device_switch_has_switch(sw->libinput_device, which) <= 0)
- return LITEST_NOT_APPLICABLE;
- touchpad = switch_init_paired_touchpad(li);
- litest_disable_tap(touchpad->libinput_device);
- litest_disable_hold_gestures(touchpad->libinput_device);
- litest_drain_events(li);
- /* default: switch is off - motion events */
- litest_touch_down(touchpad, 0, 50, 50);
- litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10);
- litest_touch_up(touchpad, 0);
- litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
- /* disable switch - motion events */
- litest_switch_action(sw, which, LIBINPUT_SWITCH_STATE_OFF);
- litest_assert_empty_queue(li);
- litest_touch_down(touchpad, 0, 50, 50);
- litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10);
- litest_touch_up(touchpad, 0);
- litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
- litest_device_destroy(touchpad);
- }
- END_TEST
- START_TEST(switch_dont_resume_disabled_touchpad)
- {
- struct litest_device *sw = litest_current_device();
- struct litest_device *touchpad;
- struct libinput *li = sw->libinput;
- enum libinput_switch which =
- litest_test_param_get_i32(test_env->params, "switch");
- if (libinput_device_switch_has_switch(sw->libinput_device, which) <= 0)
- return LITEST_NOT_APPLICABLE;
- touchpad = switch_init_paired_touchpad(li);
- litest_disable_tap(touchpad->libinput_device);
- litest_disable_hold_gestures(touchpad->libinput_device);
- libinput_device_config_send_events_set_mode(
- touchpad->libinput_device,
- LIBINPUT_CONFIG_SEND_EVENTS_DISABLED);
- litest_drain_events(li);
- /* switch is on - no events */
- litest_grab_device(sw);
- litest_switch_action(sw, which, LIBINPUT_SWITCH_STATE_ON);
- litest_ungrab_device(sw);
- litest_assert_only_typed_events(li, LIBINPUT_EVENT_SWITCH_TOGGLE);
- litest_touch_down(touchpad, 0, 50, 50);
- litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10);
- litest_touch_up(touchpad, 0);
- litest_assert_empty_queue(li);
- /* switch is off but but tp is still disabled */
- litest_switch_action(sw, which, LIBINPUT_SWITCH_STATE_OFF);
- litest_assert_only_typed_events(li, LIBINPUT_EVENT_SWITCH_TOGGLE);
- litest_touch_down(touchpad, 0, 50, 50);
- litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10);
- litest_touch_up(touchpad, 0);
- litest_assert_empty_queue(li);
- litest_device_destroy(touchpad);
- }
- END_TEST
- START_TEST(switch_dont_resume_disabled_touchpad_external_mouse)
- {
- struct litest_device *sw = litest_current_device();
- struct litest_device *touchpad, *mouse;
- struct libinput *li = sw->libinput;
- enum libinput_switch which =
- litest_test_param_get_i32(test_env->params, "switch");
- if (libinput_device_switch_has_switch(sw->libinput_device, which) <= 0)
- return LITEST_NOT_APPLICABLE;
- touchpad = switch_init_paired_touchpad(li);
- mouse = litest_add_device(li, LITEST_MOUSE);
- litest_disable_tap(touchpad->libinput_device);
- litest_disable_hold_gestures(touchpad->libinput_device);
- libinput_device_config_send_events_set_mode(
- touchpad->libinput_device,
- LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE);
- litest_drain_events(li);
- litest_touch_down(touchpad, 0, 50, 50);
- litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10);
- litest_touch_up(touchpad, 0);
- litest_assert_empty_queue(li);
- /* switch is on - no events */
- litest_grab_device(sw);
- litest_switch_action(sw, which, LIBINPUT_SWITCH_STATE_ON);
- litest_ungrab_device(sw);
- litest_assert_only_typed_events(li, LIBINPUT_EVENT_SWITCH_TOGGLE);
- litest_touch_down(touchpad, 0, 50, 50);
- litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10);
- litest_touch_up(touchpad, 0);
- litest_assert_empty_queue(li);
- /* switch is off but but tp is still disabled */
- litest_switch_action(sw, which, LIBINPUT_SWITCH_STATE_OFF);
- litest_assert_only_typed_events(li, LIBINPUT_EVENT_SWITCH_TOGGLE);
- litest_touch_down(touchpad, 0, 50, 50);
- litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10);
- litest_touch_up(touchpad, 0);
- litest_assert_empty_queue(li);
- litest_device_destroy(touchpad);
- litest_device_destroy(mouse);
- }
- END_TEST
- START_TEST(lid_open_on_key)
- {
- struct litest_device *sw = litest_current_device();
- struct litest_device *keyboard;
- struct libinput *li = sw->libinput;
- struct libinput_event *event;
- if (!switch_has_lid(sw))
- return LITEST_NOT_APPLICABLE;
- keyboard = litest_add_device(li, LITEST_KEYBOARD);
- litest_grab_device(sw);
- for (int i = 0; i < 3; i++) {
- litest_switch_action(sw, LIBINPUT_SWITCH_LID, LIBINPUT_SWITCH_STATE_ON);
- litest_drain_events(li);
- litest_event(keyboard, EV_KEY, KEY_A, 1);
- litest_event(keyboard, EV_SYN, SYN_REPORT, 0);
- litest_event(keyboard, EV_KEY, KEY_A, 0);
- litest_event(keyboard, EV_SYN, SYN_REPORT, 0);
- litest_dispatch(li);
- event = libinput_get_event(li);
- litest_is_switch_event(event,
- LIBINPUT_SWITCH_LID,
- LIBINPUT_SWITCH_STATE_OFF);
- libinput_event_destroy(event);
- litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY);
- litest_switch_action(sw,
- LIBINPUT_SWITCH_LID,
- LIBINPUT_SWITCH_STATE_OFF);
- litest_assert_empty_queue(li);
- }
- litest_ungrab_device(sw);
- litest_device_destroy(keyboard);
- }
- END_TEST
- START_TEST(lid_open_on_key_touchpad_enabled)
- {
- struct litest_device *sw = litest_current_device();
- struct litest_device *keyboard, *touchpad;
- struct libinput *li = sw->libinput;
- if (!switch_has_lid(sw))
- return LITEST_NOT_APPLICABLE;
- keyboard = litest_add_device(li, LITEST_KEYBOARD);
- touchpad = litest_add_device(li, LITEST_SYNAPTICS_I2C);
- litest_disable_hold_gestures(touchpad->libinput_device);
- litest_grab_device(sw);
- litest_switch_action(sw, LIBINPUT_SWITCH_LID, LIBINPUT_SWITCH_STATE_ON);
- litest_ungrab_device(sw);
- litest_drain_events(li);
- litest_event(keyboard, EV_KEY, KEY_A, 1);
- litest_event(keyboard, EV_SYN, SYN_REPORT, 0);
- litest_event(keyboard, EV_KEY, KEY_A, 0);
- litest_event(keyboard, EV_SYN, SYN_REPORT, 0);
- litest_drain_events(li);
- litest_timeout_dwt_long(li);
- litest_touch_down(touchpad, 0, 50, 50);
- litest_touch_move_to(touchpad, 0, 50, 50, 70, 70, 10);
- litest_touch_up(touchpad, 0);
- litest_dispatch(li);
- litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
- litest_device_destroy(keyboard);
- litest_device_destroy(touchpad);
- }
- END_TEST
- START_TEST(switch_suspend_with_keyboard)
- {
- struct litest_device *keyboard;
- struct litest_device *sw;
- enum libinput_switch which =
- litest_test_param_get_i32(test_env->params, "switch");
- _litest_context_destroy_ struct libinput *li = litest_create_context();
- switch (which) {
- case LIBINPUT_SWITCH_LID:
- sw = litest_add_device(li, LITEST_LID_SWITCH);
- break;
- case LIBINPUT_SWITCH_TABLET_MODE:
- sw = litest_add_device(li, LITEST_THINKPAD_EXTRABUTTONS);
- break;
- case LIBINPUT_SWITCH_KEYPAD_SLIDE:
- sw = litest_add_device(li, LITEST_KEYPAD_SLIDE_SWITCH);
- break;
- default:
- abort();
- }
- litest_dispatch(li);
- keyboard = litest_add_device(li, LITEST_KEYBOARD);
- litest_dispatch(li);
- litest_grab_device(sw);
- litest_switch_action(sw, which, LIBINPUT_SWITCH_STATE_ON);
- litest_drain_events(li);
- litest_switch_action(sw, which, LIBINPUT_SWITCH_STATE_OFF);
- litest_drain_events(li);
- litest_ungrab_device(sw);
- litest_device_destroy(keyboard);
- litest_drain_events(li);
- litest_device_destroy(sw);
- litest_dispatch(li);
- }
- END_TEST
- START_TEST(switch_suspend_with_touchpad)
- {
- struct litest_device *touchpad, *sw;
- enum libinput_switch which =
- litest_test_param_get_i32(test_env->params, "switch");
- _litest_context_destroy_ struct libinput *li = litest_create_context();
- switch (which) {
- case LIBINPUT_SWITCH_LID:
- sw = litest_add_device(li, LITEST_LID_SWITCH);
- break;
- case LIBINPUT_SWITCH_TABLET_MODE:
- sw = litest_add_device(li, LITEST_THINKPAD_EXTRABUTTONS);
- break;
- default:
- abort();
- }
- litest_drain_events(li);
- touchpad = litest_add_device(li, LITEST_SYNAPTICS_I2C);
- litest_drain_events(li);
- litest_grab_device(sw);
- litest_switch_action(sw, which, LIBINPUT_SWITCH_STATE_ON);
- litest_drain_events(li);
- litest_switch_action(sw, which, LIBINPUT_SWITCH_STATE_OFF);
- litest_drain_events(li);
- litest_ungrab_device(sw);
- litest_device_destroy(sw);
- litest_drain_events(li);
- litest_device_destroy(touchpad);
- litest_drain_events(li);
- }
- END_TEST
- START_TEST(lid_update_hw_on_key)
- {
- struct litest_device *sw = litest_current_device();
- struct libinput *li = sw->libinput;
- struct litest_device *keyboard;
- _free_(libevdev) *evdev = NULL;
- struct input_event event;
- int rc;
- if (!switch_has_lid(sw))
- return LITEST_NOT_APPLICABLE;
- keyboard = litest_add_device(li, LITEST_KEYBOARD);
- litest_grab_device(sw);
- litest_switch_action(sw, LIBINPUT_SWITCH_LID, LIBINPUT_SWITCH_STATE_ON);
- litest_drain_events(li);
- litest_ungrab_device(sw);
- /* Separate direct libevdev context to check if the HW event goes
- * through */
- _autoclose_ int fd =
- open(libevdev_uinput_get_devnode(sw->uinput), O_RDONLY | O_NONBLOCK);
- litest_assert_int_ge(fd, 0);
- litest_assert_int_eq(libevdev_new_from_fd(fd, &evdev), 0);
- litest_assert_int_eq(libevdev_get_event_value(evdev, EV_SW, SW_LID), 1);
- /* Typing on the keyboard should trigger a lid open event */
- litest_event(keyboard, EV_KEY, KEY_A, 1);
- litest_event(keyboard, EV_SYN, SYN_REPORT, 0);
- litest_event(keyboard, EV_KEY, KEY_A, 0);
- litest_event(keyboard, EV_SYN, SYN_REPORT, 0);
- litest_drain_events(li);
- rc = libevdev_next_event(evdev, LIBEVDEV_READ_FLAG_NORMAL, &event);
- litest_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SUCCESS);
- litest_assert_int_eq(event.type, EV_SW);
- litest_assert_int_eq(event.code, SW_LID);
- litest_assert_int_eq(event.value, 0);
- rc = libevdev_next_event(evdev, LIBEVDEV_READ_FLAG_NORMAL, &event);
- litest_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SUCCESS);
- litest_assert_int_eq(event.type, EV_SYN);
- litest_assert_int_eq(event.code, SYN_REPORT);
- litest_assert_int_eq(event.value, 0);
- rc = libevdev_next_event(evdev, LIBEVDEV_READ_FLAG_NORMAL, &event);
- litest_assert_int_eq(rc, -EAGAIN);
- litest_device_destroy(keyboard);
- }
- END_TEST
- START_TEST(lid_update_hw_on_key_closed_on_init)
- {
- struct litest_device *sw = litest_current_device();
- struct litest_device *keyboard;
- _free_(libevdev) * evdev;
- struct input_event event;
- int rc;
- litest_grab_device(sw);
- litest_switch_action(sw, LIBINPUT_SWITCH_LID, LIBINPUT_SWITCH_STATE_ON);
- litest_ungrab_device(sw);
- /* Separate direct libevdev context to check if the HW event goes
- * through */
- _autoclose_ int fd =
- open(libevdev_uinput_get_devnode(sw->uinput), O_RDONLY | O_NONBLOCK);
- litest_assert_int_ge(fd, 0);
- litest_assert_int_eq(libevdev_new_from_fd(fd, &evdev), 0);
- litest_assert_int_eq(libevdev_get_event_value(evdev, EV_SW, SW_LID), 1);
- keyboard = litest_add_device(sw->libinput, LITEST_KEYBOARD);
- /* separate context for the right state on init */
- _litest_context_destroy_ struct libinput *li = litest_create_context();
- libinput_path_add_device(li, libevdev_uinput_get_devnode(sw->uinput));
- libinput_path_add_device(li, libevdev_uinput_get_devnode(keyboard->uinput));
- /* don't expect a switch waiting for us, this is run for an
- * unreliable device */
- while (libinput_next_event_type(li) != LIBINPUT_EVENT_NONE) {
- litest_assert_enum_ne(libinput_next_event_type(li),
- LIBINPUT_EVENT_SWITCH_TOGGLE);
- libinput_event_destroy(libinput_get_event(li));
- }
- litest_event(keyboard, EV_KEY, KEY_A, 1);
- litest_event(keyboard, EV_SYN, SYN_REPORT, 0);
- litest_event(keyboard, EV_KEY, KEY_A, 0);
- litest_event(keyboard, EV_SYN, SYN_REPORT, 0);
- /* No switch event, we're still in vanilla (open) state */
- litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY);
- /* Make sure kernel state has updated */
- rc = libevdev_next_event(evdev, LIBEVDEV_READ_FLAG_NORMAL, &event);
- litest_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SUCCESS);
- litest_assert_int_eq(event.type, EV_SW);
- litest_assert_int_eq(event.code, SW_LID);
- litest_assert_int_eq(event.value, 0);
- rc = libevdev_next_event(evdev, LIBEVDEV_READ_FLAG_NORMAL, &event);
- litest_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SUCCESS);
- litest_assert_int_eq(event.type, EV_SYN);
- litest_assert_int_eq(event.code, SYN_REPORT);
- litest_assert_int_eq(event.value, 0);
- rc = libevdev_next_event(evdev, LIBEVDEV_READ_FLAG_NORMAL, &event);
- litest_assert_int_eq(rc, -EAGAIN);
- litest_device_destroy(keyboard);
- }
- END_TEST
- START_TEST(lid_update_hw_on_key_multiple_keyboards)
- {
- struct litest_device *sw = litest_current_device();
- struct libinput *li = sw->libinput;
- struct litest_device *keyboard1, *keyboard2;
- _free_(libevdev) * evdev;
- struct input_event event;
- int rc;
- if (!switch_has_lid(sw))
- return LITEST_NOT_APPLICABLE;
- keyboard1 = litest_add_device(li, LITEST_KEYBOARD_BLADE_STEALTH_VIDEOSWITCH);
- litest_dispatch(li);
- keyboard2 = litest_add_device(li, LITEST_KEYBOARD_BLADE_STEALTH);
- litest_dispatch(li);
- litest_grab_device(sw);
- litest_switch_action(sw, LIBINPUT_SWITCH_LID, LIBINPUT_SWITCH_STATE_ON);
- litest_drain_events(li);
- litest_ungrab_device(sw);
- /* Separate direct libevdev context to check if the HW event goes
- * through */
- _autoclose_ int fd =
- open(libevdev_uinput_get_devnode(sw->uinput), O_RDONLY | O_NONBLOCK);
- litest_assert_int_ge(fd, 0);
- litest_assert_int_eq(libevdev_new_from_fd(fd, &evdev), 0);
- litest_assert_int_eq(libevdev_get_event_value(evdev, EV_SW, SW_LID), 1);
- /* Typing on the second keyboard should trigger a lid open event */
- litest_event(keyboard2, EV_KEY, KEY_A, 1);
- litest_event(keyboard2, EV_SYN, SYN_REPORT, 0);
- litest_event(keyboard2, EV_KEY, KEY_A, 0);
- litest_event(keyboard2, EV_SYN, SYN_REPORT, 0);
- litest_drain_events(li);
- rc = libevdev_next_event(evdev, LIBEVDEV_READ_FLAG_NORMAL, &event);
- litest_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SUCCESS);
- litest_assert_int_eq(event.type, EV_SW);
- litest_assert_int_eq(event.code, SW_LID);
- litest_assert_int_eq(event.value, 0);
- rc = libevdev_next_event(evdev, LIBEVDEV_READ_FLAG_NORMAL, &event);
- litest_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SUCCESS);
- litest_assert_int_eq(event.type, EV_SYN);
- litest_assert_int_eq(event.code, SYN_REPORT);
- litest_assert_int_eq(event.value, 0);
- rc = libevdev_next_event(evdev, LIBEVDEV_READ_FLAG_NORMAL, &event);
- litest_assert_int_eq(rc, -EAGAIN);
- litest_device_destroy(keyboard1);
- litest_device_destroy(keyboard2);
- }
- END_TEST
- START_TEST(lid_key_press)
- {
- struct litest_device *sw = litest_current_device();
- struct libinput *li = sw->libinput;
- litest_drain_events(li);
- litest_keyboard_key(sw, KEY_VOLUMEUP, true);
- litest_keyboard_key(sw, KEY_VOLUMEUP, false);
- litest_dispatch(li);
- /* Check that we're routing key events from a lid device too */
- litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY);
- }
- END_TEST
- START_TEST(tablet_mode_disable_touchpad_on_init)
- {
- struct litest_device *sw = litest_current_device();
- struct litest_device *touchpad;
- struct libinput *li = sw->libinput;
- if (!switch_has_tablet_mode(sw))
- return LITEST_NOT_APPLICABLE;
- litest_grab_device(sw);
- litest_switch_action(sw, LIBINPUT_SWITCH_TABLET_MODE, LIBINPUT_SWITCH_STATE_ON);
- litest_drain_events(li);
- /* touchpad comes with switch already on - no events */
- touchpad = switch_init_paired_touchpad(li);
- litest_disable_tap(touchpad->libinput_device);
- litest_disable_hold_gestures(touchpad->libinput_device);
- litest_drain_events(li);
- litest_touch_down(touchpad, 0, 50, 50);
- litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10);
- litest_touch_up(touchpad, 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_touch_down(touchpad, 0, 50, 50);
- litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10);
- litest_touch_up(touchpad, 0);
- litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
- litest_ungrab_device(sw);
- litest_device_destroy(touchpad);
- }
- END_TEST
- START_TEST(tablet_mode_disable_touchpad_on_resume)
- {
- struct litest_device *sw = litest_current_device();
- struct litest_device *touchpad;
- struct libinput *li = sw->libinput;
- struct libinput_event *event;
- bool have_switch_toggle = false;
- if (!switch_has_tablet_mode(sw))
- return LITEST_NOT_APPLICABLE;
- touchpad = switch_init_paired_touchpad(li);
- litest_disable_tap(touchpad->libinput_device);
- litest_disable_hold_gestures(touchpad->libinput_device);
- litest_drain_events(li);
- libinput_suspend(li);
- litest_switch_action(sw, LIBINPUT_SWITCH_TABLET_MODE, LIBINPUT_SWITCH_STATE_ON);
- litest_drain_events(li);
- libinput_resume(li);
- litest_dispatch(li);
- while ((event = libinput_get_event(li))) {
- enum libinput_event_type type;
- type = libinput_event_get_type(event);
- switch (type) {
- case LIBINPUT_EVENT_DEVICE_ADDED:
- break;
- case LIBINPUT_EVENT_SWITCH_TOGGLE:
- litest_is_switch_event(event,
- LIBINPUT_SWITCH_TABLET_MODE,
- LIBINPUT_SWITCH_STATE_ON);
- have_switch_toggle = true;
- break;
- default:
- litest_abort_msg("Unexpected event type");
- }
- libinput_event_destroy(event);
- }
- litest_assert(have_switch_toggle);
- litest_touch_down(touchpad, 0, 50, 50);
- litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10);
- litest_touch_up(touchpad, 0);
- litest_assert_empty_queue(li);
- litest_switch_action(sw,
- LIBINPUT_SWITCH_TABLET_MODE,
- LIBINPUT_SWITCH_STATE_OFF);
- litest_dispatch(li);
- event = libinput_get_event(li);
- litest_is_switch_event(event,
- LIBINPUT_SWITCH_TABLET_MODE,
- LIBINPUT_SWITCH_STATE_OFF);
- libinput_event_destroy(event);
- litest_touch_down(touchpad, 0, 50, 50);
- litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10);
- litest_touch_up(touchpad, 0);
- litest_dispatch(li);
- litest_drain_events_of_type(li,
- LIBINPUT_EVENT_GESTURE_HOLD_BEGIN,
- LIBINPUT_EVENT_GESTURE_HOLD_END);
- litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
- litest_device_destroy(touchpad);
- }
- END_TEST
- START_TEST(tablet_mode_enable_touchpad_on_resume)
- {
- struct litest_device *sw = litest_current_device();
- struct litest_device *touchpad;
- struct libinput *li = sw->libinput;
- struct libinput_event *event;
- if (!switch_has_tablet_mode(sw))
- return LITEST_NOT_APPLICABLE;
- touchpad = switch_init_paired_touchpad(li);
- litest_disable_tap(touchpad->libinput_device);
- litest_drain_events(li);
- litest_switch_action(sw, LIBINPUT_SWITCH_TABLET_MODE, LIBINPUT_SWITCH_STATE_ON);
- libinput_suspend(li);
- litest_drain_events(li);
- litest_switch_action(sw,
- LIBINPUT_SWITCH_TABLET_MODE,
- LIBINPUT_SWITCH_STATE_OFF);
- libinput_resume(li);
- litest_dispatch(li);
- litest_assert_only_typed_events(li, LIBINPUT_EVENT_DEVICE_ADDED);
- litest_touch_down(touchpad, 0, 50, 50);
- litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10);
- litest_touch_up(touchpad, 0);
- litest_drain_events_of_type(li,
- LIBINPUT_EVENT_GESTURE_HOLD_BEGIN,
- LIBINPUT_EVENT_GESTURE_HOLD_END);
- litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
- litest_switch_action(sw, LIBINPUT_SWITCH_TABLET_MODE, LIBINPUT_SWITCH_STATE_ON);
- litest_dispatch(li);
- event = libinput_get_event(li);
- litest_is_switch_event(event,
- LIBINPUT_SWITCH_TABLET_MODE,
- LIBINPUT_SWITCH_STATE_ON);
- libinput_event_destroy(event);
- litest_touch_down(touchpad, 0, 50, 50);
- litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10);
- litest_touch_up(touchpad, 0);
- litest_assert_empty_queue(li);
- litest_device_destroy(touchpad);
- }
- 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 LITEST_NOT_APPLICABLE;
- 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_keyboard_key(keyboard, KEY_B, true); /* KEY_B down but not up */
- litest_dispatch(li);
- litest_assert_key_event(li, KEY_A, LIBINPUT_KEY_STATE_PRESSED);
- litest_assert_key_event(li, KEY_A, LIBINPUT_KEY_STATE_RELEASED);
- litest_assert_key_event(li,
- KEY_B,
- LIBINPUT_KEY_STATE_PRESSED); /* KEY_B down but not up */
- litest_switch_action(sw, LIBINPUT_SWITCH_TABLET_MODE, LIBINPUT_SWITCH_STATE_ON);
- /* The key currently down must be released */
- litest_assert_key_event(li, KEY_B, LIBINPUT_KEY_STATE_RELEASED);
- litest_assert_switch_event(li,
- LIBINPUT_SWITCH_TABLET_MODE,
- LIBINPUT_SWITCH_STATE_ON);
- litest_assert_empty_queue(li);
- litest_keyboard_key(keyboard, KEY_B, false); /* release the kernel device */
- 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_switch_event(li,
- LIBINPUT_SWITCH_TABLET_MODE,
- LIBINPUT_SWITCH_STATE_OFF);
- litest_keyboard_key(keyboard, KEY_A, true);
- litest_keyboard_key(keyboard, KEY_A, false);
- litest_keyboard_key(keyboard, KEY_B, true);
- litest_keyboard_key(keyboard, KEY_B, false);
- litest_assert_key_event(li, KEY_A, LIBINPUT_KEY_STATE_PRESSED);
- litest_assert_key_event(li, KEY_A, LIBINPUT_KEY_STATE_RELEASED);
- litest_assert_key_event(li, KEY_B, LIBINPUT_KEY_STATE_PRESSED);
- litest_assert_key_event(li, KEY_B, LIBINPUT_KEY_STATE_RELEASED);
- litest_device_destroy(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_NOT_APPLICABLE;
- 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_device_destroy(keyboard);
- }
- END_TEST
- START_TEST(tablet_mode_disable_keyboard_on_resume)
- {
- struct litest_device *sw = litest_current_device();
- struct litest_device *keyboard;
- struct libinput *li = sw->libinput;
- struct libinput_event *event;
- bool have_switch_toggle = false;
- if (!switch_has_tablet_mode(sw))
- return LITEST_NOT_APPLICABLE;
- keyboard = litest_add_device(li, LITEST_KEYBOARD);
- litest_drain_events(li);
- libinput_suspend(li);
- /* We cannot grab this device because libinput doesn't have an open
- * fd to this device, we need an independent grab.
- */
- libevdev_grab(sw->evdev, LIBEVDEV_GRAB);
- litest_switch_action(sw, LIBINPUT_SWITCH_TABLET_MODE, LIBINPUT_SWITCH_STATE_ON);
- libevdev_grab(sw->evdev, LIBEVDEV_UNGRAB);
- litest_drain_events(li);
- libinput_resume(li);
- litest_dispatch(li);
- while ((event = libinput_get_event(li))) {
- enum libinput_event_type type;
- type = libinput_event_get_type(event);
- switch (type) {
- case LIBINPUT_EVENT_DEVICE_ADDED:
- break;
- case LIBINPUT_EVENT_SWITCH_TOGGLE:
- litest_is_switch_event(event,
- LIBINPUT_SWITCH_TABLET_MODE,
- LIBINPUT_SWITCH_STATE_ON);
- have_switch_toggle = true;
- break;
- default:
- litest_abort_msg("Unexpected event type");
- }
- libinput_event_destroy(event);
- }
- litest_assert(have_switch_toggle);
- litest_keyboard_key(keyboard, KEY_A, true);
- litest_keyboard_key(keyboard, KEY_A, false);
- litest_assert_empty_queue(li);
- litest_grab_device(sw);
- litest_switch_action(sw,
- LIBINPUT_SWITCH_TABLET_MODE,
- LIBINPUT_SWITCH_STATE_OFF);
- litest_ungrab_device(sw);
- 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_device_destroy(keyboard);
- }
- END_TEST
- START_TEST(tablet_mode_enable_keyboard_on_resume)
- {
- struct litest_device *sw = litest_current_device();
- struct litest_device *keyboard;
- struct libinput *li = sw->libinput;
- if (!switch_has_tablet_mode(sw))
- return LITEST_NOT_APPLICABLE;
- keyboard = litest_add_device(li, LITEST_KEYBOARD);
- litest_grab_device(sw);
- litest_switch_action(sw, LIBINPUT_SWITCH_TABLET_MODE, LIBINPUT_SWITCH_STATE_ON);
- litest_drain_events(li);
- litest_ungrab_device(sw);
- libinput_suspend(li);
- litest_drain_events(li);
- litest_switch_action(sw,
- LIBINPUT_SWITCH_TABLET_MODE,
- LIBINPUT_SWITCH_STATE_OFF);
- libinput_resume(li);
- litest_dispatch(li);
- litest_assert_only_typed_events(li, LIBINPUT_EVENT_DEVICE_ADDED);
- 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_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_empty_queue(li);
- litest_device_destroy(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 LITEST_NOT_APPLICABLE;
- 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_grab_device(sw);
- 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_ungrab_device(sw);
- litest_device_destroy(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_NOT_APPLICABLE;
- litest_grab_device(sw);
- 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_ungrab_device(sw);
- litest_device_destroy(trackpoint);
- }
- END_TEST
- START_TEST(dock_toggle)
- {
- struct litest_device *sw = litest_current_device();
- struct libinput *li = sw->libinput;
- if (!libevdev_has_event_code(sw->evdev, EV_SW, SW_DOCK))
- return LITEST_NOT_APPLICABLE;
- litest_drain_events(li);
- litest_grab_device(sw);
- litest_event(sw, EV_SW, SW_DOCK, 1);
- litest_dispatch(li);
- litest_event(sw, EV_SW, SW_DOCK, 0);
- litest_dispatch(li);
- litest_ungrab_device(sw);
- litest_assert_empty_queue(li);
- }
- END_TEST
- TEST_COLLECTION(switch)
- {
- /* clang-format off */
- litest_add(switch_has_cap, LITEST_SWITCH, LITEST_ANY);
- litest_add(switch_has_lid_switch, LITEST_SWITCH, LITEST_ANY);
- litest_add(switch_has_tablet_mode_switch, LITEST_SWITCH, LITEST_ANY);
- litest_add(switch_has_keypad_slide_switch, LITEST_SWITCH, LITEST_ANY);
- litest_add(switch_not_down_on_init, LITEST_SWITCH, LITEST_ANY);
- litest_with_parameters(params, "switch", 'I', 3, litest_named_i32(LIBINPUT_SWITCH_LID, "lid"),
- litest_named_i32(LIBINPUT_SWITCH_TABLET_MODE, "tablet_mode"),
- litest_named_i32(LIBINPUT_SWITCH_KEYPAD_SLIDE, "keypad_slide")) {
- litest_add_parametrized(switch_toggle, LITEST_SWITCH, LITEST_ANY, params);
- litest_add_parametrized(switch_toggle_double, LITEST_SWITCH, LITEST_ANY, params);
- litest_add_parametrized(switch_down_on_init, LITEST_SWITCH, LITEST_ANY, params);
- litest_add_parametrized(switch_not_down_on_init, LITEST_SWITCH, LITEST_ANY, params);
- }
- litest_with_parameters(params, "switch", 'I', 2, litest_named_i32(LIBINPUT_SWITCH_LID, "lid"),
- litest_named_i32(LIBINPUT_SWITCH_TABLET_MODE, "tablet_mode")) {
- litest_add_parametrized(switch_disable_touchpad, LITEST_SWITCH, LITEST_ANY, params);
- litest_add_parametrized(switch_disable_touchpad_during_touch, LITEST_SWITCH, LITEST_ANY, params);
- litest_add_parametrized(switch_disable_touchpad_edge_scroll, LITEST_SWITCH, LITEST_ANY, params);
- litest_add_parametrized(switch_disable_touchpad_edge_scroll_interrupt, LITEST_SWITCH, LITEST_ANY, params);
- litest_add_parametrized(switch_disable_touchpad_already_open, LITEST_SWITCH, LITEST_ANY, params);
- litest_add_parametrized(switch_dont_resume_disabled_touchpad, LITEST_SWITCH, LITEST_ANY, params);
- litest_add_parametrized(switch_dont_resume_disabled_touchpad_external_mouse, LITEST_SWITCH, LITEST_ANY, params);
- litest_add_parametrized_no_device(switch_suspend_with_keyboard, params);
- litest_add_parametrized_no_device(switch_suspend_with_touchpad, params);
- }
- litest_add(lid_open_on_key, LITEST_SWITCH, LITEST_ANY);
- litest_add(lid_open_on_key_touchpad_enabled, LITEST_SWITCH, LITEST_ANY);
- litest_add_for_device(lid_update_hw_on_key, LITEST_LID_SWITCH_SURFACE3);
- litest_add_for_device(lid_update_hw_on_key_closed_on_init, LITEST_LID_SWITCH_SURFACE3);
- litest_add_for_device(lid_update_hw_on_key_multiple_keyboards, LITEST_LID_SWITCH_SURFACE3);
- litest_add_for_device(lid_key_press, LITEST_GPIO_KEYS);
- litest_add(tablet_mode_disable_touchpad_on_init, LITEST_SWITCH, LITEST_ANY);
- litest_add(tablet_mode_disable_touchpad_on_resume, LITEST_SWITCH, LITEST_ANY);
- litest_add(tablet_mode_enable_touchpad_on_resume, LITEST_SWITCH, LITEST_ANY);
- litest_add(tablet_mode_disable_keyboard, LITEST_SWITCH, LITEST_ANY);
- litest_add(tablet_mode_disable_keyboard_on_init, LITEST_SWITCH, LITEST_ANY);
- litest_add(tablet_mode_disable_keyboard_on_resume, LITEST_SWITCH, LITEST_ANY);
- litest_add(tablet_mode_enable_keyboard_on_resume, LITEST_SWITCH, LITEST_ANY);
- litest_add(tablet_mode_disable_trackpoint, LITEST_SWITCH, LITEST_ANY);
- litest_add(tablet_mode_disable_trackpoint_on_init, LITEST_SWITCH, LITEST_ANY);
- litest_add(dock_toggle, LITEST_SWITCH, LITEST_ANY);
- /* clang-format on */
- }
|