mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2025-12-30 20:00:09 +01:00
Add libinput_device_keyboard_has_key()
Similar to libinput_device_pointer_has_button(), this function returns whether a given device has a specific keycode. This enables a caller to determine if the device is really a keyboard (check for KEY_A-KEY_Z) or just a media key device (check for KEY_PLAY or somesuch), depending on the context required. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Hans de Goede <hdegoede@redhat.com> Reviewed-by: Derek Foreman <derekf@osg.samsung.com>
This commit is contained in:
parent
5c671e0375
commit
4996076a7c
6 changed files with 59 additions and 0 deletions
|
|
@ -2148,6 +2148,15 @@ evdev_device_has_button(struct evdev_device *device, uint32_t code)
|
|||
return libevdev_has_event_code(device->evdev, EV_KEY, code);
|
||||
}
|
||||
|
||||
int
|
||||
evdev_device_has_key(struct evdev_device *device, uint32_t code)
|
||||
{
|
||||
if (!(device->seat_caps & EVDEV_DEVICE_KEYBOARD))
|
||||
return -1;
|
||||
|
||||
return libevdev_has_event_code(device->evdev, EV_KEY, code);
|
||||
}
|
||||
|
||||
static inline bool
|
||||
evdev_is_scrolling(const struct evdev_device *device,
|
||||
enum libinput_pointer_axis axis)
|
||||
|
|
|
|||
|
|
@ -316,6 +316,9 @@ evdev_device_get_size(struct evdev_device *device,
|
|||
int
|
||||
evdev_device_has_button(struct evdev_device *device, uint32_t code);
|
||||
|
||||
int
|
||||
evdev_device_has_key(struct evdev_device *device, uint32_t code);
|
||||
|
||||
double
|
||||
evdev_device_transform_x(struct evdev_device *device,
|
||||
double x,
|
||||
|
|
|
|||
|
|
@ -1547,6 +1547,12 @@ libinput_device_pointer_has_button(struct libinput_device *device, uint32_t code
|
|||
return evdev_device_has_button((struct evdev_device *)device, code);
|
||||
}
|
||||
|
||||
LIBINPUT_EXPORT int
|
||||
libinput_device_keyboard_has_key(struct libinput_device *device, uint32_t code)
|
||||
{
|
||||
return evdev_device_has_key((struct evdev_device *)device, code);
|
||||
}
|
||||
|
||||
LIBINPUT_EXPORT struct libinput_event *
|
||||
libinput_event_device_notify_get_base_event(struct libinput_event_device_notify *event)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1708,6 +1708,22 @@ libinput_device_get_size(struct libinput_device *device,
|
|||
int
|
||||
libinput_device_pointer_has_button(struct libinput_device *device, uint32_t code);
|
||||
|
||||
/**
|
||||
* @ingroup device
|
||||
*
|
||||
* Check if a @ref LIBINPUT_DEVICE_CAP_KEYBOARD device has a key with the
|
||||
* given code (see linux/input.h).
|
||||
*
|
||||
* @param device A current input device
|
||||
* @param code Key code to check for, e.g. <i>KEY_ESC</i>
|
||||
*
|
||||
* @return 1 if the device supports this key code, 0 if it does not, -1
|
||||
* on error.
|
||||
*/
|
||||
int
|
||||
libinput_device_keyboard_has_key(struct libinput_device *device,
|
||||
uint32_t code);
|
||||
|
||||
/**
|
||||
* @ingroup device
|
||||
*
|
||||
|
|
|
|||
|
|
@ -135,3 +135,8 @@ global:
|
|||
libinput_device_config_middle_emulation_is_available;
|
||||
libinput_device_config_middle_emulation_set_enabled;
|
||||
} LIBINPUT_0.12.0;
|
||||
|
||||
LIBINPUT_0.15.0 {
|
||||
global:
|
||||
libinput_device_keyboard_has_key;
|
||||
} LIBINPUT_0.14.0;
|
||||
|
|
|
|||
|
|
@ -290,12 +290,32 @@ START_TEST(keyboard_key_auto_release)
|
|||
}
|
||||
END_TEST
|
||||
|
||||
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;
|
||||
|
||||
ck_assert(libinput_device_has_capability(
|
||||
device,
|
||||
LIBINPUT_DEVICE_CAP_KEYBOARD));
|
||||
|
||||
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);
|
||||
ck_assert_int_eq(evdev_has, libinput_has);
|
||||
}
|
||||
}
|
||||
END_TEST
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
litest_add_no_device("keyboard:seat key count", keyboard_seat_key_count);
|
||||
litest_add_no_device("keyboard:key counting", keyboard_ignore_no_pressed_release);
|
||||
litest_add_no_device("keyboard:key counting", keyboard_key_auto_release);
|
||||
litest_add("keyboard:keys", keyboard_has_key, LITEST_KEYS, LITEST_ANY);
|
||||
|
||||
return litest_run(argc, argv);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue