-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Labels
C - needs discussionDirection must be ironed outDirection must be ironed outS - apiDesign and usabilityDesign and usability
Milestone
Description
Part of #3367, opening to discuss separately.
Winit needs some way for the user to synchronously respond to events with a value.
Prominent examples include:
- the dead key API (it goes via globals now).
- Deal with scale factor changes/configure races on Wayland #2921
- Allow some events to perform cancellation. #3349
- Support
Backbutton/KeyCodeon Android #2304 (requires saying that you've handled, otherwise you'll block everything) - Guarantee sending WindowEvent::Resized on window creation? #3192 (you need to ask during window creation)
- Clipboard APIs (we need to pick mime-type), the same with DND.
- Live resizes (when you can adjust the size during resize).
To do this, we propose allowing the user to implement a trait, where each method is a callback that will be called when a certain event happens. Roughly:
// API
pub trait ApplicationHandler {
fn new_events(&mut self, event_loop: ActiveEventLoop<'_>, start_cause: StartCause);
fn resized(
&mut self,
event_loop: ActiveEventLoop<'_>,
window_id: WindowId,
size: PhysicalSize<u32>
) -> bool;
// ... Further events
}
// User code
struct App {
window: Option<Window>,
}
impl Application for App { ... }
fn main() {
event_loop.run(App { window: None })?;
}Feel free to update this code-block once we narrow down the actual API.
Identified problems to which we need some sort of solution:
- It is hard to implement middleware / "mini-batching". Prominent example:
egui-winitson_window_event. - How do we allow
dbg!(event)and similar logging that access all events. - How do we allow platform-specific / backend-specific events? Related: Platform-Specific Enum Variants #3064 and Platform specific traits and requests extensions #3474.
- TODO: Further problems???
Implementation plan:
- Create new user-facing handler trait
ApplicationHandler, while still keeping theEvent-based API around to ease transition. Initial work in Begin transition to a trait-based system #3386. - Change backends such that they do not (unnecessarily) queue events.
- macOS
- iOS
- Windows
- Web
- Wayland
- Move each backend to these traits internally. Example in Example of migrating backends to
ApplicationHandler#3387. - Implement APIs that require feedback from the user, like clipboard.
Metadata
Metadata
Assignees
Labels
C - needs discussionDirection must be ironed outDirection must be ironed outS - apiDesign and usabilityDesign and usability