2014-04-01 22:24:10 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2014 Jonas Ådahl <jadahl@gmail.com>
|
|
|
|
|
*
|
2015-06-11 12:09:18 +10:00
|
|
|
* 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:
|
2014-04-01 22:24:10 +02:00
|
|
|
*
|
2015-06-11 12:09:18 +10:00
|
|
|
* 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.
|
2014-04-01 22:24:10 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
2014-07-27 16:02:46 +02:00
|
|
|
#include "libinput-util.h"
|
2014-04-01 22:24:10 +02:00
|
|
|
#include "litest.h"
|
|
|
|
|
|
|
|
|
|
START_TEST(keyboard_seat_key_count)
|
|
|
|
|
{
|
2019-06-15 13:50:33 -07:00
|
|
|
struct litest_device *devices[4];
|
|
|
|
|
const int num_devices = ARRAY_LENGTH(devices);
|
2014-04-01 22:24:10 +02:00
|
|
|
struct libinput_event *ev;
|
|
|
|
|
struct libinput_event_keyboard *kev;
|
|
|
|
|
int i;
|
2015-02-19 07:22:59 +10:00
|
|
|
int seat_key_count = 0;
|
2014-04-01 22:24:10 +02:00
|
|
|
int expected_key_button_count = 0;
|
|
|
|
|
char device_name[255];
|
|
|
|
|
|
2025-04-07 13:15:28 +10:00
|
|
|
_litest_context_destroy_ struct libinput *libinput = litest_create_context();
|
2014-04-01 22:24:10 +02:00
|
|
|
for (i = 0; i < num_devices; ++i) {
|
2014-07-04 07:55:51 +10:00
|
|
|
sprintf(device_name, "litest Generic keyboard (%d)", i);
|
2014-04-01 22:24:10 +02:00
|
|
|
devices[i] = litest_add_device_with_overrides(libinput,
|
|
|
|
|
LITEST_KEYBOARD,
|
|
|
|
|
device_name,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-05 20:11:26 +10:00
|
|
|
litest_drain_events(libinput);
|
|
|
|
|
|
2014-04-01 22:24:10 +02:00
|
|
|
for (i = 0; i < num_devices; ++i)
|
|
|
|
|
litest_keyboard_key(devices[i], KEY_A, true);
|
|
|
|
|
|
2024-09-13 15:13:38 +10:00
|
|
|
litest_dispatch(libinput);
|
2014-04-01 22:24:10 +02:00
|
|
|
while ((ev = libinput_get_event(libinput))) {
|
2015-05-05 15:43:08 +10:00
|
|
|
kev = litest_is_keyboard_event(ev, KEY_A, LIBINPUT_KEY_STATE_PRESSED);
|
2014-04-01 22:24:10 +02:00
|
|
|
|
|
|
|
|
++expected_key_button_count;
|
|
|
|
|
seat_key_count = libinput_event_keyboard_get_seat_key_count(kev);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_int_eq(expected_key_button_count, seat_key_count);
|
2014-04-01 22:24:10 +02:00
|
|
|
|
2014-04-23 11:04:48 +10:00
|
|
|
libinput_event_destroy(ev);
|
2024-09-13 15:13:38 +10:00
|
|
|
litest_dispatch(libinput);
|
2014-04-01 22:24:10 +02:00
|
|
|
}
|
|
|
|
|
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_int_eq(seat_key_count, num_devices);
|
2014-04-01 22:24:10 +02:00
|
|
|
|
|
|
|
|
for (i = 0; i < num_devices; ++i)
|
|
|
|
|
litest_keyboard_key(devices[i], KEY_A, false);
|
|
|
|
|
|
2024-09-13 15:13:38 +10:00
|
|
|
litest_dispatch(libinput);
|
2014-04-01 22:24:10 +02:00
|
|
|
while ((ev = libinput_get_event(libinput))) {
|
|
|
|
|
kev = libinput_event_get_keyboard_event(ev);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_notnull(kev);
|
2024-10-11 13:55:56 +10:00
|
|
|
litest_assert_int_eq(libinput_event_keyboard_get_key(kev),
|
|
|
|
|
(unsigned int)KEY_A);
|
2024-09-16 16:49:38 +10:00
|
|
|
litest_assert_enum_eq(libinput_event_keyboard_get_key_state(kev),
|
2014-06-17 07:55:35 +10:00
|
|
|
LIBINPUT_KEY_STATE_RELEASED);
|
2014-04-01 22:24:10 +02:00
|
|
|
|
|
|
|
|
--expected_key_button_count;
|
|
|
|
|
seat_key_count = libinput_event_keyboard_get_seat_key_count(kev);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_int_eq(expected_key_button_count, seat_key_count);
|
2014-04-01 22:24:10 +02:00
|
|
|
|
2014-04-23 11:04:48 +10:00
|
|
|
libinput_event_destroy(ev);
|
2024-09-13 15:13:38 +10:00
|
|
|
litest_dispatch(libinput);
|
2014-04-01 22:24:10 +02:00
|
|
|
}
|
|
|
|
|
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_int_eq(seat_key_count, 0);
|
2014-04-01 22:24:10 +02:00
|
|
|
|
|
|
|
|
for (i = 0; i < num_devices; ++i)
|
2025-04-07 15:12:51 +10:00
|
|
|
litest_device_destroy(devices[i]);
|
2014-04-01 22:24:10 +02:00
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2014-07-27 15:43:59 +02:00
|
|
|
START_TEST(keyboard_ignore_no_pressed_release)
|
|
|
|
|
{
|
|
|
|
|
struct litest_device *dev;
|
|
|
|
|
struct libinput_event *event;
|
|
|
|
|
struct libinput_event_keyboard *kevent;
|
|
|
|
|
int events[] = {
|
|
|
|
|
EV_KEY,
|
|
|
|
|
KEY_A,
|
|
|
|
|
-1,
|
|
|
|
|
-1,
|
|
|
|
|
};
|
|
|
|
|
enum libinput_key_state expected_states[] = {
|
|
|
|
|
LIBINPUT_KEY_STATE_PRESSED,
|
|
|
|
|
LIBINPUT_KEY_STATE_RELEASED,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* We can't send pressed -> released -> pressed events using uinput
|
|
|
|
|
* as such non-symmetric events are dropped. Work-around this by first
|
|
|
|
|
* adding the test device to the tested context after having sent an
|
|
|
|
|
* initial pressed event. */
|
2025-04-07 13:15:28 +10:00
|
|
|
_litest_context_destroy_ struct libinput *unused_libinput =
|
|
|
|
|
litest_create_context();
|
2014-07-27 15:43:59 +02:00
|
|
|
dev = litest_add_device_with_overrides(unused_libinput,
|
|
|
|
|
LITEST_KEYBOARD,
|
|
|
|
|
"Generic keyboard",
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
events);
|
|
|
|
|
|
|
|
|
|
litest_keyboard_key(dev, KEY_A, true);
|
|
|
|
|
litest_drain_events(unused_libinput);
|
|
|
|
|
|
2025-04-07 13:15:28 +10:00
|
|
|
_litest_context_destroy_ struct libinput *libinput = litest_create_context();
|
2014-07-27 15:43:59 +02:00
|
|
|
libinput_path_add_device(libinput, libevdev_uinput_get_devnode(dev->uinput));
|
|
|
|
|
litest_drain_events(libinput);
|
|
|
|
|
|
|
|
|
|
litest_keyboard_key(dev, KEY_A, false);
|
|
|
|
|
litest_keyboard_key(dev, KEY_A, true);
|
|
|
|
|
litest_keyboard_key(dev, KEY_A, false);
|
|
|
|
|
|
2024-09-13 15:13:38 +10:00
|
|
|
litest_dispatch(libinput);
|
2014-07-27 15:43:59 +02:00
|
|
|
|
|
|
|
|
ARRAY_FOR_EACH(expected_states, state) {
|
|
|
|
|
event = libinput_get_event(libinput);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_notnull(event);
|
2024-09-18 14:44:38 +10:00
|
|
|
litest_assert_event_type(event, LIBINPUT_EVENT_KEYBOARD_KEY);
|
2014-07-27 15:43:59 +02:00
|
|
|
kevent = libinput_event_get_keyboard_event(event);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_int_eq(libinput_event_keyboard_get_key(kevent),
|
2024-10-11 13:55:56 +10:00
|
|
|
(unsigned int)KEY_A);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_int_eq(libinput_event_keyboard_get_key_state(kevent),
|
2014-07-27 15:43:59 +02:00
|
|
|
*state);
|
|
|
|
|
libinput_event_destroy(event);
|
2024-09-13 15:13:38 +10:00
|
|
|
litest_dispatch(libinput);
|
2014-07-27 15:43:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
litest_assert_empty_queue(libinput);
|
2025-04-07 15:12:51 +10:00
|
|
|
litest_device_destroy(dev);
|
2014-07-27 15:43:59 +02:00
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2014-07-27 16:02:46 +02:00
|
|
|
START_TEST(keyboard_key_auto_release)
|
|
|
|
|
{
|
|
|
|
|
struct litest_device *dev;
|
|
|
|
|
struct libinput_event *event;
|
|
|
|
|
enum libinput_event_type type;
|
|
|
|
|
struct libinput_event_keyboard *kevent;
|
|
|
|
|
struct {
|
|
|
|
|
int code;
|
|
|
|
|
int released;
|
|
|
|
|
} keys[] = {
|
|
|
|
|
{
|
|
|
|
|
.code = KEY_A,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
.code = KEY_S,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
.code = KEY_D,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
.code = KEY_G,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
.code = KEY_Z,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
.code = KEY_DELETE,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
.code = KEY_F24,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
int events[2 * (ARRAY_LENGTH(keys) + 1)];
|
|
|
|
|
unsigned i;
|
|
|
|
|
int key;
|
|
|
|
|
int valid_code;
|
|
|
|
|
|
|
|
|
|
/* Enable all tested keys on the device */
|
|
|
|
|
i = 0;
|
|
|
|
|
while (i < 2 * ARRAY_LENGTH(keys)) {
|
|
|
|
|
key = keys[i / 2].code;
|
|
|
|
|
events[i++] = EV_KEY;
|
|
|
|
|
events[i++] = key;
|
|
|
|
|
}
|
|
|
|
|
events[i++] = -1;
|
|
|
|
|
events[i++] = -1;
|
|
|
|
|
|
2025-04-07 13:15:28 +10:00
|
|
|
_litest_context_destroy_ struct libinput *libinput = litest_create_context();
|
2014-07-27 16:02:46 +02:00
|
|
|
dev = litest_add_device_with_overrides(libinput,
|
|
|
|
|
LITEST_KEYBOARD,
|
|
|
|
|
"Generic keyboard",
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
events);
|
|
|
|
|
|
|
|
|
|
litest_drain_events(libinput);
|
|
|
|
|
|
|
|
|
|
/* Send pressed events, without releasing */
|
|
|
|
|
for (i = 0; i < ARRAY_LENGTH(keys); ++i) {
|
2015-05-05 15:43:08 +10:00
|
|
|
key = keys[i].code;
|
|
|
|
|
litest_event(dev, EV_KEY, key, 1);
|
|
|
|
|
litest_event(dev, EV_SYN, SYN_REPORT, 0);
|
|
|
|
|
|
2024-09-13 15:13:38 +10:00
|
|
|
litest_dispatch(libinput);
|
2015-05-05 15:43:08 +10:00
|
|
|
|
|
|
|
|
event = libinput_get_event(libinput);
|
2017-07-06 16:45:41 +10:00
|
|
|
litest_is_keyboard_event(event, key, LIBINPUT_KEY_STATE_PRESSED);
|
2015-05-05 15:43:08 +10:00
|
|
|
libinput_event_destroy(event);
|
2014-07-27 16:02:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
litest_drain_events(libinput);
|
|
|
|
|
|
|
|
|
|
/* "Disconnect" device */
|
2025-04-07 15:12:51 +10:00
|
|
|
litest_device_destroy(dev);
|
2014-07-27 16:02:46 +02:00
|
|
|
|
|
|
|
|
/* Mark all released keys until device is removed */
|
|
|
|
|
while (1) {
|
|
|
|
|
event = libinput_get_event(libinput);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_notnull(event);
|
2014-07-27 16:02:46 +02:00
|
|
|
type = libinput_event_get_type(event);
|
|
|
|
|
|
|
|
|
|
if (type == LIBINPUT_EVENT_DEVICE_REMOVED) {
|
|
|
|
|
libinput_event_destroy(event);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-18 14:44:38 +10:00
|
|
|
litest_assert_event_type(event, LIBINPUT_EVENT_KEYBOARD_KEY);
|
2014-07-27 16:02:46 +02:00
|
|
|
kevent = libinput_event_get_keyboard_event(event);
|
2024-09-16 16:49:38 +10:00
|
|
|
litest_assert_enum_eq(libinput_event_keyboard_get_key_state(kevent),
|
|
|
|
|
LIBINPUT_KEY_STATE_RELEASED);
|
2014-07-27 16:02:46 +02:00
|
|
|
key = libinput_event_keyboard_get_key(kevent);
|
|
|
|
|
|
|
|
|
|
valid_code = 0;
|
|
|
|
|
for (i = 0; i < ARRAY_LENGTH(keys); ++i) {
|
|
|
|
|
if (keys[i].code == key) {
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_int_eq(keys[i].released, 0);
|
2014-07-27 16:02:46 +02:00
|
|
|
keys[i].released = 1;
|
|
|
|
|
valid_code = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_int_eq(valid_code, 1);
|
2014-07-27 16:02:46 +02:00
|
|
|
libinput_event_destroy(event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Check that all pressed keys has been released. */
|
|
|
|
|
for (i = 0; i < ARRAY_LENGTH(keys); ++i) {
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_int_eq(keys[i].released, 1);
|
2014-07-27 16:02:46 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2015-04-22 14:36:25 +10:00
|
|
|
START_TEST(keyboard_has_key)
|
|
|
|
|
{
|
|
|
|
|
struct litest_device *dev = litest_current_device();
|
|
|
|
|
struct libinput_device *device = dev->libinput_device;
|
|
|
|
|
unsigned int code;
|
|
|
|
|
int evdev_has, libinput_has;
|
|
|
|
|
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert(
|
|
|
|
|
libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_KEYBOARD));
|
2015-04-22 14:36:25 +10:00
|
|
|
|
|
|
|
|
for (code = 0; code < KEY_CNT; code++) {
|
|
|
|
|
evdev_has = libevdev_has_event_code(dev->evdev, EV_KEY, code);
|
|
|
|
|
libinput_has = libinput_device_keyboard_has_key(device, code);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_int_eq(evdev_has, libinput_has);
|
2015-04-22 14:36:25 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2015-04-24 17:21:18 -05:00
|
|
|
START_TEST(keyboard_keys_bad_device)
|
|
|
|
|
{
|
|
|
|
|
struct litest_device *dev = litest_current_device();
|
|
|
|
|
struct libinput_device *device = dev->libinput_device;
|
|
|
|
|
unsigned int code;
|
|
|
|
|
int has_key;
|
|
|
|
|
|
|
|
|
|
if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_KEYBOARD))
|
2024-10-12 10:31:42 +10:00
|
|
|
return LITEST_NOT_APPLICABLE;
|
2015-04-24 17:21:18 -05:00
|
|
|
|
|
|
|
|
for (code = 0; code < KEY_CNT; code++) {
|
|
|
|
|
has_key = libinput_device_keyboard_has_key(device, code);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_int_eq(has_key, -1);
|
2015-04-24 17:21:18 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2015-07-27 17:51:52 +08:00
|
|
|
START_TEST(keyboard_time_usec)
|
|
|
|
|
{
|
|
|
|
|
struct litest_device *dev = litest_current_device();
|
|
|
|
|
struct libinput *li = dev->libinput;
|
|
|
|
|
struct libinput_event_keyboard *kev;
|
|
|
|
|
struct libinput_event *event;
|
2016-04-08 15:51:26 +08:00
|
|
|
uint64_t time_usec;
|
2015-07-27 17:51:52 +08:00
|
|
|
|
|
|
|
|
if (!libevdev_has_event_code(dev->evdev, EV_KEY, KEY_A))
|
2024-10-12 10:31:42 +10:00
|
|
|
return LITEST_NOT_APPLICABLE;
|
2015-07-27 17:51:52 +08:00
|
|
|
|
|
|
|
|
litest_drain_events(dev->libinput);
|
|
|
|
|
|
|
|
|
|
litest_keyboard_key(dev, KEY_A, true);
|
2024-09-13 15:13:38 +10:00
|
|
|
litest_dispatch(li);
|
2015-07-27 17:51:52 +08:00
|
|
|
|
|
|
|
|
event = libinput_get_event(li);
|
|
|
|
|
kev = litest_is_keyboard_event(event, KEY_A, LIBINPUT_KEY_STATE_PRESSED);
|
|
|
|
|
|
2016-04-08 15:51:26 +08:00
|
|
|
time_usec = libinput_event_keyboard_get_time_usec(kev);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_int_eq(libinput_event_keyboard_get_time(kev),
|
2016-04-08 15:51:26 +08:00
|
|
|
(uint32_t)(time_usec / 1000));
|
2015-07-27 17:51:52 +08:00
|
|
|
|
|
|
|
|
libinput_event_destroy(event);
|
|
|
|
|
litest_drain_events(dev->libinput);
|
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2016-05-10 12:07:36 +10:00
|
|
|
START_TEST(keyboard_no_buttons)
|
|
|
|
|
{
|
|
|
|
|
struct litest_device *dev = litest_current_device();
|
|
|
|
|
struct libinput *li = dev->libinput;
|
|
|
|
|
struct libinput_event *event;
|
|
|
|
|
int code;
|
|
|
|
|
const char *name;
|
|
|
|
|
|
|
|
|
|
litest_drain_events(dev->libinput);
|
|
|
|
|
|
|
|
|
|
for (code = 0; code < KEY_MAX; code++) {
|
|
|
|
|
if (!libevdev_has_event_code(dev->evdev, EV_KEY, code))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
name = libevdev_event_code_get_name(EV_KEY, code);
|
2025-01-09 09:04:54 +10:00
|
|
|
if (!strstartswith(name, "KEY_"))
|
2016-05-10 12:07:36 +10:00
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
litest_keyboard_key(dev, code, true);
|
|
|
|
|
litest_keyboard_key(dev, code, false);
|
2024-09-13 15:13:38 +10:00
|
|
|
litest_dispatch(li);
|
2016-05-10 12:07:36 +10:00
|
|
|
|
|
|
|
|
event = libinput_get_event(li);
|
|
|
|
|
litest_is_keyboard_event(event, code, LIBINPUT_KEY_STATE_PRESSED);
|
|
|
|
|
libinput_event_destroy(event);
|
|
|
|
|
event = libinput_get_event(li);
|
|
|
|
|
litest_is_keyboard_event(event, code, LIBINPUT_KEY_STATE_RELEASED);
|
|
|
|
|
libinput_event_destroy(event);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2017-12-08 09:41:07 +10:00
|
|
|
START_TEST(keyboard_frame_order)
|
|
|
|
|
{
|
|
|
|
|
struct litest_device *dev = litest_current_device();
|
|
|
|
|
struct libinput *li = dev->libinput;
|
|
|
|
|
|
|
|
|
|
if (!libevdev_has_event_code(dev->evdev, EV_KEY, KEY_A) ||
|
|
|
|
|
!libevdev_has_event_code(dev->evdev, EV_KEY, KEY_LEFTSHIFT))
|
2024-10-12 10:31:42 +10:00
|
|
|
return LITEST_NOT_APPLICABLE;
|
2017-12-08 09:41:07 +10:00
|
|
|
|
|
|
|
|
litest_drain_events(li);
|
|
|
|
|
|
|
|
|
|
litest_event(dev, EV_KEY, KEY_LEFTSHIFT, 1);
|
|
|
|
|
litest_event(dev, EV_KEY, KEY_A, 1);
|
|
|
|
|
litest_event(dev, EV_SYN, SYN_REPORT, 0);
|
2024-09-13 15:13:38 +10:00
|
|
|
litest_dispatch(li);
|
2017-12-08 09:41:07 +10:00
|
|
|
|
|
|
|
|
litest_assert_key_event(li, KEY_LEFTSHIFT, LIBINPUT_KEY_STATE_PRESSED);
|
|
|
|
|
litest_assert_key_event(li, KEY_A, LIBINPUT_KEY_STATE_PRESSED);
|
|
|
|
|
|
|
|
|
|
litest_event(dev, EV_KEY, KEY_LEFTSHIFT, 0);
|
|
|
|
|
litest_event(dev, EV_KEY, KEY_A, 0);
|
|
|
|
|
litest_event(dev, EV_SYN, SYN_REPORT, 0);
|
2024-09-13 15:13:38 +10:00
|
|
|
litest_dispatch(li);
|
2017-12-08 09:41:07 +10:00
|
|
|
|
|
|
|
|
litest_assert_key_event(li, KEY_LEFTSHIFT, LIBINPUT_KEY_STATE_RELEASED);
|
|
|
|
|
litest_assert_key_event(li, KEY_A, LIBINPUT_KEY_STATE_RELEASED);
|
|
|
|
|
|
|
|
|
|
litest_event(dev, EV_KEY, KEY_A, 1);
|
|
|
|
|
litest_event(dev, EV_KEY, KEY_LEFTSHIFT, 1);
|
|
|
|
|
litest_event(dev, EV_SYN, SYN_REPORT, 0);
|
2024-09-13 15:13:38 +10:00
|
|
|
litest_dispatch(li);
|
2017-12-08 09:41:07 +10:00
|
|
|
|
|
|
|
|
litest_assert_key_event(li, KEY_A, LIBINPUT_KEY_STATE_PRESSED);
|
|
|
|
|
litest_assert_key_event(li, KEY_LEFTSHIFT, LIBINPUT_KEY_STATE_PRESSED);
|
|
|
|
|
|
|
|
|
|
litest_event(dev, EV_KEY, KEY_A, 0);
|
|
|
|
|
litest_event(dev, EV_KEY, KEY_LEFTSHIFT, 0);
|
|
|
|
|
litest_event(dev, EV_SYN, SYN_REPORT, 0);
|
2024-09-13 15:13:38 +10:00
|
|
|
litest_dispatch(li);
|
2017-12-08 09:41:07 +10:00
|
|
|
|
|
|
|
|
litest_assert_key_event(li, KEY_A, LIBINPUT_KEY_STATE_RELEASED);
|
|
|
|
|
litest_assert_key_event(li, KEY_LEFTSHIFT, LIBINPUT_KEY_STATE_RELEASED);
|
|
|
|
|
|
2024-09-13 15:13:38 +10:00
|
|
|
litest_dispatch(li);
|
2017-12-08 09:41:07 +10:00
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2017-01-13 11:24:14 +10:00
|
|
|
START_TEST(keyboard_leds)
|
|
|
|
|
{
|
|
|
|
|
struct litest_device *dev = litest_current_device();
|
|
|
|
|
struct libinput_device *device = dev->libinput_device;
|
|
|
|
|
|
|
|
|
|
/* we can't actually test the results here without physically
|
|
|
|
|
* looking at the LEDs. So all we do is trigger the code for devices
|
|
|
|
|
* with and without LEDs and check that it doesn't go boom
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
libinput_device_led_update(device, LIBINPUT_LED_NUM_LOCK);
|
|
|
|
|
libinput_device_led_update(device, LIBINPUT_LED_CAPS_LOCK);
|
|
|
|
|
libinput_device_led_update(device, LIBINPUT_LED_SCROLL_LOCK);
|
2024-04-25 11:03:52 +02:00
|
|
|
libinput_device_led_update(device, LIBINPUT_LED_COMPOSE);
|
|
|
|
|
libinput_device_led_update(device, LIBINPUT_LED_KANA);
|
2017-01-13 11:24:14 +10:00
|
|
|
|
|
|
|
|
libinput_device_led_update(device,
|
|
|
|
|
LIBINPUT_LED_NUM_LOCK | LIBINPUT_LED_CAPS_LOCK);
|
|
|
|
|
libinput_device_led_update(device,
|
|
|
|
|
LIBINPUT_LED_NUM_LOCK | LIBINPUT_LED_CAPS_LOCK |
|
|
|
|
|
LIBINPUT_LED_SCROLL_LOCK);
|
2024-04-25 11:03:52 +02:00
|
|
|
libinput_device_led_update(device,
|
|
|
|
|
LIBINPUT_LED_NUM_LOCK | LIBINPUT_LED_CAPS_LOCK |
|
|
|
|
|
LIBINPUT_LED_SCROLL_LOCK |
|
|
|
|
|
LIBINPUT_LED_COMPOSE | LIBINPUT_LED_KANA);
|
2017-01-13 11:24:14 +10:00
|
|
|
libinput_device_led_update(device, 0);
|
|
|
|
|
libinput_device_led_update(device, -1);
|
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2017-01-16 14:20:23 +10:00
|
|
|
START_TEST(keyboard_no_scroll)
|
|
|
|
|
{
|
|
|
|
|
struct litest_device *dev = litest_current_device();
|
|
|
|
|
struct libinput_device *device = dev->libinput_device;
|
|
|
|
|
enum libinput_config_scroll_method method;
|
|
|
|
|
enum libinput_config_status status;
|
|
|
|
|
|
|
|
|
|
method = libinput_device_config_scroll_get_method(device);
|
2024-09-16 16:49:38 +10:00
|
|
|
litest_assert_enum_eq(method, LIBINPUT_CONFIG_SCROLL_NO_SCROLL);
|
2017-01-16 14:20:23 +10:00
|
|
|
method = libinput_device_config_scroll_get_default_method(device);
|
2024-09-16 16:49:38 +10:00
|
|
|
litest_assert_enum_eq(method, LIBINPUT_CONFIG_SCROLL_NO_SCROLL);
|
2017-01-16 14:20:23 +10:00
|
|
|
|
|
|
|
|
status = libinput_device_config_scroll_set_method(device,
|
|
|
|
|
LIBINPUT_CONFIG_SCROLL_2FG);
|
2024-09-16 16:49:38 +10:00
|
|
|
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED);
|
2017-01-16 14:20:23 +10:00
|
|
|
status = libinput_device_config_scroll_set_method(device,
|
|
|
|
|
LIBINPUT_CONFIG_SCROLL_EDGE);
|
2024-09-16 16:49:38 +10:00
|
|
|
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED);
|
2017-01-16 14:20:23 +10:00
|
|
|
status = libinput_device_config_scroll_set_method(
|
|
|
|
|
device,
|
|
|
|
|
LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN);
|
2024-09-16 16:49:38 +10:00
|
|
|
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED);
|
2017-01-16 14:20:23 +10:00
|
|
|
status = libinput_device_config_scroll_set_method(
|
|
|
|
|
device,
|
|
|
|
|
LIBINPUT_CONFIG_SCROLL_NO_SCROLL);
|
2024-09-16 16:49:38 +10:00
|
|
|
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
|
2017-01-16 14:20:23 +10:00
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
evdev: track KEY_SYSRQ frames and pass them even as repeat frames
Alt+Printscreen aka KEY_LEFTALT + KEY_SYSRQ is emulated by the kernel
and always posted with SYN_REPORT 1, see
drivers/tty/sysrq.c:sysrq_reinject_alt_sysrq()
The actual sequence when pressing Alt + Printscreen is to release Alt
first, then press it again:
- evdev:
- [ 10, 674010, 1, 56, 0] # EV_KEY / KEY_LEFTALT 0
- [ 10, 674010, 0, 0, 0] # ------------ SYN_REPORT (0) ---------- +2861ms
- evdev:
- [ 10, 674030, 1, 56, 1] # EV_KEY / KEY_LEFTALT 1
- [ 10, 674030, 1, 99, 1] # EV_KEY / KEY_SYSRQ 1
- [ 10, 674030, 0, 0, 1] # ------------ SYN_REPORT (1) ---------- +0ms
- evdev:
- [ 10, 674031, 1, 99, 0] # EV_KEY / KEY_SYSRQ 0
- [ 10, 674031, 1, 56, 0] # EV_KEY / KEY_LEFTALT 0
- [ 10, 674031, 0, 0, 1] # ------------ SYN_REPORT (1) ---------- +0ms
Handle that special case so we get our printscreen key to work as
expected anymore.
Fixes: 9a9466b6a92c ("evdev: discard any frame with EV_SYN SYN_REPORT 1")
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1273>
2025-07-15 21:29:43 +10:00
|
|
|
START_TEST(keyboard_alt_printscreen)
|
|
|
|
|
{
|
|
|
|
|
struct litest_device *dev = litest_current_device();
|
|
|
|
|
struct libinput *li = dev->libinput;
|
|
|
|
|
|
|
|
|
|
litest_drain_events(li);
|
|
|
|
|
|
|
|
|
|
/* repeat frame, ignored */
|
|
|
|
|
litest_event(dev, EV_KEY, KEY_A, 1);
|
|
|
|
|
litest_event(dev, EV_SYN, SYN_REPORT, 1);
|
|
|
|
|
litest_dispatch(li);
|
|
|
|
|
litest_assert_empty_queue(li);
|
|
|
|
|
|
|
|
|
|
/* not a repeat frame */
|
|
|
|
|
litest_event(dev, EV_KEY, KEY_LEFTALT, 1);
|
|
|
|
|
litest_event(dev, EV_SYN, SYN_REPORT, 0);
|
|
|
|
|
litest_dispatch(li);
|
|
|
|
|
litest_assert_key_event(li, KEY_LEFTALT, LIBINPUT_KEY_STATE_PRESSED);
|
|
|
|
|
|
|
|
|
|
/* normal repeat frame, ignored */
|
|
|
|
|
litest_event(dev, EV_KEY, KEY_LEFTALT, 2);
|
|
|
|
|
litest_event(dev, EV_SYN, SYN_REPORT, 1);
|
|
|
|
|
litest_dispatch(li);
|
|
|
|
|
litest_assert_empty_queue(li);
|
|
|
|
|
|
|
|
|
|
/* not repeat frame */
|
|
|
|
|
litest_event(dev, EV_KEY, KEY_LEFTALT, 0);
|
|
|
|
|
litest_event(dev, EV_SYN, SYN_REPORT, 0);
|
|
|
|
|
litest_dispatch(li);
|
|
|
|
|
litest_assert_key_event(li, KEY_LEFTALT, LIBINPUT_KEY_STATE_RELEASED);
|
|
|
|
|
|
|
|
|
|
/* special alt+printscreen repeat frame, *not* ignored */
|
|
|
|
|
litest_event(dev, EV_KEY, KEY_LEFTALT, 1);
|
|
|
|
|
litest_event(dev, EV_KEY, KEY_SYSRQ, 1);
|
|
|
|
|
litest_event(dev, EV_SYN, SYN_REPORT, 1);
|
|
|
|
|
litest_dispatch(li);
|
|
|
|
|
|
|
|
|
|
/* special alt+printscreen repeat frame, *not* ignored */
|
|
|
|
|
litest_event(dev, EV_KEY, KEY_LEFTALT, 0);
|
|
|
|
|
litest_event(dev, EV_KEY, KEY_SYSRQ, 0);
|
|
|
|
|
litest_event(dev, EV_SYN, SYN_REPORT, 1);
|
|
|
|
|
litest_dispatch(li);
|
|
|
|
|
|
|
|
|
|
/* Note: the kernel doesn't release the key combo until both keys are released
|
|
|
|
|
* and the order is reshuffled so we have alt down, sysrq down, sysrq up, alt up
|
|
|
|
|
*/
|
|
|
|
|
litest_assert_key_event(li, KEY_LEFTALT, LIBINPUT_KEY_STATE_PRESSED);
|
|
|
|
|
litest_assert_key_event(li, KEY_SYSRQ, LIBINPUT_KEY_STATE_PRESSED);
|
|
|
|
|
litest_assert_key_event(li, KEY_SYSRQ, LIBINPUT_KEY_STATE_RELEASED);
|
|
|
|
|
litest_assert_key_event(li, KEY_LEFTALT, LIBINPUT_KEY_STATE_RELEASED);
|
|
|
|
|
|
|
|
|
|
litest_assert_empty_queue(li);
|
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2018-03-21 12:54:10 +10:00
|
|
|
TEST_COLLECTION(keyboard)
|
2014-04-01 22:24:10 +02:00
|
|
|
{
|
2025-07-01 11:30:59 +10:00
|
|
|
/* clang-format off */
|
2021-02-05 14:51:02 +10:00
|
|
|
litest_add_no_device(keyboard_seat_key_count);
|
|
|
|
|
litest_add_no_device(keyboard_ignore_no_pressed_release);
|
|
|
|
|
litest_add_no_device(keyboard_key_auto_release);
|
|
|
|
|
litest_add(keyboard_has_key, LITEST_KEYS, LITEST_ANY);
|
|
|
|
|
litest_add(keyboard_keys_bad_device, LITEST_ANY, LITEST_ANY);
|
|
|
|
|
litest_add(keyboard_time_usec, LITEST_KEYS, LITEST_ANY);
|
2016-05-10 12:07:36 +10:00
|
|
|
|
2021-02-05 14:51:02 +10:00
|
|
|
litest_add(keyboard_no_buttons, LITEST_KEYS, LITEST_ANY);
|
|
|
|
|
litest_add(keyboard_frame_order, LITEST_KEYS, LITEST_ANY);
|
2017-01-13 11:24:14 +10:00
|
|
|
|
2021-02-05 14:51:02 +10:00
|
|
|
litest_add(keyboard_leds, LITEST_ANY, LITEST_ANY);
|
2017-01-16 14:20:23 +10:00
|
|
|
|
2021-02-05 14:51:02 +10:00
|
|
|
litest_add(keyboard_no_scroll, LITEST_KEYS, LITEST_WHEEL);
|
evdev: track KEY_SYSRQ frames and pass them even as repeat frames
Alt+Printscreen aka KEY_LEFTALT + KEY_SYSRQ is emulated by the kernel
and always posted with SYN_REPORT 1, see
drivers/tty/sysrq.c:sysrq_reinject_alt_sysrq()
The actual sequence when pressing Alt + Printscreen is to release Alt
first, then press it again:
- evdev:
- [ 10, 674010, 1, 56, 0] # EV_KEY / KEY_LEFTALT 0
- [ 10, 674010, 0, 0, 0] # ------------ SYN_REPORT (0) ---------- +2861ms
- evdev:
- [ 10, 674030, 1, 56, 1] # EV_KEY / KEY_LEFTALT 1
- [ 10, 674030, 1, 99, 1] # EV_KEY / KEY_SYSRQ 1
- [ 10, 674030, 0, 0, 1] # ------------ SYN_REPORT (1) ---------- +0ms
- evdev:
- [ 10, 674031, 1, 99, 0] # EV_KEY / KEY_SYSRQ 0
- [ 10, 674031, 1, 56, 0] # EV_KEY / KEY_LEFTALT 0
- [ 10, 674031, 0, 0, 1] # ------------ SYN_REPORT (1) ---------- +0ms
Handle that special case so we get our printscreen key to work as
expected anymore.
Fixes: 9a9466b6a92c ("evdev: discard any frame with EV_SYN SYN_REPORT 1")
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1273>
2025-07-15 21:29:43 +10:00
|
|
|
|
|
|
|
|
litest_add_for_device(keyboard_alt_printscreen, LITEST_KEYBOARD);
|
2025-07-01 11:30:59 +10:00
|
|
|
/* clang-format on */
|
2014-04-01 22:24:10 +02:00
|
|
|
}
|