mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2026-05-08 08:58:04 +02:00
Add a generic libinput_event_get_device() function
After dropping seat evens, all events are now are associated with a device, so provide a generic accessor function and drop the custom ones. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
parent
c29a8e8093
commit
60d46e6bd7
4 changed files with 28 additions and 41 deletions
|
|
@ -50,7 +50,7 @@ struct libinput_source {
|
||||||
|
|
||||||
struct libinput_event {
|
struct libinput_event {
|
||||||
enum libinput_event_type type;
|
enum libinput_event_type type;
|
||||||
struct libinput *libinput;
|
struct libinput_device *device;
|
||||||
union libinput_event_target target;
|
union libinput_event_target target;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -127,19 +127,11 @@ libinput_event_get_target(struct libinput_event *event)
|
||||||
LIBINPUT_EXPORT struct libinput*
|
LIBINPUT_EXPORT struct libinput*
|
||||||
libinput_event_get_context(struct libinput_event *event)
|
libinput_event_get_context(struct libinput_event *event)
|
||||||
{
|
{
|
||||||
return event->libinput;
|
return event->device->seat->libinput;
|
||||||
}
|
}
|
||||||
|
|
||||||
LIBINPUT_EXPORT struct libinput_device *
|
LIBINPUT_EXPORT struct libinput_device*
|
||||||
libinput_event_added_device_get_device(
|
libinput_event_get_device(struct libinput_event *event)
|
||||||
struct libinput_event_added_device *event)
|
|
||||||
{
|
|
||||||
return event->device;
|
|
||||||
}
|
|
||||||
|
|
||||||
LIBINPUT_EXPORT struct libinput_device *
|
|
||||||
libinput_event_removed_device_get_device(
|
|
||||||
struct libinput_event_removed_device *event)
|
|
||||||
{
|
{
|
||||||
return event->device;
|
return event->device;
|
||||||
}
|
}
|
||||||
|
|
@ -584,21 +576,22 @@ libinput_dispatch(struct libinput *libinput)
|
||||||
|
|
||||||
static void
|
static void
|
||||||
init_event_base(struct libinput_event *event,
|
init_event_base(struct libinput_event *event,
|
||||||
struct libinput *libinput,
|
struct libinput_device *device,
|
||||||
enum libinput_event_type type,
|
enum libinput_event_type type,
|
||||||
union libinput_event_target target)
|
union libinput_event_target target)
|
||||||
{
|
{
|
||||||
event->type = type;
|
event->type = type;
|
||||||
event->libinput = libinput;
|
event->device = device;
|
||||||
event->target = target;
|
event->target = target;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
post_base_event(struct libinput *libinput,
|
post_base_event(struct libinput_device *device,
|
||||||
enum libinput_event_type type,
|
enum libinput_event_type type,
|
||||||
struct libinput_event *event)
|
struct libinput_event *event)
|
||||||
{
|
{
|
||||||
init_event_base(event, libinput, type,
|
struct libinput *libinput = device->seat->libinput;
|
||||||
|
init_event_base(event, device, type,
|
||||||
(union libinput_event_target) { .libinput = libinput });
|
(union libinput_event_target) { .libinput = libinput });
|
||||||
libinput_post_event(libinput, event);
|
libinput_post_event(libinput, event);
|
||||||
}
|
}
|
||||||
|
|
@ -608,7 +601,7 @@ post_device_event(struct libinput_device *device,
|
||||||
enum libinput_event_type type,
|
enum libinput_event_type type,
|
||||||
struct libinput_event *event)
|
struct libinput_event *event)
|
||||||
{
|
{
|
||||||
init_event_base(event, device->seat->libinput, type,
|
init_event_base(event, device, type,
|
||||||
(union libinput_event_target) { .device = device });
|
(union libinput_event_target) { .device = device });
|
||||||
libinput_post_event(device->seat->libinput, event);
|
libinput_post_event(device->seat->libinput, event);
|
||||||
}
|
}
|
||||||
|
|
@ -626,7 +619,7 @@ notify_added_device(struct libinput_device *device)
|
||||||
.device = device,
|
.device = device,
|
||||||
};
|
};
|
||||||
|
|
||||||
post_base_event(device->seat->libinput,
|
post_base_event(device,
|
||||||
LIBINPUT_EVENT_ADDED_DEVICE,
|
LIBINPUT_EVENT_ADDED_DEVICE,
|
||||||
&added_device_event->base);
|
&added_device_event->base);
|
||||||
}
|
}
|
||||||
|
|
@ -644,7 +637,7 @@ notify_removed_device(struct libinput_device *device)
|
||||||
.device = device,
|
.device = device,
|
||||||
};
|
};
|
||||||
|
|
||||||
post_base_event(device->seat->libinput,
|
post_base_event(device,
|
||||||
LIBINPUT_EVENT_REMOVED_DEVICE,
|
LIBINPUT_EVENT_REMOVED_DEVICE,
|
||||||
&removed_device_event->base);
|
&removed_device_event->base);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -248,20 +248,20 @@ struct libinput*
|
||||||
libinput_event_get_context(struct libinput_event *event);
|
libinput_event_get_context(struct libinput_event *event);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @defgroup event_added_device Added device event
|
* @ingroup event
|
||||||
|
*
|
||||||
|
* Return the device associated with this event, if applicable. For device
|
||||||
|
* added/removed events this is the device added or removed. For all other
|
||||||
|
* device events, this is the device that generated the event.
|
||||||
|
*
|
||||||
|
* This device is not refcounted and its lifetime is that of the event. Use
|
||||||
|
* libinput_device_ref() before using the device outside of this scope.
|
||||||
|
*
|
||||||
|
* @return The device associated with this event
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct libinput_device *
|
struct libinput_device*
|
||||||
libinput_event_added_device_get_device(
|
libinput_event_get_device(struct libinput_event *event);
|
||||||
struct libinput_event_added_device *event);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @defgroup event_removed_device Removed device event
|
|
||||||
*/
|
|
||||||
|
|
||||||
struct libinput_device *
|
|
||||||
libinput_event_removed_device_get_device(
|
|
||||||
struct libinput_event_removed_device *event);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @defgroup event_keyboard_key Keyboard key event
|
* @defgroup event_keyboard_key Keyboard key event
|
||||||
|
|
|
||||||
10
test/path.c
10
test/path.c
|
|
@ -134,7 +134,6 @@ START_TEST(path_added_seat)
|
||||||
struct litest_device *dev = litest_current_device();
|
struct litest_device *dev = litest_current_device();
|
||||||
struct libinput *li = dev->libinput;
|
struct libinput *li = dev->libinput;
|
||||||
struct libinput_event *event;
|
struct libinput_event *event;
|
||||||
struct libinput_event_added_device *device_event;
|
|
||||||
struct libinput_device *device;
|
struct libinput_device *device;
|
||||||
struct libinput_seat *seat;
|
struct libinput_seat *seat;
|
||||||
const char *seat_name;
|
const char *seat_name;
|
||||||
|
|
@ -148,8 +147,7 @@ START_TEST(path_added_seat)
|
||||||
type = libinput_event_get_type(event);
|
type = libinput_event_get_type(event);
|
||||||
ck_assert_int_eq(type, LIBINPUT_EVENT_ADDED_DEVICE);
|
ck_assert_int_eq(type, LIBINPUT_EVENT_ADDED_DEVICE);
|
||||||
|
|
||||||
device_event = (struct libinput_event_added_device*)event;
|
device = libinput_event_get_device(event);
|
||||||
device = libinput_event_added_device_get_device(device_event);
|
|
||||||
seat = libinput_device_get_seat(device);
|
seat = libinput_device_get_seat(device);
|
||||||
ck_assert(seat != NULL);
|
ck_assert(seat != NULL);
|
||||||
|
|
||||||
|
|
@ -165,7 +163,6 @@ START_TEST(path_added_device)
|
||||||
struct litest_device *dev = litest_current_device();
|
struct litest_device *dev = litest_current_device();
|
||||||
struct libinput *li = dev->libinput;
|
struct libinput *li = dev->libinput;
|
||||||
struct libinput_event *event;
|
struct libinput_event *event;
|
||||||
struct libinput_event_added_device *device_event = NULL;
|
|
||||||
struct libinput_device *device;
|
struct libinput_device *device;
|
||||||
|
|
||||||
libinput_dispatch(li);
|
libinput_dispatch(li);
|
||||||
|
|
@ -175,16 +172,15 @@ START_TEST(path_added_device)
|
||||||
type = libinput_event_get_type(event);
|
type = libinput_event_get_type(event);
|
||||||
|
|
||||||
if (type == LIBINPUT_EVENT_ADDED_DEVICE) {
|
if (type == LIBINPUT_EVENT_ADDED_DEVICE) {
|
||||||
device_event = (struct libinput_event_added_device*)event;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
libinput_event_destroy(event);
|
libinput_event_destroy(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
ck_assert(device_event != NULL);
|
ck_assert(event != NULL);
|
||||||
|
|
||||||
device = libinput_event_added_device_get_device(device_event);
|
device = libinput_event_get_device(event);
|
||||||
ck_assert(device != NULL);
|
ck_assert(device != NULL);
|
||||||
|
|
||||||
libinput_event_destroy(event);
|
libinput_event_destroy(event);
|
||||||
|
|
|
||||||
|
|
@ -138,7 +138,6 @@ START_TEST(udev_added_seat_default)
|
||||||
struct libinput *li;
|
struct libinput *li;
|
||||||
struct libinput_event *event;
|
struct libinput_event *event;
|
||||||
struct udev *udev;
|
struct udev *udev;
|
||||||
struct libinput_event_added_device *device_event;
|
|
||||||
struct libinput_device *device;
|
struct libinput_device *device;
|
||||||
struct libinput_seat *seat;
|
struct libinput_seat *seat;
|
||||||
const char *seat_name;
|
const char *seat_name;
|
||||||
|
|
@ -159,8 +158,7 @@ START_TEST(udev_added_seat_default)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
device_event = (struct libinput_event_added_device*)event;
|
device = libinput_event_get_device(event);
|
||||||
device = libinput_event_added_device_get_device(device_event);
|
|
||||||
seat = libinput_device_get_seat(device);
|
seat = libinput_device_get_seat(device);
|
||||||
ck_assert(seat != NULL);
|
ck_assert(seat != NULL);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue