diff --git a/CHANGELOG.md b/CHANGELOG.md index b7a39d7bb6..8c57c8a9f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Unreleased - On X11, add mappings for numpad comma, numpad enter, numlock and pause. +- On Windows, reversed horizontal scrolling in `WindowEvent::MouseWheel` to match the direction of vertical scrolling. # 0.26.0 (2021-12-01) diff --git a/examples/mouse_wheel.rs b/examples/mouse_wheel.rs index e61b64af8f..107e6e7481 100644 --- a/examples/mouse_wheel.rs +++ b/examples/mouse_wheel.rs @@ -1,6 +1,6 @@ use simple_logger::SimpleLogger; use winit::{ - event::{DeviceEvent, Event, WindowEvent}, + event::{Event, WindowEvent}, event_loop::{ControlFlow, EventLoop}, window::WindowBuilder, }; @@ -20,23 +20,20 @@ fn main() { match event { Event::WindowEvent { event, .. } => match event { WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit, - _ => (), - }, - Event::DeviceEvent { event, .. } => match event { - DeviceEvent::MouseWheel { delta } => match delta { + WindowEvent::MouseWheel { delta, .. } => match delta { winit::event::MouseScrollDelta::LineDelta(x, y) => { println!("mouse wheel Line Delta: ({},{})", x, y); let pixels_per_line = 120.0; let mut pos = window.outer_position().unwrap(); - pos.x -= (x * pixels_per_line) as i32; - pos.y -= (y * pixels_per_line) as i32; + pos.x += (x * pixels_per_line) as i32; + pos.y += (y * pixels_per_line) as i32; window.set_outer_position(pos) } winit::event::MouseScrollDelta::PixelDelta(p) => { println!("mouse wheel Pixel Delta: ({},{})", p.x, p.y); let mut pos = window.outer_position().unwrap(); - pos.x -= p.x as i32; - pos.y -= p.y as i32; + pos.x += p.x as i32; + pos.y += p.y as i32; window.set_outer_position(pos) } }, diff --git a/src/platform_impl/windows/event_loop.rs b/src/platform_impl/windows/event_loop.rs index b7bc1cd42b..fe6b0cf6df 100644 --- a/src/platform_impl/windows/event_loop.rs +++ b/src/platform_impl/windows/event_loop.rs @@ -1200,7 +1200,7 @@ unsafe fn public_window_callback_inner( let value = (wparam >> 16) as i16; let value = value as i32; - let value = value as f32 / winuser::WHEEL_DELTA as f32; + let value = -value as f32 / winuser::WHEEL_DELTA as f32; update_modifiers(window, userdata);