From 4d48c76da927ac7decd22f84c5e99c41b99ab2fa Mon Sep 17 00:00:00 2001 From: Markus Siglreithmaier Date: Sat, 8 Oct 2022 05:32:40 +0200 Subject: [PATCH] Windows, emit `ReceivedCharacter` on system keybinds Currently needed for downstream users relaying on `ReceivedCharacter` for implementing keybindings. --- CHANGELOG.md | 1 + src/platform_impl/windows/event_loop.rs | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 05fb4f07..6c30e7e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ And please only add new entries to the top of this list, right below the `# Unre # Unreleased +- On Windows, emit `ReceivedCharacter` events on system keybindings. - On Windows, fixed focus event emission on minimize. - On MacOS, made `accepts_first_mouse` configurable. - Migrated `WindowBuilderExtUnix::with_resize_increments` to `WindowBuilder`. diff --git a/src/platform_impl/windows/event_loop.rs b/src/platform_impl/windows/event_loop.rs index 26b81e2d..a5baf131 100644 --- a/src/platform_impl/windows/event_loop.rs +++ b/src/platform_impl/windows/event_loop.rs @@ -65,7 +65,7 @@ use windows_sys::Win32::{ WM_MOUSEWHEEL, WM_NCACTIVATE, WM_NCCALCSIZE, WM_NCCREATE, WM_NCDESTROY, WM_NCLBUTTONDOWN, WM_PAINT, WM_POINTERDOWN, WM_POINTERUP, WM_POINTERUPDATE, WM_RBUTTONDOWN, WM_RBUTTONUP, WM_SETCURSOR, WM_SETFOCUS, WM_SETTINGCHANGE, WM_SIZE, - WM_SYSCOMMAND, WM_SYSKEYDOWN, WM_SYSKEYUP, WM_TOUCH, WM_WINDOWPOSCHANGED, + WM_SYSCHAR, WM_SYSCOMMAND, WM_SYSKEYDOWN, WM_SYSKEYUP, WM_TOUCH, WM_WINDOWPOSCHANGED, WM_WINDOWPOSCHANGING, WM_XBUTTONDOWN, WM_XBUTTONUP, WNDCLASSEXW, WS_EX_LAYERED, WS_EX_NOACTIVATE, WS_EX_TOOLWINDOW, WS_EX_TRANSPARENT, WS_OVERLAPPED, WS_POPUP, WS_VISIBLE, @@ -1186,7 +1186,7 @@ unsafe fn public_window_callback_inner( 0 } - WM_CHAR => { + WM_CHAR | WM_SYSCHAR => { use crate::event::WindowEvent::ReceivedCharacter; use std::char; let is_high_surrogate = (0xD800..=0xDBFF).contains(&wparam); @@ -1217,7 +1217,18 @@ unsafe fn public_window_callback_inner( } } - 0 + // todo(msiglreith): + // Ideally, `WM_SYSCHAR` shouldn't emit a `ReceivedChar` event + // indicating user text input. As we lack dedicated support + // accelerators/keybindings these events will be additionally + // emitted for downstream users. + // This means certain key combinations (ie Alt + Space) will + // trigger the default system behavior **and** emit a char event. + if msg == WM_SYSCHAR { + DefWindowProcW(window, msg, wparam, lparam) + } else { + 0 + } } WM_MENUCHAR => (MNC_CLOSE << 16) as isize,