diff --git a/glfw/cocoa_window.m b/glfw/cocoa_window.m index e19643138..deaf82d07 100644 --- a/glfw/cocoa_window.m +++ b/glfw/cocoa_window.m @@ -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; diff --git a/glfw/glfw3.h b/glfw/glfw3.h index 7219a8209..f6c52cd0e 100644 --- a/glfw/glfw3.h +++ b/glfw/glfw3.h @@ -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; diff --git a/glfw/wl_init.c b/glfw/wl_init.c index 68c5ab197..aa97435d1 100644 --- a/glfw/wl_init.c +++ b/glfw/wl_init.c @@ -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 */ diff --git a/glfw/x11_window.c b/glfw/x11_window.c index 87df5fbb7..b45f45a1a 100644 --- a/glfw/x11_window.c +++ b/glfw/x11_window.c @@ -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 { diff --git a/kitty/glfw-wrapper.h b/kitty/glfw-wrapper.h index 925ac6f6b..e6e051bb0 100644 --- a/kitty/glfw-wrapper.h +++ b/kitty/glfw-wrapper.h @@ -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;