Skip to content

Commit

Permalink
[Wayland] Fix touchpad scrolling
Browse files Browse the repository at this point in the history
Magic values were determined empirically...

Fixes #134
  • Loading branch information
lbonn committed Jun 6, 2024
1 parent b04bedc commit 93ad86d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
5 changes: 5 additions & 0 deletions include/wayland-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,17 @@ struct _wayland_seat {
struct wl_data_device *data_device;
struct zwp_primary_selection_device_v1 *primary_selection_device;

enum wl_pointer_axis_source axis_source;
widget_button_event button;
widget_motion_event motion;
struct {
gint vertical;
gint horizontal;
} wheel;
struct {
double vertical;
double horizontal;
} wheel_continuous;
};

/* Supported interface versions */
Expand Down
29 changes: 27 additions & 2 deletions source/wayland/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,12 @@ static void wayland_pointer_send_events(wayland_seat *self) {
self->button.button = 0;
}

if (self->axis_source == WL_POINTER_AXIS_SOURCE_FINGER ||
self->axis_source == WL_POINTER_AXIS_SOURCE_CONTINUOUS) {
self->wheel.vertical += 20 * self->wheel_continuous.vertical;
self->wheel.horizontal += 20 * self->wheel_continuous.horizontal;
}

if (abs(self->wheel.vertical) >= 120) {
gint v120 = self->wheel.vertical;
nk_bindings_seat_handle_scroll(wayland->bindings_seat, NULL,
Expand All @@ -637,6 +643,10 @@ static void wayland_pointer_send_events(wayland_seat *self) {
}
}

self->axis_source = 0;
self->wheel_continuous.vertical = 0;
self->wheel_continuous.horizontal = 0;

rofi_view_maybe_update(state);
}

Expand Down Expand Up @@ -804,7 +814,18 @@ static void wayland_pointer_button(void *data, struct wl_pointer *pointer,

static void wayland_pointer_axis(void *data, struct wl_pointer *pointer,
uint32_t time, enum wl_pointer_axis axis,
wl_fixed_t value) {}
wl_fixed_t value) {
wayland_seat *self = data;

switch (axis) {
case WL_POINTER_AXIS_VERTICAL_SCROLL:
self->wheel_continuous.vertical += wl_fixed_to_double(value);
break;
case WL_POINTER_AXIS_HORIZONTAL_SCROLL:
self->wheel_continuous.horizontal += wl_fixed_to_double(value);
break;
}
}

static void wayland_pointer_frame(void *data, struct wl_pointer *pointer) {
wayland_seat *self = data;
Expand All @@ -813,7 +834,11 @@ static void wayland_pointer_frame(void *data, struct wl_pointer *pointer) {

static void
wayland_pointer_axis_source(void *data, struct wl_pointer *pointer,
enum wl_pointer_axis_source axis_source) {}
enum wl_pointer_axis_source axis_source) {

wayland_seat *self = data;
self->axis_source = axis_source;
}

static void wayland_pointer_axis_stop(void *data, struct wl_pointer *pointer,
uint32_t time,
Expand Down

0 comments on commit 93ad86d

Please sign in to comment.