-
Notifications
You must be signed in to change notification settings - Fork 909
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 various fixes #2817
New keyboard various fixes #2817
Conversation
src/keyboard.rs
Outdated
/// Each flag represents a modifier and is set if this modifier is active. | ||
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
pub struct ModifiersState { | ||
pub(crate) flags: ModifiersStateFlags, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how PartialEq
and Eq
should work here. Internally in winit we want to compare by each field, but users might not want such a thing and instead compare just shift
/alt
, etc.
The `OptionAsAlt` could be easily implemented in the user code if they want to. The ralt/lalt will be optionally exposed in the `ModifiersState` event.
I don't use macOS regularly so every time this Option/Alt question comes up, I have to do a small research to remember what this is about. The way I understand it is the following: With some keyboard layouts, holding down the Option key and pressing another key allows users to produce special characters. However, some applications have keyboard shortcuts that are bound to Option+another key. With the previous keyboard API, winit only reported the special character and not the original key, which prevented the shortcut from being triggered. This is why we needed Is this correct? |
Yes. |
I think I don't like the current impl of left/right modifiers and they way the struct is ending up used downstream. I'll rewrite it to be as a separate field instead. |
Rewrote the way the |
I've also removed the deprecated @daxpedda could you ensure that I haven't broke the web by doing so? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MacOS impl looks good, nice to have the OptionAsAlt
removed, better that it can now be implemented outside of winit
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Web is fine, though I found that if you hold down both left and right of any modifier key and you release only one, it will report that no modifier keys are active, even though you are holding one down. Though this isn't an issue with this PR, it's already one with #2662, I will fix it there.
So this PR LGTM!
@daxpedda have you tested the case when you hold the modifier before focusing the browser and simply move the mouse over it? |
Provide additional metadata when possing along side the `ModifiersState` as in which keys were pressed resulting in modifiers change. This also removes deprecated modifiers bits on the Mouse events and fixes redox impl of not sending this event.
I think it was re-iterated and your latest commit addresses all of that. |
Modifiers on WebChanges
Failed Solution 1Why we don't "track" modifiers over keyboard and mouse events while the window isn't in focus? Failed Solution 2Trying to resolve the solution outlined above, we could track modifiers while the canvas isn't in focus but the browser window is, but clear modifiers if the browser window loses focus to avoid getting modifiers stuck when the window loses focus. Unfortunately this doesn't really provide any advantage, because the only way a canvas can regain focus without having lost the browser window focus is with a keyboard or mouse event (unless you do it over scripting, which is becoming increasingly insane). ConclusionI wish I could explain any of this better, but this is all very convoluted and the Web APIs are quite limiting. The conclusion is that there is really no perfect way to have a correct modifier state when regaining the browser window focus, we will have to wait until we get a keyboard or mouse event. |
Leaving #2817 (comment) here for future reference. |
This should make repeat behavior consistent with other apps.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding the left/right modifiers reporting, I personally think the commented out portions of ModifiersState
can be used in a sensible manner to support left/right modifiers (i.e. SHIFT = LSHIFT | RSHIFT
, but SHIFT
can be set regardless of whether we support distinguishing between left and right). The way you've implemented is also serviceable, but I'd like to have a rationale for why this way would be preferred.
The wasm changes appear to work as intended, as far as I can tell, so that's nice.
Other than that, I only have a couple of nits.
|
||
// NOTE: Currently pressed modifiers keys. | ||
// | ||
// The field providing a metadata, it shouldn't be used as a source of truth. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// The field providing a metadata, it shouldn't be used as a source of truth. | |
// The field provides metadata, and shouldn't be used as a source of truth. |
nit
On some platforms you could have modifier change without any key press at all, so left/right can't be determined by any means. Only macOS supports such a thing and only macOS requires this API anyway, because they have broken modifiers input (Option and not AltGr). |
The main highlight is modifiers event rework.