2 * Copyright © 2014 Jonas Ådahl <jadahl@gmail.com>
4 * Permission to use, copy, modify, distribute, and sell this software and
5 * its documentation for any purpose is hereby granted without fee, provided
6 * that the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of the copyright holders not be used in
9 * advertising or publicity pertaining to distribution of the software
10 * without specific, written prior permission. The copyright holders make
11 * no representations about the suitability of this software for any
12 * purpose. It is provided "as is" without express or implied warranty.
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
15 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
17 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
18 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
19 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
20 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
30 START_TEST(keyboard_seat_key_count)
32 const int num_devices = 4;
33 struct litest_device *devices[num_devices];
34 struct libinput *libinput;
35 struct libinput_event *ev;
36 struct libinput_event_keyboard *kev;
39 int expected_key_button_count = 0;
40 char device_name[255];
42 libinput = litest_create_context();
43 for (i = 0; i < num_devices; ++i) {
44 sprintf(device_name, "Generic keyboard (%d)", i);
45 devices[i] = litest_add_device_with_overrides(libinput,
51 for (i = 0; i < num_devices; ++i)
52 litest_keyboard_key(devices[i], KEY_A, true);
54 libinput_dispatch(libinput);
55 while ((ev = libinput_get_event(libinput))) {
56 if (libinput_event_get_type(ev) !=
57 LIBINPUT_EVENT_KEYBOARD_KEY) {
58 libinput_event_destroy(ev);
59 libinput_dispatch(libinput);
63 kev = libinput_event_get_keyboard_event(ev);
64 ck_assert_notnull(kev);
65 ck_assert_int_eq(libinput_event_keyboard_get_key(kev), KEY_A);
66 ck_assert_int_eq(libinput_event_keyboard_get_key_state(kev),
67 LIBINPUT_KEY_STATE_PRESSED);
69 ++expected_key_button_count;
71 libinput_event_keyboard_get_seat_key_count(kev);
72 ck_assert_int_eq(expected_key_button_count, seat_key_count);
74 libinput_event_destroy(ev);
75 libinput_dispatch(libinput);
78 ck_assert_int_eq(seat_key_count, num_devices);
80 for (i = 0; i < num_devices; ++i)
81 litest_keyboard_key(devices[i], KEY_A, false);
83 libinput_dispatch(libinput);
84 while ((ev = libinput_get_event(libinput))) {
85 if (libinput_event_get_type(ev) !=
86 LIBINPUT_EVENT_KEYBOARD_KEY) {
87 libinput_event_destroy(ev);
88 libinput_dispatch(libinput);
92 kev = libinput_event_get_keyboard_event(ev);
93 ck_assert_notnull(kev);
94 ck_assert_int_eq(libinput_event_keyboard_get_key(kev), KEY_A);
95 ck_assert_int_eq(libinput_event_keyboard_get_key_state(kev),
96 LIBINPUT_KEY_STATE_RELEASED);
98 --expected_key_button_count;
100 libinput_event_keyboard_get_seat_key_count(kev);
101 ck_assert_int_eq(expected_key_button_count, seat_key_count);
103 libinput_event_destroy(ev);
104 libinput_dispatch(libinput);
107 ck_assert_int_eq(seat_key_count, 0);
109 for (i = 0; i < num_devices; ++i)
110 litest_delete_device(devices[i]);
111 libinput_destroy(libinput);
116 main(int argc, char **argv)
118 litest_add_no_device("keyboard:seat key count", keyboard_seat_key_count);
120 return litest_run(argc, argv);