-
Notifications
You must be signed in to change notification settings - Fork 903
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
New keyboard API for macOS #1890
New keyboard API for macOS #1890
Conversation
I think there is an issue here where ModifiersState reports alt as held down when using a keyboard layout where the right alt key is actually AltGr. This leads to incorrect keybindings when using the modifiers state to determine if alt is held in combination with another character. |
Ok I've been discussing with some folks and my comment is incorrect. Example: I believe this represents a bug, but I could be wrong. Any insight would be greatly appreciated. |
@Kethku thank you for reporting this, I completely missed this bug! It should be fixed by the commit I just pushed. Test for this behaviour and potential regressions would be greatly appreciated. |
Edit: adding @ArturKovacs because this request is mostly targeted at you who designed the change I will test this soon. Over all the new design is a huge improvement. One problem I'm fighting though is that as far as I can tell it's not possible to determine whether a given modifier was used in the construction of a character. My usecase is in a vim client so if the user binds the key binding ctrl-!, it's not correct to send ctrl-shift-! Because the shift was "used up". This becomes more complicated with bindings where control or alt modify the character. I don't know if it's possible, but an api which allows you to compare the values with or without individual (not just all modifiers) modifiers would make this perfect. But that's just my two cents. Amazing improvement regardless |
The intended usage is that you listen to The reason for not putting the modifier info into the |
If I understand you correctly, this is already possible: match event {
Event::WindowEvent {
event: WindowEvent::ModifiersChanged(new_modifiers),
..
} => {
if new_modifiers.contains(winit::keyboard::ModifiersState::CONTROL) {
// Do the thing
}
}
_ => ()
} |
That's not quite the problem. Knowing whether a modifier is held is easy like you've shown. Knowing whether a particular modifier contributed to the selected character is not easy though. Due to a quirk in neovim's keybinding code, shift-{character} is different from {character} so shift-! would be handled differently than ! even though the shift key is necessary to produce the ! character. This problem extends to other modifiers such as ctrl. I'm told that some keyboard layouts require ctrl to input given characters. So the thing that would help is a way to tell if a given modifier contributed to the selection of the resulting character and so should be omitted from the keybinding reporting or if the modifier could have been omitted to produce the same character. I don't know if such an api is possible on all platforms so it may be a moot point but I figured I'd ask and see |
That is true, in fact I doubt it's possible on macOS or Windows. However, assuming that all active modifiers contributed to the generated character could be a useable approximation. Also note that on desktop platforms you have access to the pressed key as if there was no modifiers active, using If I understand correctly, you have keybindings that you want to trigger in response to the corresponding input. And you want to allow this "corresponding input" to be either
I don't understand why 2 is a requirement. For example I would not expect that my ctrl+A keybinding gets triggered when I press cmd+ctrl+A. In fact I would hope it doesn't get triggered in that case. In any case, if you want to allow 2, then what you could do, is to check if the current input is exactly the same as the specified binding, then remove cmd from the current input and check if it matches the binding that way. This assumes that cmd is the only key which doesn't influece the pressed key but that could be a decent approximation for your use case. |
Interesting can you elaborate on what you mean by remove the modifier? Are you suggesting I construct a new key event somehow? |
I think you mean submit the keybinding to neovim with and without the modifier? I think the conclusion I'm coming to is that a change needs to happen in neovim to handle with and without bindings the same. I will think some more on whether that's possible. From neovim's perspective, they can't know whether a key used modifiers to produce a given character, so they have to assume that shift-! shouldn't be handled the same as ! because a given keyboard layout may input the ! without it. I guess what I sorta need is an api to look up predicively what a given set of keys would produce. Again though that might not be possible... |
Alright it took me a while, but I think now I understand what you want to achieve. Correct me if I'm wrong but what you want seems to be that Shift+1=
Something similar is probably possible on desktop platforms, but I would like to merge the current API into |
1ef0b49
to
54bb969
Compare
Sooo.... is the code on this branch still a candidate for (The folks from the neovide project would like to use the new keyboard API.) Thank you! |
closing as we have mono branch. |
cargo fmt
has been run on this branchcargo doc
builds successfullyCHANGELOG.md
if knowledge of this change could be valuable to usersThis is the macOS implementation of #753 and it also brings the Android backed up to date with the new API.
This should be merged after #1788.
Side-note: the IME implementation is based on #1669 but as I don't know any language which naturally uses IME, it's difficult for me to know if what I ended up implementing is correct.