From e5932867f1c939cf3deb3dd575fb61572b5d872e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Exp=C3=B3sito?= Date: Mon, 20 Sep 2021 19:47:07 +0200 Subject: [PATCH] backend/wayland: handle high-res scroll events Receive high-resolution scroll events from the parent compositor using a Wayland listiner and emit the appropiate wlr_pointer signal. --- backend/wayland/backend.c | 2 +- backend/wayland/seat.c | 43 +++++++++++++++++++++++++++++++-------- include/backend/wayland.h | 1 + 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/backend/wayland/backend.c b/backend/wayland/backend.c index c11d25ca9..da3ec2ea5 100644 --- a/backend/wayland/backend.c +++ b/backend/wayland/backend.c @@ -211,7 +211,7 @@ static void registry_global(void *data, struct wl_registry *registry, &wl_compositor_interface, 4); } else if (strcmp(iface, wl_seat_interface.name) == 0) { struct wl_seat *wl_seat = wl_registry_bind(registry, name, - &wl_seat_interface, 5); + &wl_seat_interface, version < 8 ? version : 8); if (!create_wl_seat(wl_seat, wl)) { wl_seat_destroy(wl_seat); } diff --git a/backend/wayland/seat.c b/backend/wayland/seat.c index 05524a7ed..bcbaecd99 100644 --- a/backend/wayland/seat.c +++ b/backend/wayland/seat.c @@ -129,15 +129,28 @@ static void pointer_handle_axis(void *data, struct wl_pointer *wl_pointer, return; } - struct wlr_event_pointer_axis event = { - .device = &pointer->input_device->wlr_input_device, - .delta = wl_fixed_to_double(value), - .delta_discrete = pointer->axis_discrete, - .orientation = axis, - .time_msec = time, - .source = pointer->axis_source, - }; - wlr_signal_emit_safe(&pointer->wlr_pointer.events.axis, &event); + uint32_t seat_version = wl_seat_get_version(seat->wl_seat); + if (seat_version >= WL_POINTER_AXIS_VALUE120_SINCE_VERSION) { + struct wlr_event_pointer_axis_value120 event = { + .device = &pointer->input_device->wlr_input_device, + .delta = wl_fixed_to_double(value), + .delta_value120 = pointer->axis_value120, + .orientation = axis, + .time_msec = time, + .source = pointer->axis_source, + }; + wlr_signal_emit_safe(&pointer->wlr_pointer.events.axis_value120, &event); + } else { + struct wlr_event_pointer_axis event = { + .device = &pointer->input_device->wlr_input_device, + .delta = wl_fixed_to_double(value), + .delta_discrete = pointer->axis_discrete, + .orientation = axis, + .time_msec = time, + .source = pointer->axis_source, + }; + wlr_signal_emit_safe(&pointer->wlr_pointer.events.axis, &event); + } pointer->axis_discrete = 0; } @@ -194,6 +207,17 @@ static void pointer_handle_axis_discrete(void *data, pointer->axis_discrete = discrete; } +static void pointer_handle_axis_value120(void *data, struct wl_pointer *wl_pointer, + uint32_t axis, int32_t value120) { + struct wlr_wl_seat *seat = data; + struct wlr_wl_pointer *pointer = seat->active_pointer; + if (pointer == NULL) { + return; + } + + pointer->axis_value120 = value120; +} + static const struct wl_pointer_listener pointer_listener = { .enter = pointer_handle_enter, .leave = pointer_handle_leave, @@ -204,6 +228,7 @@ static const struct wl_pointer_listener pointer_listener = { .axis_source = pointer_handle_axis_source, .axis_stop = pointer_handle_axis_stop, .axis_discrete = pointer_handle_axis_discrete, + .axis_value120 = pointer_handle_axis_value120, }; static void keyboard_handle_keymap(void *data, struct wl_keyboard *wl_keyboard, diff --git a/include/backend/wayland.h b/include/backend/wayland.h index 6f4fa201e..586e94a8d 100644 --- a/include/backend/wayland.h +++ b/include/backend/wayland.h @@ -101,6 +101,7 @@ struct wlr_wl_pointer { struct zwp_relative_pointer_v1 *relative_pointer; enum wlr_axis_source axis_source; int32_t axis_discrete; + int32_t axis_value120; struct wlr_wl_output *output; struct wl_listener output_destroy;