-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Platform-specific event callbacks #2120
Copy link
Copy link
Open
Labels
C - needs discussionDirection must be ironed outDirection must be ironed outDS - androidAffects the Android backendAffects the Android backendDS - appkitAffects the AppKit/macOS backendAffects the AppKit/macOS backendDS - uikitAffects the UIKit backend (iOS, tvOS, watchOS, visionOS)Affects the UIKit backend (iOS, tvOS, watchOS, visionOS)DS - waylandAffects the Wayland backend, or generally free Unix platformsAffects the Wayland backend, or generally free Unix platformsDS - win32Affects the Win32/Windows backendAffects the Win32/Windows backendDS - x11Affects the X11 backend, or generally free Unix platformsAffects the X11 backend, or generally free Unix platformsS - apiDesign and usabilityDesign and usabilityS - enhancementWouldn't this be the coolest?Wouldn't this be the coolest?
Metadata
Metadata
Assignees
Labels
C - needs discussionDirection must be ironed outDirection must be ironed outDS - androidAffects the Android backendAffects the Android backendDS - appkitAffects the AppKit/macOS backendAffects the AppKit/macOS backendDS - uikitAffects the UIKit backend (iOS, tvOS, watchOS, visionOS)Affects the UIKit backend (iOS, tvOS, watchOS, visionOS)DS - waylandAffects the Wayland backend, or generally free Unix platformsAffects the Wayland backend, or generally free Unix platformsDS - win32Affects the Win32/Windows backendAffects the Win32/Windows backendDS - x11Affects the X11 backend, or generally free Unix platformsAffects the X11 backend, or generally free Unix platformsS - apiDesign and usabilityDesign and usabilityS - enhancementWouldn't this be the coolest?Wouldn't this be the coolest?
Issues like #1878, #1928, and #1759 have made it clear that there is a need to hook into platform-specific events that winit itself doesn't (and arguably shouldn't) handle. Ideally, we'd give users the ability to hook into these events with minimal effort, and in a way that doesn't interfere with winit (although some would perhaps like to do that as well).
The simplest solution I can think of to this is to add an
EventLoopBuilderstruct where you can register platform-specific callback functions before the event loop is ever entered. This will make it so that these callbacks don't miss any events, like the file opening events in #1759.Granted, this doesn't lend itself to being a particularly ergonomic API, as any data shared between the platform-specific callbacks and the platform-independent on would have to be behind something like an
Rc<RefCell<T>>or anArc<Mutex<T>>. I think there may exist a solution where sharing such state is easier, but I don't want to spend much energy on that ATM.Another issue is that this will (by necessity) make some projects (like AccessKit) end up depending directly on winit or have to provide an adapter crate. Maybe it could be possible to pull a
raw-window-handleand create some cross-windowing-library interface for this, but I don't think it's ultimately going to be all that feasible.The Windows backend for this should be fairly trivial, so I'll go and implement that soon-ish, unless there are any major concerns with this proposal.
This is on some level related to #2010, but this concerns the public API, rather than the internal one.