fix(windows): apply scroll lines per wheel setting (#1119)

* fix(windows): apply scroll lines per wheel setting

* Add change file

* typo
This commit is contained in:
Tony
2025-08-23 20:52:39 +08:00
committed by GitHub
parent a1edbeb448
commit 28f5a96a7d
2 changed files with 37 additions and 2 deletions

View File

@@ -0,0 +1,5 @@
---
tao: patch
---
Fix `WindowEvent::MouseWheel` doesn't account for mouse wheel speed settings

View File

@@ -68,6 +68,13 @@ use runner::{EventLoopRunner, EventLoopRunnerShared};
use super::{dpi::hwnd_dpi, util::get_system_metrics_for_dpi};
// This is defined in `winuser.h` as a macro that expands to `UINT_MAX`
const WHEEL_PAGESCROLL: u32 = u32::MAX;
// https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-systemparametersinfoa#:~:text=SPI_GETWHEELSCROLLLINES
const DEFAULT_SCROLL_LINES_PER_WHEEL_DELTA: isize = 3;
// https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-systemparametersinfoa#:~:text=SPI_GETWHEELSCROLLCHARS
const DEFAULT_SCROLL_CHARACTERS_PER_WHEEL_DELTA: isize = 3;
type GetPointerFrameInfoHistory = unsafe extern "system" fn(
pointerId: u32,
entriesCount: *mut u32,
@@ -1378,11 +1385,25 @@ unsafe fn public_window_callback_inner<T: 'static>(
let modifiers = update_modifiers(window, subclass_input);
let mut scroll_lines = DEFAULT_SCROLL_LINES_PER_WHEEL_DELTA;
let _ = SystemParametersInfoW(
SPI_GETWHEELSCROLLLINES,
0,
Some(&mut scroll_lines as *mut isize as *mut c_void),
SYSTEM_PARAMETERS_INFO_UPDATE_FLAGS(0),
);
if scroll_lines as u32 == WHEEL_PAGESCROLL {
// TODO: figure out how to handle page scrolls
scroll_lines = DEFAULT_SCROLL_LINES_PER_WHEEL_DELTA;
}
subclass_input.send_event(Event::WindowEvent {
window_id: RootWindowId(WindowId(window.0 as _)),
event: WindowEvent::MouseWheel {
device_id: DEVICE_ID,
delta: LineDelta(0.0, value),
delta: LineDelta(0.0, value * scroll_lines as f32),
phase: TouchPhase::Moved,
modifiers,
},
@@ -1399,11 +1420,20 @@ unsafe fn public_window_callback_inner<T: 'static>(
let modifiers = update_modifiers(window, subclass_input);
let mut scroll_characters = DEFAULT_SCROLL_CHARACTERS_PER_WHEEL_DELTA;
let _ = SystemParametersInfoW(
SPI_GETWHEELSCROLLCHARS,
0,
Some(&mut scroll_characters as *mut isize as *mut c_void),
SYSTEM_PARAMETERS_INFO_UPDATE_FLAGS(0),
);
subclass_input.send_event(Event::WindowEvent {
window_id: RootWindowId(WindowId(window.0 as _)),
event: WindowEvent::MouseWheel {
device_id: DEVICE_ID,
delta: LineDelta(value, 0.0),
delta: LineDelta(value * scroll_characters as f32, 0.0),
phase: TouchPhase::Moved,
modifiers,
},