6 static const struct ds_input_device_interface input_device_iface;
9 ds_input_device_is_libinput(struct ds_input_device *ds_dev)
11 return ds_dev->iface == &input_device_iface;
14 static struct ds_libinput_input_device *
15 get_libinput_input_device_from_input_device(struct ds_input_device *ds_dev)
17 assert(ds_input_device_is_libinput(ds_dev));
18 return (struct ds_libinput_input_device *)ds_dev;
22 input_device_iface_destroy(struct ds_input_device *ds_dev)
24 struct ds_libinput_input_device *dev;
26 dev = get_libinput_input_device_from_input_device(ds_dev);
31 static const struct ds_input_device_interface input_device_iface =
33 .destroy = input_device_iface_destroy,
36 static struct ds_keyboard *
39 struct ds_keyboard *kbd;
40 kbd = calloc(1, sizeof *kbd);
42 ds_err("Could not allocate memory");
45 ds_keyboard_init(kbd, NULL);
50 static struct ds_pointer *
53 struct ds_pointer *pointer;
54 pointer = calloc(1, sizeof *pointer);
56 ds_err("Could not allocate memory");
59 ds_pointer_init(pointer, NULL);
64 static struct ds_touch *
67 struct ds_touch *touch;
68 touch = calloc(1, sizeof *touch);
70 ds_err("Could not allocate memory");
73 ds_touch_init(touch, NULL);
79 handle_device_added(struct ds_libinput_backend *backend,
80 struct libinput_device *libinput_dev)
84 struct ds_libinput_input_device *dev;
86 vendor = libinput_device_get_id_vendor(libinput_dev);
87 product = libinput_device_get_id_product(libinput_dev);
88 name = libinput_device_get_name(libinput_dev);
89 ds_log(DS_DBG, "Adding %s [%d:%d]", name, vendor, product);
91 dev = calloc(1, sizeof(struct ds_libinput_input_device));
93 ds_log(DS_ERR, "failed to allocate ds_libinput_input_device");
97 dev->handle = libinput_dev;
98 dev->backend = backend;
99 libinput_device_ref(libinput_dev);
100 libinput_device_set_user_data(libinput_dev, dev);
102 wl_list_insert(&backend->devices, &dev->link);
104 if (libinput_device_has_capability(
105 libinput_dev, LIBINPUT_DEVICE_CAP_KEYBOARD)) {
106 ds_input_device_init(&dev->base, DS_INPUT_DEVICE_KEYBOARD,
107 &input_device_iface, name, vendor, product);
108 dev->base.keyboard = create_ds_keyboard();
110 wl_signal_emit(&backend->base.events.new_input,
114 if (libinput_device_has_capability(
115 libinput_dev, LIBINPUT_DEVICE_CAP_POINTER)) {
116 ds_input_device_init(&dev->base, DS_INPUT_DEVICE_POINTER,
117 &input_device_iface, name, vendor, product);
118 dev->base.pointer = create_ds_pointer();
120 wl_signal_emit(&backend->base.events.new_input,
124 if (libinput_device_has_capability(
125 libinput_dev, LIBINPUT_DEVICE_CAP_TOUCH)) {
126 ds_input_device_init(&dev->base, DS_INPUT_DEVICE_TOUCH,
127 &input_device_iface, name, vendor, product);
128 dev->base.touch = create_ds_touch();
130 wl_signal_emit(&backend->base.events.new_input,
136 handle_device_removed(struct ds_libinput_backend *backend,
137 struct libinput_device *libinput_dev)
141 struct ds_libinput_input_device *dev;
143 vendor = libinput_device_get_id_vendor(libinput_dev);
144 product = libinput_device_get_id_product(libinput_dev);
145 name = libinput_device_get_name(libinput_dev);
146 ds_log(DS_DBG, "Removing %s [%d:%d]", name, vendor, product);
148 dev = libinput_device_get_user_data(libinput_dev);
150 ds_log(DS_ERR, "libinput_device has no ds_libinput_input_device");
154 destroy_libinput_input_device(dev);
158 handle_libinput_event(struct ds_libinput_backend *backend,
159 struct libinput_event *event)
161 struct libinput_device *libinput_dev;
162 struct ds_libinput_input_device *dev;
163 enum libinput_event_type event_type;
165 libinput_dev = libinput_event_get_device(event);
166 event_type = libinput_event_get_type(event);
167 dev = libinput_device_get_user_data(libinput_dev);
169 switch (event_type) {
170 case LIBINPUT_EVENT_DEVICE_ADDED:
171 handle_device_added(backend, libinput_dev);
173 case LIBINPUT_EVENT_DEVICE_REMOVED:
174 handle_device_removed(backend, libinput_dev);
176 case LIBINPUT_EVENT_KEYBOARD_KEY:
177 handle_keyboard_key(event, dev->base.keyboard);
179 case LIBINPUT_EVENT_POINTER_MOTION:
180 handle_pointer_motion(event, dev->base.pointer);
182 case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
183 handle_pointer_motion_abs(event, dev->base.pointer);
185 case LIBINPUT_EVENT_POINTER_BUTTON:
186 handle_pointer_button(event, dev->base.pointer);
188 case LIBINPUT_EVENT_POINTER_AXIS:
189 handle_pointer_axis(event, dev->base.pointer);
191 case LIBINPUT_EVENT_TOUCH_DOWN:
192 handle_touch_down(event, dev->base.touch);
194 case LIBINPUT_EVENT_TOUCH_UP:
195 handle_touch_up(event, dev->base.touch);
197 case LIBINPUT_EVENT_TOUCH_MOTION:
198 handle_touch_motion(event, dev->base.touch);
200 case LIBINPUT_EVENT_TOUCH_CANCEL:
201 handle_touch_cancel(event, dev->base.touch);
203 case LIBINPUT_EVENT_TOUCH_FRAME:
204 handle_touch_frame(event, dev->base.touch);
207 ds_log(DS_DBG, "Unknown libinput event %d", event_type);