{
if ((device->caps & (EVDEV_MOTION_ABS | EVDEV_MOTION_REL)) &&
(device->caps & EVDEV_BUTTON)) {
- device->base.device_interface->register_capability(
- LIBINPUT_DEVICE_CAP_POINTER,
- device->base.device_interface_data);
+ device_register_capability(&device->base,
+ LIBINPUT_DEVICE_CAP_POINTER);
device->seat_caps |= EVDEV_DEVICE_POINTER;
}
if ((device->caps & EVDEV_KEYBOARD)) {
- device->base.device_interface->register_capability(
- LIBINPUT_DEVICE_CAP_KEYBOARD,
- device->base.device_interface_data);
+ device_register_capability(&device->base,
+ LIBINPUT_DEVICE_CAP_KEYBOARD);
device->seat_caps |= EVDEV_DEVICE_KEYBOARD;
}
if ((device->caps & EVDEV_TOUCH)) {
- device->base.device_interface->register_capability(
- LIBINPUT_DEVICE_CAP_TOUCH,
- device->base.device_interface_data);
+ device_register_capability(&device->base,
+ LIBINPUT_DEVICE_CAP_TOUCH);
device->seat_caps |= EVDEV_DEVICE_TOUCH;
}
}
void
-evdev_device_destroy(struct evdev_device *device)
+evdev_device_terminate(struct evdev_device *device)
{
- struct evdev_dispatch *dispatch;
-
if (device->seat_caps & EVDEV_DEVICE_POINTER) {
- device->base.device_interface->unregister_capability(
- LIBINPUT_DEVICE_CAP_POINTER,
- device->base.device_interface_data);
+ device_unregister_capability(&device->base,
+ LIBINPUT_DEVICE_CAP_POINTER);
}
if (device->seat_caps & EVDEV_DEVICE_KEYBOARD) {
- device->base.device_interface->unregister_capability(
- LIBINPUT_DEVICE_CAP_KEYBOARD,
- device->base.device_interface_data);
+ device_unregister_capability(&device->base,
+ LIBINPUT_DEVICE_CAP_KEYBOARD);
}
if (device->seat_caps & EVDEV_DEVICE_TOUCH) {
- device->base.device_interface->unregister_capability(
- LIBINPUT_DEVICE_CAP_TOUCH,
- device->base.device_interface_data);
+ device_unregister_capability(&device->base,
+ LIBINPUT_DEVICE_CAP_TOUCH);
}
+}
+
+void
+evdev_device_destroy(struct evdev_device *device)
+{
+ struct evdev_dispatch *dispatch;
dispatch = device->dispatch;
if (dispatch)
void
evdev_device_calibrate(struct evdev_device *device, float calibration[6]);
+void
+evdev_device_terminate(struct evdev_device *terminate);
+
void
evdev_device_destroy(struct evdev_device *device);
struct libinput *libinput;
const struct libinput_device_interface *device_interface;
void *device_interface_data;
+ int terminated;
};
typedef void (*libinput_source_dispatch_t)(void *data);
libinput_post_event(struct libinput *libinput,
struct libinput_event *event);
+void
+device_register_capability(struct libinput_device *device,
+ enum libinput_device_capability capability);
+
+void
+device_unregister_capability(struct libinput_device *device,
+ enum libinput_device_capability capability);
+
void
keyboard_notify_key(struct libinput_device *device,
uint32_t time,
#include <string.h>
#include <sys/epoll.h>
#include <unistd.h>
+#include <assert.h>
#include "libinput.h"
#include "evdev.h"
libinput_post_event(device->libinput, event);
}
+void
+device_register_capability(struct libinput_device *device,
+ enum libinput_device_capability capability)
+{
+ struct libinput_event_device_register_capability *capability_event;
+
+ capability_event = malloc(sizeof *capability_event);
+
+ *capability_event = (struct libinput_event_device_register_capability) {
+ .capability = capability,
+ };
+
+ post_device_event(device,
+ LIBINPUT_EVENT_DEVICE_REGISTER_CAPABILITY,
+ &capability_event->base);
+}
+
+void
+device_unregister_capability(struct libinput_device *device,
+ enum libinput_device_capability capability)
+{
+ struct libinput_event_device_unregister_capability *capability_event;
+
+ capability_event = malloc(sizeof *capability_event);
+
+ *capability_event = (struct libinput_event_device_unregister_capability) {
+ .capability = capability,
+ };
+
+ post_device_event(device,
+ LIBINPUT_EVENT_DEVICE_UNREGISTER_CAPABILITY,
+ &capability_event->base);
+}
+
void
keyboard_notify_key(struct libinput_device *device,
uint32_t time,
return event;
}
+LIBINPUT_EXPORT void
+libinput_device_terminate(struct libinput_device *device)
+{
+ evdev_device_terminate((struct evdev_device *) device);
+ device->terminated = 1;
+}
+
LIBINPUT_EXPORT void
libinput_device_destroy(struct libinput_device *device)
{
+ assert(device->terminated);
evdev_device_destroy((struct evdev_device *) device);
}
};
enum libinput_event_type {
+ LIBINPUT_EVENT_DEVICE_REGISTER_CAPABILITY = 200,
+ LIBINPUT_EVENT_DEVICE_UNREGISTER_CAPABILITY,
LIBINPUT_EVENT_KEYBOARD_KEY = 300,
struct libinput_device *device;
};
+struct libinput_event_device_register_capability {
+ struct libinput_event base;
+ enum libinput_device_capability capability;
+};
+
+struct libinput_event_device_unregister_capability {
+ struct libinput_event base;
+ enum libinput_device_capability capability;
+};
+
struct libinput_event_keyboard_key {
struct libinput_event base;
uint32_t time;
typedef void (*libinput_fd_callback)(int fd, void *data);
struct libinput_device_interface {
- /* */
- void (*register_capability)(enum libinput_device_capability capability,
- void *data);
- void (*unregister_capability)(enum libinput_device_capability capability,
- void *data);
-
- /* */
void (*get_current_screen_dimensions)(int *width,
int *height,
void *data);
const struct libinput_device_interface *interface,
void *user_data);
+void
+libinput_device_terminate(struct libinput_device *device);
+
void
libinput_device_destroy(struct libinput_device *device);