diff options
author | José Expósito <jose.exposito89@gmail.com> | 2022-02-25 17:30:42 +0100 |
---|---|---|
committer | José Expósito <jose.exposito89@gmail.com> | 2022-07-11 11:01:35 +0200 |
commit | c6032d6b1cc1cfb884924bb8afbdd200c3258d9a (patch) | |
tree | 2a497c181b1aec9801cf2ca42b41954b349fedfa | |
parent | 65c436407f37118618b348b9b7303b55322d66a2 (diff) |
backend/libinput: handle high-res scroll events
On newer versions of libinput, the event LIBINPUT_EVENT_POINTER_AXIS
has been deprecated in favour of LIBINPUT_EVENT_POINTER_SCROLL_WHEEL,
LIBINPUT_EVENT_POINTER_SCROLL_FINGER and
LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS.
Where new events are provided by the backend, ignore
LIBINPUT_EVENT_POINTER_AXIS, receive high-resolution scroll events from
libinput and emit the appropiate wlr_pointer signal.
-rw-r--r-- | backend/libinput/events.c | 17 | ||||
-rw-r--r-- | backend/libinput/pointer.c | 39 | ||||
-rw-r--r-- | include/backend/libinput.h | 4 |
3 files changed, 60 insertions, 0 deletions
diff --git a/backend/libinput/events.c b/backend/libinput/events.c index b9f2f43c..c5d9c67a 100644 --- a/backend/libinput/events.c +++ b/backend/libinput/events.c @@ -176,8 +176,25 @@ void handle_libinput_event(struct wlr_libinput_backend *backend, handle_pointer_button(event, &dev->pointer); break; case LIBINPUT_EVENT_POINTER_AXIS: +#if !LIBINPUT_HAS_SCROLL_VALUE120 + /* This event must be ignored in favour of the SCROLL_* events */ handle_pointer_axis(event, &dev->pointer); +#endif + break; +#if LIBINPUT_HAS_SCROLL_VALUE120 + case LIBINPUT_EVENT_POINTER_SCROLL_WHEEL: + handle_pointer_axis_value120(event, &dev->pointer, + WLR_AXIS_SOURCE_WHEEL); + break; + case LIBINPUT_EVENT_POINTER_SCROLL_FINGER: + handle_pointer_axis_value120(event, &dev->pointer, + WLR_AXIS_SOURCE_FINGER); break; + case LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS: + handle_pointer_axis_value120(event, &dev->pointer, + WLR_AXIS_SOURCE_CONTINUOUS); + break; +#endif case LIBINPUT_EVENT_TOUCH_DOWN: handle_touch_down(event, &dev->touch); break; diff --git a/backend/libinput/pointer.c b/backend/libinput/pointer.c index b391b0e5..50b63c90 100644 --- a/backend/libinput/pointer.c +++ b/backend/libinput/pointer.c @@ -123,6 +123,45 @@ void handle_pointer_axis(struct libinput_event *event, wlr_signal_emit_safe(&pointer->events.frame, pointer); } +#if LIBINPUT_HAS_SCROLL_VALUE120 +void handle_pointer_axis_value120(struct libinput_event *event, + struct wlr_pointer *pointer, enum wlr_axis_source source) { + struct libinput_event_pointer *pevent = + libinput_event_get_pointer_event(event); + struct wlr_pointer_axis_event wlr_event = { 0 }; + wlr_event.pointer = pointer; + 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])) { + continue; + } + 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_discrete = + libinput_event_pointer_get_scroll_value_v120(pevent, axes[i]); + } + wlr_signal_emit_safe(&pointer->events.axis, &wlr_event); + } + wlr_signal_emit_safe(&pointer->events.frame, pointer); +} +#endif + void handle_pointer_swipe_begin(struct libinput_event *event, struct wlr_pointer *pointer) { struct libinput_event_gesture *gevent = diff --git a/include/backend/libinput.h b/include/backend/libinput.h index 7c1dc30a..1ec94c2d 100644 --- a/include/backend/libinput.h +++ b/include/backend/libinput.h @@ -70,6 +70,10 @@ void handle_pointer_button(struct libinput_event *event, struct wlr_pointer *pointer); void handle_pointer_axis(struct libinput_event *event, struct wlr_pointer *pointer); +#if LIBINPUT_HAS_SCROLL_VALUE120 +void handle_pointer_axis_value120(struct libinput_event *event, + struct wlr_pointer *pointer, enum wlr_axis_source source); +#endif void handle_pointer_swipe_begin(struct libinput_event *event, struct wlr_pointer *pointer); void handle_pointer_swipe_update(struct libinput_event *event, |