Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Windows] Reverse horizonal scroll direction in WindowEvent::MouseWheel #2101

Closed
wants to merge 3 commits into from

Conversation

aevyrie
Copy link

@aevyrie aevyrie commented Dec 18, 2021

  • Tested on all platforms changed
  • Compilation warnings were addressed
  • cargo fmt has been run on this branch
  • cargo doc builds successfully
  • Added an entry to CHANGELOG.md if knowledge of this change could be valuable to users
  • Updated documentation to reflect any user-facing changes, including notes of platform-specific behavior
  • Created or updated an example program if it would help users understand this functionality
  • Updated feature matrix, if new features were added or implemented

Fixes #2099
Addresses part of downstream issue emilk/egui#356

On windows, the horizonal and vertical scrolling directions do not match when running the MRE in #2099. Considering vertical scroll is used in many places already, it seems sensible to swap horizontal scroll deltas on windows, like #1695.

This PR also changes the mouse_wheel example to demonstrate scroll behavior. In its current state, it only reports mouse device events, which don't seem to report horizontal scrolling on windows. I've changed this to WindowEvent::MouseWheel, which allows you to test x and y scrolling - which seems to be the intent of the example considering it already allows repositioning the window in x and y. I've also flipped the delta applied to the window, so it moves in the direction the page you are scrolling would move. This makes it easier to verify "natural" scrolling is working as expected.

@maroider maroider added DS - windows C - needs discussion Direction must be ironed out labels Dec 18, 2021
@aevyrie aevyrie changed the title Flip horizonal scroll on windows impl [Windows] Reverse horizonal scroll direction in WindowEvent::MouseWheel Dec 18, 2021
@@ -1200,7 +1200,7 @@ unsafe fn public_window_callback_inner<T: 'static>(

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;
Copy link
Contributor

@aloucks aloucks Dec 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://docs.microsoft.com/en-us/windows/win32/api/windowsx/nf-windowsx-get_y_lparam

Use GET_Y_LPARAM instead of HIWORD to extract signed coordinate data. Negative screen coordinates may be returned on multiple monitor systems.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aloucks could you expand on the relevance of this please? I'm not familiar with the win32 api.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the suggestion to use lparam instead of wparam?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I misread part of https://docs.microsoft.com/en-us/windows/win32/inputdev/wm-mousehwheel and thought the negative value might be related. I think you can disregard my previous comment.

Have you checked to see how GLFW treats the mouse wheel direction? I think we should just use that prior art as reference and have the same behavior.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

@aevyrie aevyrie Dec 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, if I read this correctly, this PR follows GLFW prior art.

emilk added a commit to emilk/winit that referenced this pull request Dec 20, 2021
The previous hscroll was based on a wrong precedence set by windows.

The PR to fix this on windows is at rust-windowing#2101

With this PR we now match what GLFW does: https://github.com/glfw/glfw/blob/53d86c64d709ff52886580d338d9b3b2b1f27266/src/cocoa_window.m#L614:L627

This will remove the need for a workaround in my egui crate at https://github.com/emilk/egui/blob/master/egui-winit/src/lib.rs#L456-L460
@emilk emilk mentioned this pull request Dec 20, 2021
8 tasks
emilk added a commit to emilk/winit that referenced this pull request Jan 3, 2022
The previous hscroll was based on a wrong precedence set by windows.

The PR to fix this on windows is at rust-windowing#2101

With this PR we now match what GLFW does: https://github.com/glfw/glfw/blob/53d86c64d709ff52886580d338d9b3b2b1f27266/src/cocoa_window.m#L614:L627

This will remove the need for a workaround in my egui crate at https://github.com/emilk/egui/blob/master/egui-winit/src/lib.rs#L456-L460
@emilk
Copy link
Contributor

emilk commented Jan 3, 2022

I've cherry-picked the changes in this PR into #2105, so I suggest we close this PR in favor of that more all-encompassing PR (which also includes updated documentation).

@madsmtm
Copy link
Member

madsmtm commented Jan 3, 2022

Agreed, closing in favor of #2105, thanks for your contribution @aevyrie!

@madsmtm madsmtm closed this Jan 3, 2022
@aevyrie
Copy link
Author

aevyrie commented Jan 3, 2022

Sounds great. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C - needs discussion Direction must be ironed out DS - windows
Development

Successfully merging this pull request may close these issues.

Horizontal Scrolling Backwards on Windows
6 participants