From d18b85c88ae1b4c89adca042a656d4be0342c436 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Exp=C3=B3sito?= Date: Mon, 20 Sep 2021 19:47:03 +0200 Subject: [PATCH] backend/libinput: handle high-res scroll events Receive high-resolution scroll events from libinput and emit the appropiate wlr_pointer signal. --- backend/libinput/events.c | 14 ++++++++++++ backend/libinput/pointer.c | 45 ++++++++++++++++++++++++++++++++++++++ include/backend/libinput.h | 6 +++++ 3 files changed, 65 insertions(+) diff --git a/backend/libinput/events.c b/backend/libinput/events.c index 66773a814..ce208eca0 100644 --- a/backend/libinput/events.c +++ b/backend/libinput/events.c @@ -262,6 +262,20 @@ void handle_libinput_event(struct wlr_libinput_backend *backend, handle_pointer_axis(event, libinput_dev); #endif break; +#if LIBINPUT_HAS_SCROLL_VALUE120 + case LIBINPUT_EVENT_POINTER_SCROLL_WHEEL: + handle_pointer_axis_value120(event, libinput_dev, + WLR_AXIS_SOURCE_WHEEL); + break; + case LIBINPUT_EVENT_POINTER_SCROLL_FINGER: + handle_pointer_axis_value120(event, libinput_dev, + WLR_AXIS_SOURCE_FINGER); + break; + case LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS: + handle_pointer_axis_value120(event, libinput_dev, + WLR_AXIS_SOURCE_CONTINUOUS); + break; +#endif case LIBINPUT_EVENT_TOUCH_DOWN: handle_touch_down(event, libinput_dev); break; diff --git a/backend/libinput/pointer.c b/backend/libinput/pointer.c index 2e799df63..a9a5df563 100644 --- a/backend/libinput/pointer.c +++ b/backend/libinput/pointer.c @@ -141,6 +141,51 @@ void handle_pointer_axis(struct libinput_event *event, wlr_signal_emit_safe(&wlr_dev->pointer->events.frame, wlr_dev->pointer); } +#if LIBINPUT_HAS_SCROLL_VALUE120 +void handle_pointer_axis_value120(struct libinput_event *event, + struct libinput_device *device, + enum wlr_axis_source source) { + struct wlr_input_device *wlr_dev = + get_appropriate_device(WLR_INPUT_DEVICE_POINTER, device); + if (!wlr_dev) { + wlr_log(WLR_DEBUG, "Got a pointer event for a device with no pointers?"); + return; + } + struct libinput_event_pointer *pevent = + libinput_event_get_pointer_event(event); + struct wlr_event_pointer_axis_value120 wlr_event = { 0 }; + wlr_event.device = wlr_dev; + wlr_event.time_msec = + usec_to_msec(libinput_event_pointer_get_time_usec(pevent)); + wlr_event.source = source; + + const enum libinput_pointer_axis axes[] = { + LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, + LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, + }; + for (size_t i = 0; i < sizeof(axes) / sizeof(axes[0]); ++i) { + if (libinput_event_pointer_has_axis(pevent, axes[i])) { + switch (axes[i]) { + case LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL: + wlr_event.orientation = WLR_AXIS_ORIENTATION_VERTICAL; + break; + case LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL: + wlr_event.orientation = WLR_AXIS_ORIENTATION_HORIZONTAL; + break; + } + wlr_event.delta = + libinput_event_pointer_get_scroll_value(pevent, axes[i]); + if (source == WLR_AXIS_SOURCE_WHEEL) { + wlr_event.delta_value120 = + libinput_event_pointer_get_scroll_value_v120(pevent, axes[i]); + } + wlr_signal_emit_safe(&wlr_dev->pointer->events.axis_value120, &wlr_event); + } + } + wlr_signal_emit_safe(&wlr_dev->pointer->events.frame, wlr_dev->pointer); +} +#endif + void handle_pointer_swipe_begin(struct libinput_event *event, struct libinput_device *libinput_dev) { struct wlr_input_device *wlr_dev = diff --git a/include/backend/libinput.h b/include/backend/libinput.h index 06e23a17a..142c0e3f4 100644 --- a/include/backend/libinput.h +++ b/include/backend/libinput.h @@ -7,6 +7,7 @@ #include #include #include +#include struct wlr_libinput_backend { struct wlr_backend backend; @@ -54,6 +55,11 @@ void handle_pointer_button(struct libinput_event *event, struct libinput_device *device); void handle_pointer_axis(struct libinput_event *event, struct libinput_device *device); +#if LIBINPUT_HAS_SCROLL_VALUE120 +void handle_pointer_axis_value120(struct libinput_event *event, + struct libinput_device *device, + enum wlr_axis_source source); +#endif void handle_pointer_swipe_begin(struct libinput_event *event, struct libinput_device *device); void handle_pointer_swipe_update(struct libinput_event *event,