Wayland: Fix line and v120 scroll event types being multiplied by screen scale

This does not match X11/macOS behavior. And I see no logical reason why
it should be so. The wheel_scroll_multiplier should be used to adjust
this by end users.
This commit is contained in:
Kovid Goyal 2026-01-09 12:50:07 +05:30
parent 48de08ded1
commit 3c250a741d
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
5 changed files with 19 additions and 16 deletions

View file

@ -1314,9 +1314,10 @@ is_modifier_pressed(NSUInteger flags, NSUInteger target_mask, NSUInteger other_m
- (void)scrollWheel:(NSEvent *)event
{
GLFWScrollEvent ev = {.keyboard_modifiers=translateFlags([event modifierFlags])};
ev.x_offset = [event scrollingDeltaX];
ev.y_offset = [event scrollingDeltaY];
GLFWScrollEvent ev = {
.keyboard_modifiers=translateFlags([event modifierFlags]), .unscaled.x = [event scrollingDeltaX], .unscaled.y = [event scrollingDeltaY]};
ev.x_offset = ev.unscaled.x;
ev.y_offset = ev.unscaled.y;
if ([event hasPreciseScrollingDeltas]) {
ev.offset_type = GLFW_SCROLL_OFFEST_HIGHRES;
float xscale = 1, yscale = 1;

3
glfw/glfw3.h vendored
View file

@ -563,7 +563,8 @@ typedef enum GLFWOffsetType {
} GLFWOffsetType;
typedef struct GLFWScrollEvent {
double x_offset, y_offset; // offsets are scaled by the window scale
double x_offset, y_offset; // offsets are scaled by the window scale for HIGHRES
struct { double x, y; } unscaled; // unscaled offsets, aka logical pixels
GLFWMomentumType momentum_type;
GLFWOffsetType offset_type;
int keyboard_modifiers;

14
glfw/wl_init.c vendored
View file

@ -207,23 +207,23 @@ pointer_handle_frame(void *data UNUSED, struct wl_pointer *pointer UNUSED) {
GLFWScrollEvent ev = {.keyboard_modifiers=_glfw.wl.xkb.states.modifiers};
if (info.discrete.y_axis_type != AXIS_EVENT_UNKNOWN) {
ev.y_offset = info.discrete.y;
ev.unscaled.y = info.discrete.y;
if (info.discrete.y_axis_type == AXIS_EVENT_VALUE120) ev.offset_type = GLFW_SCROLL_OFFEST_V120;
} else if (info.continuous.y_axis_type != AXIS_EVENT_UNKNOWN) {
ev.offset_type = GLFW_SCROLL_OFFEST_HIGHRES;
ev.y_offset = info.continuous.y;
ev.unscaled.y = info.continuous.y;
}
if (info.discrete.x_axis_type != AXIS_EVENT_UNKNOWN) {
ev.x_offset = info.discrete.x;
ev.unscaled.x = info.discrete.x;
if (info.discrete.x_axis_type == AXIS_EVENT_VALUE120) ev.offset_type = GLFW_SCROLL_OFFEST_V120;
} else if (info.continuous.x_axis_type != AXIS_EVENT_UNKNOWN) {
ev.offset_type = GLFW_SCROLL_OFFEST_HIGHRES;
ev.x_offset = info.continuous.x;
ev.unscaled.x = info.continuous.x;
}
float scale = (float)_glfwWaylandWindowScale(window);
ev.x_offset *= scale; ev.y_offset *= scale;
ev.x_offset *= -1;
ev.unscaled.x *= -1;
const double scale = ev.offset_type == GLFW_SCROLL_OFFEST_HIGHRES ? _glfwWaylandWindowScale(window) : 1;
ev.x_offset = scale * ev.unscaled.x; ev.y_offset = scale * ev.unscaled.y;
glfw_handle_scroll_event_for_momentum(
window, &ev, info.y_stop_received || info.x_stop_received, info.source_type == WL_POINTER_AXIS_SOURCE_FINGER);
/* clear pointer_curr_axis_info for next frame */

8
glfw/x11_window.c vendored
View file

@ -1445,13 +1445,13 @@ static void processEvent(XEvent *event)
// Modern X provides scroll events as mouse button presses
else if (event->xbutton.button == Button4)
_glfwInputScroll(window, &(GLFWScrollEvent){.keyboard_modifiers=mods, .y_offset=1});
_glfwInputScroll(window, &(GLFWScrollEvent){.keyboard_modifiers=mods, .y_offset=1, .unscaled.y=1});
else if (event->xbutton.button == Button5)
_glfwInputScroll(window, &(GLFWScrollEvent){.keyboard_modifiers=mods, .y_offset=-1});
_glfwInputScroll(window, &(GLFWScrollEvent){.keyboard_modifiers=mods, .y_offset=-1, .unscaled.y=-1});
else if (event->xbutton.button == Button6)
_glfwInputScroll(window, &(GLFWScrollEvent){.keyboard_modifiers=mods, .x_offset=1});
_glfwInputScroll(window, &(GLFWScrollEvent){.keyboard_modifiers=mods, .x_offset=1, .unscaled.x=1});
else if (event->xbutton.button == Button7)
_glfwInputScroll(window, &(GLFWScrollEvent){.keyboard_modifiers=mods, .x_offset=-1});
_glfwInputScroll(window, &(GLFWScrollEvent){.keyboard_modifiers=mods, .x_offset=-1, .unscaled.x=-1});
else
{

3
kitty/glfw-wrapper.h generated
View file

@ -301,7 +301,8 @@ typedef enum GLFWOffsetType {
} GLFWOffsetType;
typedef struct GLFWScrollEvent {
double x_offset, y_offset; // offsets are scaled by the window scale
double x_offset, y_offset; // offsets are scaled by the window scale for HIGHRES
struct { double x, y; } unscaled; // unscaled offsets, aka logical pixels
GLFWMomentumType momentum_type;
GLFWOffsetType offset_type;
int keyboard_modifiers;