-
Notifications
You must be signed in to change notification settings - Fork 912
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
The Key
enum: categories, extension, commands (shortcuts)
#2995
Comments
I like the idea of categorizing the Supporting shortcuts would be a worthwhile addition imo and I'm in favor of adding that. This might be an incentive to add categorization instead of either adding commands to All in all I'm not particularly in favor of categorizing |
@daxpedda you usually handle them together though, because you have a general
No, it shouldn't, it a subject to an application to handle that, winit can't decide what combination could possibly mean. Probably having a |
Noting that we want to integrate with |
True. There don't appear to be any recent changes to |
I am not following in detail how winit is progressing, however these are my 2 cents. For matching shortcuts I suggest you have a look at this simple matcher, which is part of keyboard-types: https://docs.rs/keyboard-types/latest/keyboard_types/struct.ShortcutMatcher.html
You should absolutely not share values between |
Yeah, I agree. There's no reason to merge the physical keys with normal keys, they don't make any sense. We don't do any shortcuts in winit, downstream clients do that with all the freedom they have. |
Some of my questions are resolved:
To return to question 2, being able to define an app-specific enum If we agree I am happy to make PRs, otherwise this issue can be closed. @pyfisch's |
I'm not sure about that one tbh, but I could see a desire to do things like that. The main issue is that it could complicate matching, though, not that much... |
Additional motivation: I wish to cleanly write a custom serialiser for pub enum Key<Str = SmolStr> {
Action(Action),
Character(Str),
Unidentified(NativeKey),
Dead(Option<char>),
}
Especially given that matching will mostly be concerned with things like |
Split `Key` into clear categories, like `Named`, `Dead`, Character`, `Unidentified` removing the `#[non_exhaustive]` from the `Key` itself. Similar action was done for the `KeyCode`. Fixes: rust-windowing#2995 Co-authored-by: Kirill Chibisov <[email protected]>
Split `Key` into clear categories, like `Named`, `Dead`, Character`, `Unidentified` removing the `#[non_exhaustive]` from the `Key` itself. Similar action was done for the `KeyCode`. Fixes: #2995 Co-authored-by: Kirill Chibisov <[email protected]>
This is partly beyond the scope of Winit but deserves a little discussion. See also #1806 and the many prior discussions (too many to easily navigate). Also pyfisch/keyboard-types#19
Key
replaces the oldVirtualKeyCode
as a listing of named keys. The main difference, besidesKey
being much larger and based on a different standard is thatKey
includesCharacter(Str)
,Unidentified(NativeKey)
andDead(Option<char>)
super-categories.Categories
The W3C standard categorises "named keys" into:
Key
includesSpace
; W3C standard does not)Key
includes up to F35), Soft1-4Omissions
This is a big list with a lot of categories, yet still omits some things:
Key::Character
: typed textKey::Dead
: usually the start of a key-combo sequenceViewUp
/ViewDown
,WordLeft
/WordRight
,Italic
,Bold
,Underline
,Link
Find
is included (under UI keys) butFindNext
,FindPrevious
,FindReplace
are notFullscreen
Related: shortcut mapping
Somehow an app needs to match combos like Ctrl+C (which could be mapped to
Key::Copy
) and Ctrl+Left / Alt+Left / Command+Left (which could be mapped toKey::WordLeft
if this were added).So far, I have been using a different enum for this,
Command
. The result: much repetition and repetitive matching, yet with many omissions.As an alternative, I could use a much reduced
Command
enum like this:Caveat: if e.g.
FindNext
were in the future added toKey
, this enum would need a breaking change.Caveat: values like
Command::Key(Key::Find)
have long names making matching tedious.Questions
Should
Key
categorise its values? If so, some values could be shared with thePhysicalKey
enum, and some key mapping operations may be easier, but there isn't a large incentive to make changes here. (And a dis-incentive: matching e.g.Key::Multimedia(MultimediaKey::Open)
is tedious with non-obvious category.)Should, instead, all "named keys" be placed under another
NamedKey
enum?Should
Key
be extended to include things likeWordLeft
,FindNext
,Fullscreen
? These are not known keys (though they almost could be), but are common UI functionality and shortcut targets.The text was updated successfully, but these errors were encountered: