Commit d9a729e1 authored by Peter Hutterer's avatar Peter Hutterer

Add libinput_device_switch_has_switch()

Signed-off-by: Peter Hutterer's avatarPeter Hutterer <peter.hutterer@who-t.net>
parent e242ad21
......@@ -3417,6 +3417,26 @@ evdev_device_has_key(struct evdev_device *device, uint32_t code)
return libevdev_has_event_code(device->evdev, EV_KEY, code);
}
int
evdev_device_has_switch(struct evdev_device *device,
enum libinput_switch sw)
{
unsigned int code;
if (!(device->seat_caps & EVDEV_DEVICE_SWITCH))
return -1;
switch (sw) {
case LIBINPUT_SWITCH_LID:
code = SW_LID;
break;
default:
return -1;
}
return libevdev_has_event_code(device->evdev, EV_SW, code);
}
static inline bool
evdev_is_scrolling(const struct evdev_device *device,
enum libinput_pointer_axis axis)
......
......@@ -489,6 +489,10 @@ evdev_device_has_button(struct evdev_device *device, uint32_t code);
int
evdev_device_has_key(struct evdev_device *device, uint32_t code);
int
evdev_device_has_switch(struct evdev_device *device,
enum libinput_switch sw);
int
evdev_device_tablet_pad_get_num_buttons(struct evdev_device *device);
......
......@@ -2936,6 +2936,13 @@ libinput_device_keyboard_has_key(struct libinput_device *device, uint32_t code)
return evdev_device_has_key((struct evdev_device *)device, code);
}
LIBINPUT_EXPORT int
libinput_device_switch_has_switch(struct libinput_device *device,
enum libinput_switch sw)
{
return evdev_device_has_switch((struct evdev_device *)device, sw);
}
LIBINPUT_EXPORT int
libinput_device_tablet_pad_get_num_buttons(struct libinput_device *device)
{
......
......@@ -3696,6 +3696,22 @@ int
libinput_device_keyboard_has_key(struct libinput_device *device,
uint32_t code);
/**
* @ingroup device
*
* Check if a @ref LIBINPUT_DEVICE_CAP_SWITCH device has a switch of the
* given type.
*
* @param device A current input device
* @param sw Switch to check for
*
* @return 1 if the device supports this switch, 0 if it does not, -1
* on error.
*/
int
libinput_device_switch_has_switch(struct libinput_device *device,
enum libinput_switch sw);
/**
* @ingroup device
*
......
......@@ -289,3 +289,7 @@ LIBINPUT_1.7 {
libinput_event_switch_get_time;
libinput_event_switch_get_time_usec;
} LIBINPUT_1.5;
LIBINPUT_1.9 {
libinput_device_switch_has_switch;
} LIBINPUT_1.7;
......@@ -39,6 +39,16 @@ START_TEST(switch_has_cap)
}
END_TEST
START_TEST(switch_has)
{
struct litest_device *dev = litest_current_device();
ck_assert_int_eq(libinput_device_switch_has_switch(dev->libinput_device,
LIBINPUT_SWITCH_LID),
1);
}
END_TEST
START_TEST(switch_toggle)
{
struct litest_device *dev = litest_current_device();
......@@ -605,6 +615,7 @@ void
litest_setup_tests_lid(void)
{
litest_add("switch:has", switch_has_cap, LITEST_SWITCH, LITEST_ANY);
litest_add("switch:has", switch_has, LITEST_SWITCH, LITEST_ANY);
litest_add("switch:toggle", switch_toggle, LITEST_SWITCH, LITEST_ANY);
litest_add("switch:toggle", switch_toggle_double, LITEST_SWITCH, LITEST_ANY);
litest_add("switch:toggle", switch_down_on_init, LITEST_SWITCH, LITEST_ANY);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment