Skip to content

Commit

Permalink
Fix continuous scrolling speed on Wayland
Browse files Browse the repository at this point in the history
Wayland compositors seem to have standardized on 10 units per "wheel tick" for
continuous scroll events, so we need to convert these axis values to ticks by
dividing by 10 before reporting them in SDL_MOUSEWHEEL events.
  • Loading branch information
cgutman committed Jan 24, 2021
1 parent 8c921d8 commit 7ff3832
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/video/wayland/SDL_waylandevents.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@
#include <unistd.h>
#include <xkbcommon/xkbcommon.h>

/* Weston uses a ratio of 10 units per scroll tick */
#define WAYLAND_WHEEL_AXIS_UNIT 10

typedef struct {
// repeat_rate in range of [1, 1000]
int32_t repeat_rate;
Expand Down Expand Up @@ -471,6 +474,9 @@ pointer_handle_axis_common_v1(struct SDL_WaylandInput *input,
return;
}

x /= WAYLAND_WHEEL_AXIS_UNIT;
y /= WAYLAND_WHEEL_AXIS_UNIT;

SDL_SendMouseWheel(window->sdlwindow, 0, x, y, SDL_MOUSEWHEEL_NORMAL);
}
}
Expand Down Expand Up @@ -528,7 +534,17 @@ pointer_handle_frame(void *data, struct wl_pointer *pointer)
{
struct SDL_WaylandInput *input = data;
SDL_WindowData *window = input->pointer_focus;
float x = input->pointer_curr_axis_info.x, y = input->pointer_curr_axis_info.y;
float x, y;

if (input->pointer_curr_axis_info.is_x_discrete)
x = input->pointer_curr_axis_info.x;
else
x = input->pointer_curr_axis_info.x / WAYLAND_WHEEL_AXIS_UNIT;

if (input->pointer_curr_axis_info.is_y_discrete)
y = input->pointer_curr_axis_info.y;
else
y = input->pointer_curr_axis_info.y / WAYLAND_WHEEL_AXIS_UNIT;

/* clear pointer_curr_axis_info for next frame */
memset(&input->pointer_curr_axis_info, 0, sizeof input->pointer_curr_axis_info);
Expand Down

0 comments on commit 7ff3832

Please sign in to comment.