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: Update handling of system keypresses #2445

Merged
merged 1 commit into from Aug 31, 2022

Conversation

ajtribick
Copy link
Contributor

  • Tested on all platforms changed
    • Windows 10
  • 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 (N/A)
  • Created or updated an example program if it would help users understand this functionality (N/A)
  • Updated feature matrix, if new features were added or implemented (N/A)

This follows Microsoft's documentation on handling the WM_SYSCHAR and WM_SYSKEYDOWN events. Allows the ALT+Space menu to work.

This also allows opening the window menu in fullscreen, as tested in the "fullscreen" example. I'm not sure whether or not that is desired behavior.

Resolves #2406

Copy link
Member

@msiglreith msiglreith left a comment

Choose a reason for hiding this comment

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

thanks! a few changes would be needed

@@ -1218,7 +1218,12 @@ unsafe fn public_window_callback_inner<T: 'static>(
});
}
}
0

if msg == WM_SYSCHAR {
Copy link
Member

Choose a reason for hiding this comment

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

I would prefer to completely remove the WM_SYSCHAR as a case we explicitly handle in WM_CHAR | WM_SYSCHAR - otherwise we would generate ReceivedCharacter events which isn't desired imo.
WM_SYSCHAR would be then handled by the default fallback.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. I've also added a handler for WM_MENUCHAR to disable the annoying beep sound when an ALT+keypress is entered. This could in principle be used to communicate an event to be used in a menu system, but not sure how generalisable that would be to other platforms.

src/platform_impl/windows/event_loop.rs Outdated Show resolved Hide resolved
- Pass WM_SYSKEYDOWN to DefWindowProc
- Avoid intercepting WM_SYSCHAR to allow ALT+Space to work: removes ReceivedCharacter events for alt+keypress
- Intercept WM_MENUCHAR to disable bell sound
@ajtribick
Copy link
Contributor Author

Force pushed to pick up the CI fix

@ajtribick ajtribick changed the title Windows: Pass WM_SYSCHAR and WM_SYSKEYDOWN to DefWindowProc Windows: Update handling of system keypresses Aug 31, 2022
@msiglreith msiglreith merged commit dfecdc5 into rust-windowing:master Aug 31, 2022
@ajtribick ajtribick deleted the alt-space-fix branch September 1, 2022 05:49
kchibisov pushed a commit to kchibisov/winit that referenced this pull request Sep 9, 2022
- Pass WM_SYSKEYDOWN to DefWindowProc
- Avoid intercepting WM_SYSCHAR to allow ALT+Space to work: removes ReceivedCharacter events for alt+keypress
- Intercept WM_MENUCHAR to disable bell sound
kchibisov pushed a commit that referenced this pull request Sep 11, 2022
- Pass WM_SYSKEYDOWN to DefWindowProc
- Avoid intercepting WM_SYSCHAR to allow ALT+Space to work: removes ReceivedCharacter events for alt+keypress
- Intercept WM_MENUCHAR to disable bell sound
@ilya-bobyr
Copy link

This change broke compatibility between Windows and other platforms.
On Unix pressing Alt+B emits ReceivedCharacter, while on Windows, after this change, ReceivedCharacter is no longer emitted.

Here is a relevant bug for Alacritty, for example: alacritty/alacritty#6356

Should I open a separate issue for this discussion, or should we use this one?

@madsmtm
Copy link
Member

madsmtm commented Sep 27, 2022

Please open a new issue, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

Alt-space does not open the system menu on Windows
5 participants