From 25ab8c8b9ccfa1b293ea191f12f4a5b29aba3fe0 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Wed, 27 Jan 2021 19:42:32 +0100 Subject: [PATCH] Added wayland discrete axis events for mouse wheel the discrete axis event gives changes in steps just like the xfreerdp version uses. This way scrolling can be implemented consistent with the behaviour of xfreerdp --- client/Wayland/wlf_input.c | 23 ++++++++++------------- client/Wayland/wlfreerdp.c | 3 +++ uwac/include/uwac/uwac.h | 1 + uwac/libuwac/uwac-input.c | 18 ++++++++++++++++++ 4 files changed, 32 insertions(+), 13 deletions(-) diff --git a/client/Wayland/wlf_input.c b/client/Wayland/wlf_input.c index 6ca9c982b..b18ec429f 100644 --- a/client/Wayland/wlf_input.c +++ b/client/Wayland/wlf_input.c @@ -137,9 +137,9 @@ BOOL wlf_handle_pointer_axis(freerdp* instance, const UwacPointerAxisEvent* ev) { rdpInput* input; UINT16 flags = 0; - int direction; - uint32_t step; + int32_t direction; uint32_t x, y; + uint32_t i; if (!instance || !ev || !instance->input) return FALSE; @@ -152,7 +152,7 @@ BOOL wlf_handle_pointer_axis(freerdp* instance, const UwacPointerAxisEvent* ev) input = instance->input; - direction = wl_fixed_to_int(ev->value); + direction = ev->value; switch (ev->axis) { case WL_POINTER_AXIS_VERTICAL_SCROLL: @@ -176,17 +176,14 @@ BOOL wlf_handle_pointer_axis(freerdp* instance, const UwacPointerAxisEvent* ev) * positive: 0 ... 0xFF -> slow ... fast * negative: 0 ... 0xFF -> fast ... slow */ - step = abs(direction); - if (step > 0xFF) - step = 0xFF; + for (i = 0; i < abs(direction); i++) + { + const uint32_t cflags = flags | 0x78; + if (!freerdp_input_send_mouse_event(input, cflags, (UINT16)x, (UINT16)y)) + return FALSE; + } - /* Negative rotation, so count down steps from top */ - if (flags & PTR_FLAGS_WHEEL_NEGATIVE) - step = 0xFF - step; - - flags |= step; - - return freerdp_input_send_mouse_event(input, flags, (UINT16)x, (UINT16)y); + return TRUE; } BOOL wlf_handle_key(freerdp* instance, const UwacKeyEvent* ev) diff --git a/client/Wayland/wlfreerdp.c b/client/Wayland/wlfreerdp.c index 4ba89a8c5..96764ee14 100644 --- a/client/Wayland/wlfreerdp.c +++ b/client/Wayland/wlfreerdp.c @@ -356,6 +356,9 @@ static BOOL handle_uwac_events(freerdp* instance, UwacDisplay* display) break; case UWAC_EVENT_POINTER_AXIS: + break; + + case UWAC_EVENT_POINTER_AXIS_DISCRETE: if (!wlf_handle_pointer_axis(instance, &event.mouse_axis)) return FALSE; diff --git a/uwac/include/uwac/uwac.h b/uwac/include/uwac/uwac.h index f44da7d3c..819796105 100644 --- a/uwac/include/uwac/uwac.h +++ b/uwac/include/uwac/uwac.h @@ -107,6 +107,7 @@ enum UWAC_EVENT_CLIPBOARD_SELECT, UWAC_EVENT_CLIPBOARD_OFFER, UWAC_EVENT_OUTPUT_GEOMETRY, + UWAC_EVENT_POINTER_AXIS_DISCRETE }; /** @brief window states */ diff --git a/uwac/libuwac/uwac-input.c b/uwac/libuwac/uwac-input.c index 31c2b369d..1e0200167 100644 --- a/uwac/libuwac/uwac-input.c +++ b/uwac/libuwac/uwac-input.c @@ -862,6 +862,24 @@ static void pointer_axis_discrete(void* data, struct wl_pointer* wl_pointer, uin int32_t discrete) { /*UwacSeat *seat = data;*/ + UwacPointerAxisEvent* event; + UwacSeat* seat = data; + UwacWindow* window = seat->pointer_focus; + + if (!window) + return; + + event = + (UwacPointerAxisEvent*)UwacDisplayNewEvent(seat->display, UWAC_EVENT_POINTER_AXIS_DISCRETE); + if (!event) + return; + + event->seat = seat; + event->window = window; + event->x = seat->sx; + event->y = seat->sy; + event->axis = axis; + event->value = discrete; } static const struct wl_pointer_listener pointer_listener = {