Part of #3367, opening to discuss separately.
Winit is designed around a single crate with a specific set of backends, which is great for users that can use that, but there is a need for other backends that are not implemented in Winit today, like GTK. Additionally, the backend-specific extensions that we do have usually constrain some other part of the design.
So it would probably be useful to try to split Winit into multiple smaller crates (though still in the same repository), to ease doing this work. The top-level winit crate would still remain.
Along with this, we'd want a way to write out-of-tree backends, and allow the user to integrate them into their application. This could probably be solved by introducing internal / "backend" traits, and keep a dyn in structures inside the winit crate.
A rough implementation plan could be:
@kchibisov: I've tried to fairly faithfully reproduce what I felt was the important points from #3367, but please edit this issue description with your own.
EDIT: Implementation history:
Part of #3367, opening to discuss separately.
Winit is designed around a single crate with a specific set of backends, which is great for users that can use that, but there is a need for other backends that are not implemented in Winit today, like GTK. Additionally, the backend-specific extensions that we do have usually constrain some other part of the design.
So it would probably be useful to try to split Winit into multiple smaller crates (though still in the same repository), to ease doing this work. The top-level
winitcrate would still remain.Along with this, we'd want a way to write out-of-tree backends, and allow the user to integrate them into their application. This could probably be solved by introducing internal / "backend" traits, and keep a
dynin structures inside thewinitcrate.A rough implementation plan could be:
winit-corecrate, which contains the common types that all backends use (likedpiand keyboard types)winit-core, that implements the desired functionality, and move each backend to also implement those traits.winitcrate to an API that is notcfg-based, butdyn Trait-based.winit-commoncrate to have shared functionality between the crates, which will be intended for winit internal usage and help writing new backends.winit-core, but still have the mainwinitcrate "merge" these backends withcfgs, not with a trait.@kchibisov: I've tried to fairly faithfully reproduce what I felt was the important points from #3367, but please edit this issue description with your own.
EDIT: Implementation history:
dyntraits:CustomCursorto bedyn#4163MonitorHandleto store dyn object #3927Windowtodyn Window#3857Iconto bedyn#4182EventLoopProvider#4221dummy()fromWindowIdandDeviceIdand useOption<DeviceId>#3864WindowIdinto a single type in the core crate #3902DeviceId::{into,from}_raw#3941as_innerhelper method on trait objects #4160EventLoopExt*towinit-core#4228winit-common#4241winit-android#4250winit-appkit#4248winit-orbital#4243winit-uikit#4242winit-web#4249winit-win32#4247winit-wayland#4252winit-x11#4253serdeis properly enabled throughout: TODO