Description
Description
Trying to fix the lack of side-aware data for modifier keys on Windows I've come to realize that the current modifiers APIs are a nest of confusing complications.
Currently you get https://docs.rs/winit/latest/winit/event/struct.Modifiers.html which instead of directly exposing modifier state splits this state into 2 confusingly named state
and pressed_mods
while both refer to exactly the same modifier sate, only one is left/right side-agnostic while the other is side-aware. And while the latter can be queried right away, the former requires and getting the nested bitlfags via a .state()
call
Instead ideally this initial Modifiers struct should already have all the bitflags:
- 2 per paired modifier key: Left and Right
- Checking for a specific side would use side-aware
.lshift()
/.rshift()
functions or be done directly via bitflag checks.contains(Modifiers::LSHIFT)
. - Checking for any side modifier would use a side-agnostic
.shift()
function or be done directly via bitflag checks
(currently shift_key
check is a boolean while lshift_state
check is an enum, think this was to signal the fact that side-aware state is unreliable, though not sure it's worth breaking the API consistency for if all modifiers are consolidated)
Basically this provides exactly the same interface for both side-agnostic and side-aware states and avoids any additional nesting.
In cases when you don't get side-aware information from the OS so you could always store side-unaware state in the Left bitflag (even today side-aware state isn't reliable, so this won't change).
But if for some reason it's very important for the side-aware state to always reflect known reality, then you'd need an extra bit to signal it, so would have 3 bits per paired modifier key: Shift, LeftShift, and RightShift (and L/RShift will NOT be set if Winit doesn't know which key activated Shift)
Relevant platforms
No response