2022-02-24 20:53:54 +00:00
|
|
|
|
2017-06-09 21:31:21 +00:00
|
|
|
#include <libinput.h>
|
2018-02-12 20:29:23 +00:00
|
|
|
#include <stdlib.h>
|
2017-07-11 07:18:34 +00:00
|
|
|
#include <wlr/backend/session.h>
|
2022-02-24 20:53:54 +00:00
|
|
|
#include <wlr/interfaces/wlr_keyboard.h>
|
|
|
|
#include <wlr/interfaces/wlr_pointer.h>
|
|
|
|
#include <wlr/interfaces/wlr_touch.h>
|
|
|
|
#include <wlr/interfaces/wlr_tablet_tool.h>
|
|
|
|
#include <wlr/interfaces/wlr_tablet_pad.h>
|
|
|
|
#include <wlr/interfaces/wlr_switch.h>
|
2017-06-21 16:10:07 +00:00
|
|
|
#include <wlr/util/log.h>
|
2017-06-10 15:58:25 +00:00
|
|
|
#include "backend/libinput.h"
|
2017-06-09 21:31:21 +00:00
|
|
|
|
2022-02-24 20:53:54 +00:00
|
|
|
void destroy_libinput_input_device(struct wlr_libinput_input_device *dev) {
|
|
|
|
if (dev->keyboard.impl) {
|
2022-03-01 19:49:30 +00:00
|
|
|
wlr_keyboard_finish(&dev->keyboard);
|
2017-06-09 21:52:11 +00:00
|
|
|
}
|
2022-02-24 20:53:54 +00:00
|
|
|
if (dev->pointer.impl) {
|
2022-03-02 18:57:28 +00:00
|
|
|
wlr_pointer_finish(&dev->pointer);
|
2017-06-09 21:52:11 +00:00
|
|
|
}
|
2022-02-24 20:53:54 +00:00
|
|
|
if (dev->switch_device.impl) {
|
2022-03-02 19:17:31 +00:00
|
|
|
wlr_switch_finish(&dev->switch_device);
|
2022-02-24 20:53:54 +00:00
|
|
|
}
|
|
|
|
if (dev->touch.impl) {
|
2022-03-02 21:07:40 +00:00
|
|
|
wlr_touch_finish(&dev->touch);
|
2022-02-24 20:53:54 +00:00
|
|
|
}
|
|
|
|
if (dev->tablet.impl) {
|
2022-03-02 20:58:44 +00:00
|
|
|
finish_device_tablet(dev);
|
2022-02-24 20:53:54 +00:00
|
|
|
}
|
|
|
|
if (dev->tablet_pad.impl) {
|
2022-03-02 20:11:25 +00:00
|
|
|
finish_device_tablet_pad(dev);
|
2022-02-09 21:03:12 +00:00
|
|
|
}
|
|
|
|
|
2017-08-14 12:54:53 +00:00
|
|
|
libinput_device_unref(dev->handle);
|
2021-11-22 21:30:40 +00:00
|
|
|
wl_list_remove(&dev->link);
|
2017-08-14 12:54:53 +00:00
|
|
|
free(dev);
|
2017-06-10 16:21:54 +00:00
|
|
|
}
|
|
|
|
|
2017-12-19 18:46:30 +00:00
|
|
|
bool wlr_input_device_is_libinput(struct wlr_input_device *wlr_dev) {
|
2022-02-09 21:03:12 +00:00
|
|
|
switch (wlr_dev->type) {
|
|
|
|
case WLR_INPUT_DEVICE_KEYBOARD:
|
2022-06-20 14:57:29 +00:00
|
|
|
return wlr_keyboard_from_input_device(wlr_dev)->impl ==
|
|
|
|
&libinput_keyboard_impl;
|
2022-02-09 21:03:12 +00:00
|
|
|
case WLR_INPUT_DEVICE_POINTER:
|
2022-06-20 14:57:29 +00:00
|
|
|
return wlr_pointer_from_input_device(wlr_dev)->impl ==
|
|
|
|
&libinput_pointer_impl;
|
2022-02-09 21:03:12 +00:00
|
|
|
case WLR_INPUT_DEVICE_TOUCH:
|
2022-06-20 14:57:29 +00:00
|
|
|
return wlr_touch_from_input_device(wlr_dev)->impl ==
|
|
|
|
&libinput_touch_impl;
|
2024-02-29 12:31:00 +00:00
|
|
|
case WLR_INPUT_DEVICE_TABLET:
|
2022-06-20 14:57:29 +00:00
|
|
|
return wlr_tablet_from_input_device(wlr_dev)-> impl ==
|
|
|
|
&libinput_tablet_impl;
|
2022-02-09 21:03:12 +00:00
|
|
|
case WLR_INPUT_DEVICE_TABLET_PAD:
|
2022-06-20 14:57:29 +00:00
|
|
|
return wlr_tablet_pad_from_input_device(wlr_dev)->impl ==
|
|
|
|
&libinput_tablet_pad_impl;
|
2022-02-09 21:03:12 +00:00
|
|
|
case WLR_INPUT_DEVICE_SWITCH:
|
2022-06-20 14:57:29 +00:00
|
|
|
return wlr_switch_from_input_device(wlr_dev)->impl ==
|
|
|
|
&libinput_switch_impl;
|
2022-02-09 21:03:12 +00:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
2017-12-19 18:46:30 +00:00
|
|
|
}
|
|
|
|
|
2017-08-12 17:51:47 +00:00
|
|
|
static void handle_device_added(struct wlr_libinput_backend *backend,
|
2017-08-12 22:50:09 +00:00
|
|
|
struct libinput_device *libinput_dev) {
|
|
|
|
int vendor = libinput_device_get_id_vendor(libinput_dev);
|
|
|
|
int product = libinput_device_get_id_product(libinput_dev);
|
|
|
|
const char *name = libinput_device_get_name(libinput_dev);
|
2022-02-24 20:53:54 +00:00
|
|
|
wlr_log(WLR_DEBUG, "Adding %s [%d:%d]", name, vendor, product);
|
2022-02-23 15:42:20 +00:00
|
|
|
|
2023-10-03 05:51:07 +00:00
|
|
|
struct wlr_libinput_input_device *dev = calloc(1, sizeof(*dev));
|
2022-02-23 15:42:20 +00:00
|
|
|
if (dev == NULL) {
|
|
|
|
wlr_log_errno(WLR_ERROR, "failed to allocate wlr_libinput_input_device");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dev->handle = libinput_dev;
|
|
|
|
libinput_device_ref(libinput_dev);
|
|
|
|
libinput_device_set_user_data(libinput_dev, dev);
|
|
|
|
|
2022-02-24 20:53:54 +00:00
|
|
|
wl_list_insert(&backend->devices, &dev->link);
|
2022-02-23 15:42:20 +00:00
|
|
|
|
|
|
|
if (libinput_device_has_capability(
|
|
|
|
libinput_dev, LIBINPUT_DEVICE_CAP_KEYBOARD)) {
|
|
|
|
init_device_keyboard(dev);
|
|
|
|
|
2022-08-18 11:16:16 +00:00
|
|
|
wl_signal_emit_mutable(&backend->backend.events.new_input,
|
2022-02-23 15:42:20 +00:00
|
|
|
&dev->keyboard.base);
|
|
|
|
}
|
|
|
|
|
2022-02-28 16:57:35 +00:00
|
|
|
if (libinput_device_has_capability(
|
|
|
|
libinput_dev, LIBINPUT_DEVICE_CAP_POINTER)) {
|
|
|
|
init_device_pointer(dev);
|
|
|
|
|
2022-08-18 11:16:16 +00:00
|
|
|
wl_signal_emit_mutable(&backend->backend.events.new_input,
|
2022-02-28 16:57:35 +00:00
|
|
|
&dev->pointer.base);
|
|
|
|
}
|
2022-02-23 15:42:20 +00:00
|
|
|
|
2022-02-23 18:41:34 +00:00
|
|
|
if (libinput_device_has_capability(
|
|
|
|
libinput_dev, LIBINPUT_DEVICE_CAP_SWITCH)) {
|
|
|
|
init_device_switch(dev);
|
2022-08-18 11:16:16 +00:00
|
|
|
wl_signal_emit_mutable(&backend->backend.events.new_input,
|
2022-02-23 18:41:34 +00:00
|
|
|
&dev->switch_device.base);
|
|
|
|
}
|
|
|
|
|
2022-02-23 19:06:02 +00:00
|
|
|
if (libinput_device_has_capability(
|
|
|
|
libinput_dev, LIBINPUT_DEVICE_CAP_TOUCH)) {
|
|
|
|
init_device_touch(dev);
|
2022-08-18 11:16:16 +00:00
|
|
|
wl_signal_emit_mutable(&backend->backend.events.new_input,
|
2022-02-23 19:06:02 +00:00
|
|
|
&dev->touch.base);
|
|
|
|
}
|
|
|
|
|
2022-02-24 16:00:11 +00:00
|
|
|
if (libinput_device_has_capability(libinput_dev,
|
|
|
|
LIBINPUT_DEVICE_CAP_TABLET_TOOL)) {
|
|
|
|
init_device_tablet(dev);
|
2022-08-18 11:16:16 +00:00
|
|
|
wl_signal_emit_mutable(&backend->backend.events.new_input,
|
2022-02-24 16:00:11 +00:00
|
|
|
&dev->tablet.base);
|
|
|
|
}
|
|
|
|
|
2022-02-24 20:30:26 +00:00
|
|
|
if (libinput_device_has_capability(
|
|
|
|
libinput_dev, LIBINPUT_DEVICE_CAP_TABLET_PAD)) {
|
|
|
|
init_device_tablet_pad(dev);
|
2022-08-18 11:16:16 +00:00
|
|
|
wl_signal_emit_mutable(&backend->backend.events.new_input,
|
2022-02-24 20:30:26 +00:00
|
|
|
&dev->tablet_pad.base);
|
2022-02-23 15:42:20 +00:00
|
|
|
}
|
|
|
|
|
2018-09-17 19:53:03 +00:00
|
|
|
if (libinput_device_has_capability(
|
|
|
|
libinput_dev, LIBINPUT_DEVICE_CAP_GESTURE)) {
|
2022-02-24 20:53:54 +00:00
|
|
|
wlr_log(WLR_DEBUG, "libinput gesture not handled");
|
2017-10-14 16:17:43 +00:00
|
|
|
}
|
2017-06-09 21:31:21 +00:00
|
|
|
}
|
|
|
|
|
2017-08-12 17:51:47 +00:00
|
|
|
static void handle_device_removed(struct wlr_libinput_backend *backend,
|
2022-09-17 19:18:42 +00:00
|
|
|
struct wlr_libinput_input_device *dev) {
|
|
|
|
int vendor = libinput_device_get_id_vendor(dev->handle);
|
|
|
|
int product = libinput_device_get_id_product(dev->handle);
|
|
|
|
const char *name = libinput_device_get_name(dev->handle);
|
2018-07-09 21:49:54 +00:00
|
|
|
wlr_log(WLR_DEBUG, "Removing %s [%d:%d]", name, vendor, product);
|
2022-02-22 21:17:48 +00:00
|
|
|
|
2022-02-24 20:53:54 +00:00
|
|
|
destroy_libinput_input_device(dev);
|
2017-06-09 21:31:21 +00:00
|
|
|
}
|
|
|
|
|
2018-04-25 22:24:58 +00:00
|
|
|
void handle_libinput_event(struct wlr_libinput_backend *backend,
|
2017-06-09 21:31:21 +00:00
|
|
|
struct libinput_event *event) {
|
2017-08-12 22:50:09 +00:00
|
|
|
struct libinput_device *libinput_dev = libinput_event_get_device(event);
|
2022-02-23 15:42:20 +00:00
|
|
|
struct wlr_libinput_input_device *dev =
|
|
|
|
libinput_device_get_user_data(libinput_dev);
|
2017-06-09 21:31:21 +00:00
|
|
|
enum libinput_event_type event_type = libinput_event_get_type(event);
|
2022-09-17 19:18:42 +00:00
|
|
|
|
|
|
|
if (dev == NULL && event_type != LIBINPUT_EVENT_DEVICE_ADDED) {
|
|
|
|
wlr_log(WLR_ERROR, "libinput_device has no wlr_libinput_input_device");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-09 21:31:21 +00:00
|
|
|
switch (event_type) {
|
|
|
|
case LIBINPUT_EVENT_DEVICE_ADDED:
|
2017-08-12 22:50:09 +00:00
|
|
|
handle_device_added(backend, libinput_dev);
|
2017-06-09 21:31:21 +00:00
|
|
|
break;
|
|
|
|
case LIBINPUT_EVENT_DEVICE_REMOVED:
|
2022-09-17 19:18:42 +00:00
|
|
|
handle_device_removed(backend, dev);
|
2017-06-09 21:52:11 +00:00
|
|
|
break;
|
|
|
|
case LIBINPUT_EVENT_KEYBOARD_KEY:
|
2022-02-23 15:42:20 +00:00
|
|
|
handle_keyboard_key(event, &dev->keyboard);
|
2017-06-09 21:31:21 +00:00
|
|
|
break;
|
2017-06-13 14:27:15 +00:00
|
|
|
case LIBINPUT_EVENT_POINTER_MOTION:
|
2022-02-28 16:57:35 +00:00
|
|
|
handle_pointer_motion(event, &dev->pointer);
|
2017-06-13 14:27:15 +00:00
|
|
|
break;
|
|
|
|
case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
|
2022-02-28 16:57:35 +00:00
|
|
|
handle_pointer_motion_abs(event, &dev->pointer);
|
2017-06-13 14:27:15 +00:00
|
|
|
break;
|
|
|
|
case LIBINPUT_EVENT_POINTER_BUTTON:
|
2022-02-28 16:57:35 +00:00
|
|
|
handle_pointer_button(event, &dev->pointer);
|
2017-06-13 14:27:15 +00:00
|
|
|
break;
|
|
|
|
case LIBINPUT_EVENT_POINTER_AXIS:
|
2022-11-25 17:15:31 +00:00
|
|
|
#if !HAVE_LIBINPUT_SCROLL_VALUE120
|
2022-02-25 16:30:42 +00:00
|
|
|
/* This event must be ignored in favour of the SCROLL_* events */
|
2022-02-28 16:57:35 +00:00
|
|
|
handle_pointer_axis(event, &dev->pointer);
|
2022-02-25 16:30:42 +00:00
|
|
|
#endif
|
2017-06-13 14:27:15 +00:00
|
|
|
break;
|
2022-11-25 17:15:31 +00:00
|
|
|
#if HAVE_LIBINPUT_SCROLL_VALUE120
|
2022-02-25 16:30:42 +00:00
|
|
|
case LIBINPUT_EVENT_POINTER_SCROLL_WHEEL:
|
|
|
|
handle_pointer_axis_value120(event, &dev->pointer,
|
2024-02-28 09:15:13 +00:00
|
|
|
WL_POINTER_AXIS_SOURCE_WHEEL);
|
2022-02-25 16:30:42 +00:00
|
|
|
break;
|
|
|
|
case LIBINPUT_EVENT_POINTER_SCROLL_FINGER:
|
|
|
|
handle_pointer_axis_value120(event, &dev->pointer,
|
2024-02-28 09:15:13 +00:00
|
|
|
WL_POINTER_AXIS_SOURCE_FINGER);
|
2022-02-25 16:30:42 +00:00
|
|
|
break;
|
|
|
|
case LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS:
|
|
|
|
handle_pointer_axis_value120(event, &dev->pointer,
|
2024-02-28 09:15:13 +00:00
|
|
|
WL_POINTER_AXIS_SOURCE_CONTINUOUS);
|
2022-02-25 16:30:42 +00:00
|
|
|
break;
|
|
|
|
#endif
|
2017-06-14 18:50:09 +00:00
|
|
|
case LIBINPUT_EVENT_TOUCH_DOWN:
|
2022-02-23 19:06:02 +00:00
|
|
|
handle_touch_down(event, &dev->touch);
|
2017-06-14 18:50:09 +00:00
|
|
|
break;
|
|
|
|
case LIBINPUT_EVENT_TOUCH_UP:
|
2022-02-23 19:06:02 +00:00
|
|
|
handle_touch_up(event, &dev->touch);
|
2017-06-14 18:50:09 +00:00
|
|
|
break;
|
|
|
|
case LIBINPUT_EVENT_TOUCH_MOTION:
|
2022-02-23 19:06:02 +00:00
|
|
|
handle_touch_motion(event, &dev->touch);
|
2017-06-14 18:50:09 +00:00
|
|
|
break;
|
|
|
|
case LIBINPUT_EVENT_TOUCH_CANCEL:
|
2022-02-23 19:06:02 +00:00
|
|
|
handle_touch_cancel(event, &dev->touch);
|
2017-06-14 18:50:09 +00:00
|
|
|
break;
|
|
|
|
case LIBINPUT_EVENT_TOUCH_FRAME:
|
2022-02-23 19:06:02 +00:00
|
|
|
handle_touch_frame(event, &dev->touch);
|
2017-06-14 18:50:09 +00:00
|
|
|
break;
|
2017-06-15 18:32:28 +00:00
|
|
|
case LIBINPUT_EVENT_TABLET_TOOL_AXIS:
|
2022-02-24 16:00:11 +00:00
|
|
|
handle_tablet_tool_axis(event, &dev->tablet);
|
2017-06-15 18:32:28 +00:00
|
|
|
break;
|
|
|
|
case LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY:
|
2022-02-24 16:00:11 +00:00
|
|
|
handle_tablet_tool_proximity(event, &dev->tablet);
|
2017-06-15 18:32:28 +00:00
|
|
|
break;
|
|
|
|
case LIBINPUT_EVENT_TABLET_TOOL_TIP:
|
2022-02-24 16:00:11 +00:00
|
|
|
handle_tablet_tool_tip(event, &dev->tablet);
|
2017-06-15 18:32:28 +00:00
|
|
|
break;
|
|
|
|
case LIBINPUT_EVENT_TABLET_TOOL_BUTTON:
|
2022-02-24 16:00:11 +00:00
|
|
|
handle_tablet_tool_button(event, &dev->tablet);
|
2017-06-15 18:32:28 +00:00
|
|
|
break;
|
2017-06-19 18:49:07 +00:00
|
|
|
case LIBINPUT_EVENT_TABLET_PAD_BUTTON:
|
2022-02-24 20:30:26 +00:00
|
|
|
handle_tablet_pad_button(event, &dev->tablet_pad);
|
2017-06-19 18:49:07 +00:00
|
|
|
break;
|
|
|
|
case LIBINPUT_EVENT_TABLET_PAD_RING:
|
2022-02-24 20:30:26 +00:00
|
|
|
handle_tablet_pad_ring(event, &dev->tablet_pad);
|
2017-06-19 18:49:07 +00:00
|
|
|
break;
|
|
|
|
case LIBINPUT_EVENT_TABLET_PAD_STRIP:
|
2022-02-24 20:30:26 +00:00
|
|
|
handle_tablet_pad_strip(event, &dev->tablet_pad);
|
2017-06-19 18:49:07 +00:00
|
|
|
break;
|
2018-11-14 23:24:55 +00:00
|
|
|
case LIBINPUT_EVENT_SWITCH_TOGGLE:
|
2022-02-23 18:41:34 +00:00
|
|
|
handle_switch_toggle(event, &dev->switch_device);
|
2018-11-14 23:24:55 +00:00
|
|
|
break;
|
2019-01-25 22:51:38 +00:00
|
|
|
case LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN:
|
2022-02-28 16:57:35 +00:00
|
|
|
handle_pointer_swipe_begin(event, &dev->pointer);
|
2019-01-25 22:51:38 +00:00
|
|
|
break;
|
|
|
|
case LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE:
|
2022-02-28 16:57:35 +00:00
|
|
|
handle_pointer_swipe_update(event, &dev->pointer);
|
2019-01-25 22:51:38 +00:00
|
|
|
break;
|
|
|
|
case LIBINPUT_EVENT_GESTURE_SWIPE_END:
|
2022-02-28 16:57:35 +00:00
|
|
|
handle_pointer_swipe_end(event, &dev->pointer);
|
2019-01-25 22:51:38 +00:00
|
|
|
break;
|
|
|
|
case LIBINPUT_EVENT_GESTURE_PINCH_BEGIN:
|
2022-02-28 16:57:35 +00:00
|
|
|
handle_pointer_pinch_begin(event, &dev->pointer);
|
2019-01-25 22:51:38 +00:00
|
|
|
break;
|
|
|
|
case LIBINPUT_EVENT_GESTURE_PINCH_UPDATE:
|
2022-02-28 16:57:35 +00:00
|
|
|
handle_pointer_pinch_update(event, &dev->pointer);
|
2019-01-25 22:51:38 +00:00
|
|
|
break;
|
|
|
|
case LIBINPUT_EVENT_GESTURE_PINCH_END:
|
2022-02-28 16:57:35 +00:00
|
|
|
handle_pointer_pinch_end(event, &dev->pointer);
|
2019-01-25 22:51:38 +00:00
|
|
|
break;
|
2022-11-25 17:15:31 +00:00
|
|
|
#if HAVE_LIBINPUT_HOLD_GESTURES
|
2021-07-12 17:50:44 +00:00
|
|
|
case LIBINPUT_EVENT_GESTURE_HOLD_BEGIN:
|
2022-02-28 16:57:35 +00:00
|
|
|
handle_pointer_hold_begin(event, &dev->pointer);
|
2021-07-12 17:50:44 +00:00
|
|
|
break;
|
|
|
|
case LIBINPUT_EVENT_GESTURE_HOLD_END:
|
2022-02-28 16:57:35 +00:00
|
|
|
handle_pointer_hold_end(event, &dev->pointer);
|
2021-07-12 17:50:44 +00:00
|
|
|
break;
|
|
|
|
#endif
|
2017-06-09 21:31:21 +00:00
|
|
|
default:
|
2018-07-09 21:49:54 +00:00
|
|
|
wlr_log(WLR_DEBUG, "Unknown libinput event %d", event_type);
|
2017-06-09 21:31:21 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|