From 7b7ba38655d93959540dcf711f3a249b3d6d6c05 Mon Sep 17 00:00:00 2001 From: MacDue Date: Sat, 5 Aug 2023 17:25:19 +0100 Subject: [PATCH] Ladybird: Fix scroll step size The Qt docs are not that clear, but to get the number of steps the wheel was scrolled you divide by 120 (which when multiplied by wheelScrollLines() gives the scroll offset). --- Ladybird/WebContentView.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Ladybird/WebContentView.cpp b/Ladybird/WebContentView.cpp index cd1c2a9189..c1d45e4911 100644 --- a/Ladybird/WebContentView.cpp +++ b/Ladybird/WebContentView.cpp @@ -282,9 +282,13 @@ void WebContentView::wheelEvent(QWheelEvent* event) auto button = get_button_from_qt_event(*event); auto buttons = get_buttons_from_qt_event(*event); auto modifiers = get_modifiers_from_qt_mouse_event(*event); - auto num_degrees = -event->angleDelta() / 8; - client().async_mouse_wheel(to_content_position(position), button, buttons, modifiers, num_degrees.x(), num_degrees.y()); - + auto num_degrees = -event->angleDelta(); + float delta_x = -num_degrees.x() / 120; + float delta_y = num_degrees.y() / 120; + // Note: This does not use the QScrollBar's step size as LibWeb multiples this by a step size internally. + auto step_x = delta_x * QApplication::wheelScrollLines() * devicePixelRatio(); + auto step_y = delta_y * QApplication::wheelScrollLines() * devicePixelRatio(); + client().async_mouse_wheel(to_content_position(position), button, buttons, modifiers, step_x, step_y); event->accept(); return; }