-
Notifications
You must be signed in to change notification settings - Fork 893
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
Some key combinations with control generate incomplete events #2898
Comments
There are also report by @fredizzimo that similar problem happens on Wayland, but this is probably a different issue. |
I am on Windows 10 21H2 build 19044.1526, 64-bit. |
@ZyX-II you should have |
Looks like offending key combinations come as just WM_KEYDOWN/WM_SYSKEYDOWN which is why utf16parts is missing. Log where I typed diff --git a/src/platform_impl/windows/event_loop.rs b/src/platform_impl/windows/event_loop.rs
index 7ed5b820..e9de3ffa 100644
--- a/src/platform_impl/windows/event_loop.rs
+++ b/src/platform_impl/windows/event_loop.rs
@@ -163,7 +163,7 @@ impl<T> ThreadMsgTargetData<T> {
}
/// The result of a subclass procedure (the message handling callback)
-#[derive(Clone, Copy)]
+#[derive(Clone, Copy, Debug)]
pub(crate) enum ProcResult {
DefWindowProc(WPARAM),
Value(isize),
diff --git a/src/platform_impl/windows/keyboard.rs b/src/platform_impl/windows/keyboard.rs
index 595cd4c5..fe5084dd 100644
--- a/src/platform_impl/windows/keyboard.rs
+++ b/src/platform_impl/windows/keyboard.rs
@@ -124,6 +124,7 @@ impl KeyEventBuilder {
return MatchResult::Nothing;
}
let pending_token = self.pending.add_pending();
+ trace!("KD w:{wparam:04x} l:{lparam:04x} r:{result:?}");
*result = ProcResult::Value(0);
let next_msg = next_kbd_msg(hwnd);
@@ -136,6 +137,7 @@ impl KeyEventBuilder {
&mut layouts,
));
let mut event_info = self.event_info.lock().unwrap();
+ trace!("KD ei:{event_info:?}");
*event_info = None;
if let Some(next_msg) = next_msg {
let next_msg_kind = next_msg.message;
@@ -191,6 +193,7 @@ impl KeyEventBuilder {
trace!("Received a CHAR message but no `event_info` was available. The message is probably IME, returning.");
return MatchResult::Nothing;
}
+ trace!("w:{wparam:04x} l:{lparam:04x} r:{result:?} ei:{event_info:?}");
let pending_token = self.pending.add_pending();
*result = ProcResult::Value(0);
let is_high_surrogate = (0xD800..=0xDBFF).contains(&wparam);
@@ -490,12 +493,14 @@ impl KeyEventBuilder {
}
}
+#[derive(Debug)]
enum PartialText {
// Unicode
System(Vec<u16>),
Text(Option<SmolStr>),
}
+#[derive(Debug)]
enum PartialLogicalKey {
/// Use the text provided by the WM_CHAR messages and report that as a `Character` variant. If
/// the text consists of multiple grapheme clusters (user-precieved characters) that means that
@@ -507,6 +512,7 @@ enum PartialLogicalKey {
This(Key),
}
+#[derive(Debug)]
struct PartialKeyEventInfo {
vkey: VIRTUAL_KEY,
key_state: ElementState,
@@ -617,6 +623,7 @@ impl PartialKeyEventInfo {
}
fn finalize(self) -> KeyEvent {
+ trace!("KeyEvent fin: {self:?}");
let mut char_with_all_modifiers = None;
if !self.utf16parts.is_empty() {
let os_string = OsString::from_wide(&self.utf16parts); |
@kchibisov So you are saying that this should be fixed on neovide side? |
@fredizzimo could you reproduce your issue on Wayland with some example in winit with the full log of events? |
@ZyX-II I'm saying that neovide has all the information, however it would be nice to know why on windows we don't get |
I will do later this evening, when I have access to that computer. But here is what I wrote when I did the testing before, with US layout and the keys
So somehow it seems to be layout dependent. |
For Windows it looks like it is just a matter of system choosing to not emit |
We could check for this in the following order
But I don't see why we should have to check |
@fredizzimo I think you can check It's true though, that you might want to have bindings for some weird characters, so you may want text as well to bind weird keys (but I don't see why you'd want to bind anything other than latin in vim anyway (they have keyboard map setting to make it work for non-latin...). |
We definitely want the operating system to resolve the keymap specific characters, dor example, to resolve There are plenty of default bindings that would stop working without that on my Swedish keyboard and as far as I know Edit: That makes me wonder what does for example, |
That's for normal, so you can navigate on non ascii layouts. |
Yes, but my point was that it solves a different problem and does nothing to help with turning base key + shift state + altgr state to the correct mapping in Vim. So, if we used just |
Basically this:
|
Note: neovide diff changed from previous comment in PR, it is now diff --git a/src/window/keyboard_manager.rs b/src/window/keyboard_manager.rs
index 3525f08..ddd6f52 100644
--- a/src/window/keyboard_manager.rs
+++ b/src/window/keyboard_manager.rs
@@ -67,6 +67,7 @@ impl KeyboardManager {
}
fn format_key(&self, key_event: &KeyEvent) -> Option<String> {
+ log::trace!("Format key: {key_event:?}. Mods: {:?}.", &self.modifiers);
if let Some(text) = get_special_key(&key_event.logical_key) {
Some(self.format_key_text(text, true))
} else { . Basically I just added “Mods: …” part with current modifiers. |
Logs are currently collected by running
with |
That's good news. I was afraid that it would return the base key. But the logical key has the correct information. So using that as a backup could work in Neovide. Still i think that according to the winit documentation it should also include the correct text. |
I won't be able to test wayland until after the weekend. But I did some testing on Windows using spy++, I can confirm that I found that on Windows none of the control + number mappings work with my Swedish keyboard layout. But the alpha keys can be mapped. Then I went to http://www.kbdlayout.info to check the Swedish keymap. I found out that it's actually possible to map Control to a character, and disallow it completely with -1, as can be seen for the numbers here http://www.kbdlayout.info/kbdsw/download/klc. So, I believe this solves the mystery why it works the way it does currently, at least on Windows. Now, it's more of a winit design decision to choose if text should be valid or not. In Neovide I think we can work both ways, I already did some local changes and can confirm that using |
I think the issue title is inaccurate? Anyway, I have run into basically the same thing:
On the other hand, does use of Using |
I think the original issue was about some special layout on Windows and the fact that some keys were not reaching the users of winit. @dhardy logical keys is what should be used for mappings. If you want to ignore shift, in the current revision the only way to do so, is to lowercase the character yourself, which is more or less ok... |
I think it's relevant to neovide/neovide#1290, and https://github.com/joshgoebel/keyszer can work (with some little bug) I have the same problem on wayland with xremap |
While working with neovide/neovide#1899 it was found out that neovide from this PR still cannot recognize keyboard shortcuts like
<C-]>
on some layouts.Tracing the issue it was found out that for offending shortcuts neovide receives events from winint looking like
: note lack of any indication of
<C-
being pressed andtext_with_all_modifiers
being absent. (Keyboard layout in question is programming dvorak, with some modifications.) Some more digging led me to finding out that earlier inwinint::platform_impl::windows::keyboard::PartialKeyEventInfo::finalize
function receivesself
withutf16parts
missing, looking like this:and also utterly lacking any indication that this key was pressed while
<C-
was pressed.I can reproduce the issue on standard Windows US layout with
<C-->
: https://gist.github.com/ZyX-II/0ae83a6c1935cdd7ccd64df7ccc683d2. (Log was generated with modifications to neovide from neovide/neovide#1899 (comment), and winit f7a400d with)
The text was updated successfully, but these errors were encountered: