mirror of
https://github.com/tauri-apps/tao.git
synced 2026-01-31 00:35:16 +01:00
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:
5
.changes/windows-scroll-line-settings.md
Normal file
5
.changes/windows-scroll-line-settings.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
tao: patch
|
||||
---
|
||||
|
||||
Fix `WindowEvent::MouseWheel` doesn't account for mouse wheel speed settings
|
||||
@@ -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,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user