rust-windowing / rust-windowing/winit
Simplify and consolidate modifiers API
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 6.2k
- Forks
- 1.3k
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 9
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with winit's event::Modifiers API in the docs and review the Windows side-aware modifier context from issue 3611. Define a consolidated bitflag interface for paired modifiers, including how unknown side information is represented; done means side-aware and side-agnostic checks share one consistent, non-nested API.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- desktop
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100