From f7aab11128cc707de62bb509939b88021abac5cf Mon Sep 17 00:00:00 2001 From: Andri Yngvason Date: Sun, 19 Jul 2020 21:55:40 +0000 Subject: [PATCH] pointer: Translate contiguous scroll to discrete scroll --- include/pointer.h | 3 +++ src/pointer.c | 25 ++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/include/pointer.h b/include/pointer.h index a51640b..86899da 100644 --- a/include/pointer.h +++ b/include/pointer.h @@ -47,6 +47,9 @@ struct pointer { int vertical_scroll_steps; int horizontal_scroll_steps; + double vertical_axis_value; + double horizontal_axis_value; + struct wl_cursor_theme* cursor_theme; struct wl_surface* cursor_surface; diff --git a/src/pointer.c b/src/pointer.c index 82daea9..bbfb5a4 100644 --- a/src/pointer.c +++ b/src/pointer.c @@ -24,6 +24,8 @@ #include "pointer.h" +#define STEP_SIZE 15.0 + extern struct wl_shm* wl_shm; extern struct wl_compositor* wl_compositor; @@ -228,7 +230,19 @@ static void pointer_button(void* data, struct wl_pointer* wl_pointer, static void pointer_axis(void* data, struct wl_pointer* wl_pointer, uint32_t t, enum wl_pointer_axis axis, wl_fixed_t value) { - // TODO + struct pointer_collection* self = data; + struct pointer* pointer = + pointer_collection_find_wl_pointer(self, wl_pointer); + + switch (axis) { + case WL_POINTER_AXIS_VERTICAL_SCROLL: + pointer->vertical_axis_value += wl_fixed_to_double(value); + break; + case WL_POINTER_AXIS_HORIZONTAL_SCROLL: + pointer->horizontal_axis_value += wl_fixed_to_double(value); + break; + default:; + } } static void pointer_axis_source(void* data, struct wl_pointer* wl_pointer, @@ -267,6 +281,15 @@ static void pointer_frame(void* data, struct wl_pointer* wl_pointer) struct pointer* pointer = pointer_collection_find_wl_pointer(self, wl_pointer); + double vertical_steps = trunc(pointer->vertical_axis_value / STEP_SIZE); + pointer->vertical_axis_value -= vertical_steps * STEP_SIZE; + + double horizontal_steps = trunc(pointer->horizontal_axis_value / STEP_SIZE); + pointer->horizontal_axis_value -= horizontal_steps * STEP_SIZE; + + pointer->vertical_scroll_steps += vertical_steps; + pointer->horizontal_scroll_steps += horizontal_steps; + self->on_frame(self, pointer); pointer->vertical_scroll_steps = 0;