-
Notifications
You must be signed in to change notification settings - Fork 913
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
feat(x11): Map Shift+keys to the same virtual code #2630
Conversation
Previously, symbols (particularly number row symbols) were poorly mapped and Shift+[Number] would either not trigger a KeyboardInput event at all, or trigger one with a symbol (e.g. At) as opposed to the non-symbol (Key2). The approach taken here would map, for instance, XK_2 and XK_at to VirtualKeyCode::Key2, this approach was taken as opposed to mapping XK_at to VirtualKeyCode::At as it makes more sense to have a `virtual_keycode` of Key2 with Shift in `modifiers` active, rather than to have a `virtual_keycode` of At with a Shift in `modifiers` which would be nonsensical. This approach was also taken for the macOS implementation in src/platform_impl/macos/event.rs. Furthermore, Alacritty (a notable dependant of this library) defines key bindings by specifying a key as `Key[Number]` as opposed to the symbol name, coupled with any modifiers.
Remains unchanged. But, unless anyone puts in the effort of making a cross-platform API over this based on physical key position (possibly necessary for reliable game key bindings; IIRC the great keyboard events overhaul #1806 / #753 does propose this), it's only real use is to match key release.
Yes, probably preferable to assign bindings to e.g. |
Ah, I should have know this couldn't be such an easy fix :) Thanks for the info.
I'm not too knowledgeable on keyboard input, but is it an issue that the scancode remains the same? What I understand is that the scancode is hardware-dependent, whereas the keycode not and is specified by It looks to me like the scancode shouldn't really be of much of a concern, looking at the code it simply appears to be the raw keycode subtracted by an offset. The
Just to clarify, do you mean cross-platform as in any hardware on an X11 system or any OS (which sounds like a big feat)? And are you referring to making it such that
But isn't Qt written in C++? Does it somehow make use of winit as a dependency? I'll try to take a look at those two threads when I'm free. But from your last statement, does it happen to be the case that there are two "binding styles" that need to be supported (with the non-preferred style being used now)? In any case, I suppose this will take much longer than expected. It's just odd that winit only supports the |
You're probably right; it's a while since I looked at this. So the scancode can be ignored. One proposal is Cross-platform usually means across any OS. But that's essentially already done ( I don't know exactly what's going on here; I've just vaguely been following. It's possible this PR is useful (since the overhaul PRs haven't been landed yet). No, Qt doesn't have much to do with Winit. Looking at prior examples can be useful (arguably looking at Windows or OSX would be more useful; Qt was just easier for me to test). |
I think #2662 should address your use-case. If it doesn't, fell free to tell us what could be improved. |
Closing given that #2662 merged. |
CHANGELOG.md
if knowledge of this change could be valuable to usersIn x11, symbols (particularly number row symbols) are poorly mapped and
Shift+[Number]
would either not trigger a KeyboardInput event at all, or trigger one with a symbol (e.g.At
) as opposed to the non-symbol (Key2
).The approach taken here would map, for instance,
XK_2
andXK_at
toVirtualKeyCode::Key2
Why was this done?
This approach was taken as opposed to mapping
XK_at
toVirtualKeyCode::At
as it makes more sense to have avirtual_keycode
ofKey2
withShift
inmodifiers
active, rather than to have avirtual_keycode
ofAt
with aShift
inmodifiers
which would be nonsensical. This approach was also taken for the macOS implementation in src/platform_impl/macos/event.rs.Furthermore, Alacritty (a notable user of this library) defines key bindings by specifying a key as
Key[Number]
as opposed to the symbol name, coupled with any modifiers, as shown here. In other words, as of this moment, none of the Shift+[Number] keys work, even on Alacritty (on x11).To illustrate the change that this PR makes, here's what this example code would produce before this change.
Run the code and hit
2
followed byShift+2
(the@
symbol)Before:
After:
Some(At)
vsSome(Key2)
.This appears to be what was done in the macOS implementation so I believe it's the right approach to take.