-
Notifications
You must be signed in to change notification settings - Fork 905
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Split Winit up into multiple crates #3433
Comments
Is there any interest in splitting We would also need to incorporate #2395 as we already included that change in our fork which was implemented based on #2148. |
Hmm, I guess that actually makes a lot of sense - and it might even be useful for I've reserved the crate name |
I'd be happy to help with the migration if there is a repo I can contribute to, or should it live within this repo? |
I'll bring it up in our meeting on friday, then I'll get back to you with a plan. |
We talked about it, and don't really think we want to pull in the extra dependency for I think we agreed on doing the split like I described in #3455 (comment), have put up #3518 to move the module, then you're free to submit PRs to improve that afterwards. |
Hey, thank you for this initiative. Do you think a split like this would enable us to use winit types (like keycodes) independently from winit and in external APIs. I am finding winits input and event types, especially the KeyCode to be massively beneficial to use in e.g game engine or ui library public APIs rather than re-defining the enum and using Would this be a usecase you would be willing to support, I.e; using winit even types in the API (I am ok with breaking changes and refactors, just as long as I can use these in an API) :) |
Given that the |
just wondering if part of this would include a way to access the event loop types and os types in a another crate. |
One set of backends this would enable that would be particularly useful are dummy/proxy backends that could be used for:
|
We have discussed this before and we do have a plan to allow other crates to offer plugin-like interfaces that users can hook up. Definitely something we will be investigating in more detail when its time to make the change. Right now its not an issue because |
is there any public discussions as to why this is? |
I'm not following exactly where you are going with this. With current Winit, I'm unsure how exposing the types (its internals) would make any sense. Mostly their internals are backend specific anyway, so I'm unsure how anybody would make use of it. For future Winit: we have talked about reusability a lot. There it makes much more sense, because we want to allow external backends and split the crate as discussed in this issue. So internal access is actually a requirement. However we should also make sure that the top-level crate doesn't actually allow internal access, otherwise it would all just be very terrible to use and probably But if you have a specific suggestion with a specific use-case in mind for current Winit, let us know! |
@daxpedda A concrete use case I have is for a generic "text editor" library that implements a textbox widget with full support for layout, selection, rendering, and responding to input events. We would like to make use of Winit's keyboard and IME event types, but we don't want the crate to depend on Winit because:
As far as I can see this would work great today if the relevant types were published in their own crate as all the fields are already public. Code: linebender/parley#88 |
The main problem with such approaches is that you can not really encode everything in single Though, what I'm saying is mostly for keyboard input, and maybe for that part you can define your own type. The current type in winit, for example, is not covering all the use cases on dekstop, since it's hard to do shortcuts with it. In general though, you should be able to use types in the future, since the core stuff won't depend on anything, so even if you pull a bit more traits, it'll still be relatively slim to use, so you could just pull the entire thing. The end layout is anyway outlined in the issue description, and This also means that you can bring whatever you want as long as it'll implement |
its used in the tray icon code i linked to. many people have wanted tray support directly in winit but it has been closed as not wanted(which im perfectly fine with). my suggestion is having an advanced feature or whatever that allow libraries to use platform dependent code. as well as in internal types |
this file shows the windows tray icon i built. which uses these internal types use crate::{
dpi::PhysicalPosition,
error::OsError as RootOsError,
event::Event,
platform_impl::platform::{event_loop::ProcResult, WindowId, DEVICE_ID},
tray::TrayBuilder,
window::{Icon, WindowId as RootWindowId},
};
use super::{
event_loop::{runner::EventLoopRunnerShared, DESTROY_MSG_ID},
util, EventLoopWindowTarget,
}; |
See @n1ght-hunter looking at your tray implementation I don't believe this is a "I don't have access to internal types" issue, you need access to the internal event loop to integrate your tray in. This seems to be an entirely different issue to me, probably more like #2120. Let me know if I missed anything! |
@daxpedda didn't want to overload this issue so moved to discussion |
I'd like to help push this along. Is there anything I could potentially start work on? |
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 thewinit
crate.A rough implementation plan could be:
winit-core
crate, which contains the common types that all backends use (likedpi
and keyboard types)winit-core
, but still have the mainwinit
crate "merge" these backends withcfg
s, not with a trait.winit-core
, that implements the desired functionality, and move each backend to also implement those traits.winit
crate to an API that is notcfg
-based, butdyn Trait
-based.winit-common
crate to have shared functionality between the crates, which will be intended for winit internal usage and help writing new backends.@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.
The text was updated successfully, but these errors were encountered: