struct libinput_event {
enum libinput_event_type type;
- struct libinput *libinput;
+ struct libinput_device *device;
union libinput_event_target target;
};
LIBINPUT_EXPORT struct libinput*
libinput_event_get_context(struct libinput_event *event)
{
- return event->libinput;
-}
-
-LIBINPUT_EXPORT struct libinput_device *
-libinput_event_added_device_get_device(
- struct libinput_event_added_device *event)
-{
- return event->device;
+ return event->device->seat->libinput;
}
-LIBINPUT_EXPORT struct libinput_device *
-libinput_event_removed_device_get_device(
- struct libinput_event_removed_device *event)
+LIBINPUT_EXPORT struct libinput_device*
+libinput_event_get_device(struct libinput_event *event)
{
return event->device;
}
static void
init_event_base(struct libinput_event *event,
- struct libinput *libinput,
+ struct libinput_device *device,
enum libinput_event_type type,
union libinput_event_target target)
{
event->type = type;
- event->libinput = libinput;
+ event->device = device;
event->target = target;
}
static void
-post_base_event(struct libinput *libinput,
+post_base_event(struct libinput_device *device,
enum libinput_event_type type,
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 });
libinput_post_event(libinput, event);
}
enum libinput_event_type type,
struct libinput_event *event)
{
- init_event_base(event, device->seat->libinput, type,
+ init_event_base(event, device, type,
(union libinput_event_target) { .device = device });
libinput_post_event(device->seat->libinput, event);
}
.device = device,
};
- post_base_event(device->seat->libinput,
+ post_base_event(device,
LIBINPUT_EVENT_ADDED_DEVICE,
&added_device_event->base);
}
.device = device,
};
- post_base_event(device->seat->libinput,
+ post_base_event(device,
LIBINPUT_EVENT_REMOVED_DEVICE,
&removed_device_event->base);
}
libinput_event_get_context(struct libinput_event *event);
/**
- * @defgroup event_added_device Added device event
- */
-
-struct libinput_device *
-libinput_event_added_device_get_device(
- struct libinput_event_added_device *event);
-
-/**
- * @defgroup event_removed_device Removed 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 *
-libinput_event_removed_device_get_device(
- struct libinput_event_removed_device *event);
+struct libinput_device*
+libinput_event_get_device(struct libinput_event *event);
/**
* @defgroup event_keyboard_key Keyboard key event
struct litest_device *dev = litest_current_device();
struct libinput *li = dev->libinput;
struct libinput_event *event;
- struct libinput_event_added_device *device_event;
struct libinput_device *device;
struct libinput_seat *seat;
const char *seat_name;
type = libinput_event_get_type(event);
ck_assert_int_eq(type, LIBINPUT_EVENT_ADDED_DEVICE);
- device_event = (struct libinput_event_added_device*)event;
- device = libinput_event_added_device_get_device(device_event);
+ device = libinput_event_get_device(event);
seat = libinput_device_get_seat(device);
ck_assert(seat != NULL);
struct litest_device *dev = litest_current_device();
struct libinput *li = dev->libinput;
struct libinput_event *event;
- struct libinput_event_added_device *device_event = NULL;
struct libinput_device *device;
libinput_dispatch(li);
type = libinput_event_get_type(event);
if (type == LIBINPUT_EVENT_ADDED_DEVICE) {
- device_event = (struct libinput_event_added_device*)event;
break;
}
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);
libinput_event_destroy(event);