-
Notifications
You must be signed in to change notification settings - Fork 920
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
Is it possible to wrap an existing window? #1161
Comments
Afaik, no. |
Thanks for the response. Are you able to provide any detail as to why this isn't supported?
|
Looking at the implementation a bit more, the
Since
Not sure about |
I don't think anyone's needed to do it before. What exactly would be the use case? Would the window be driven with winit's eventloop or be externally driven? I can't imagine this would be an easy task. |
This would be useful for audio plugins (VSTs), since they can only use the raw window handle given to them by the host. |
In a word - interop. My interest just now is mostly in using a Rust library to draw 3D graphics in a non-Rust host application. @Azorlogh's example of VST plugins is another use case.
Using the .NET |
AFAIK the main use for making Winit able to handle foreign windows is so that, when Winit eventually gets a child/embeddable window API, you can parent Winit windows to foreign windows in a sane way. Is that correct? If so, it would probably be easier to have that API take a |
That sounds like another use case. For me it's less about being able to parent a winit-owned window to a foreign window (or vice versa), but rather about being able to access data/events from a foreign window. e.g.
|
I would also like to use winit for my VST work, but I can't switch away from SDL2 until I can create a window from a pub fn build_from_window_ptr<'a, 'b>(
self,
parent: *mut c_void,
) -> Result<Engine<'a, 'b>, String> {
let sdl_context = sdl2::init()?;
let w: *mut sdl2_sys::SDL_Window =
unsafe { sdl2_sys::SDL_CreateWindowFrom(parent as *const c_void) };
let window: sdl2::video::Window = {
let video_subsystem = sdl_context.video()?;
unsafe { sdl2::video::Window::from_ll(video_subsystem, w) }
};
...
Ok(engine)
} |
Is there any path forward here? |
Ey, I'm coming here for the same reason as schell and Azorlogh: working on a VST plugin. Until this is done, it appears the best way to do this is to attempt to something with raw wgpu and re-implement various winit features, which is not ideal. I'd be all for making winit more capable in this way. |
This is something that we will have to provide ourselves. I think a good path forward would be to create a new crate Of course, we could also write this as a patch into the |
This is somewhat difficult to do in real life. For something like X11, it is expected that there is only one event loop handler driving events. So you can't really trivially wrap some other X11 window with a The only one where it's kind of possible is Windows, where the event handler is stored in the window itself. But it requires some finesse and would still be wildly unsafe. |
For Web this is already possible through |
The plugin use-case is that we are given a window handle that doesn't have an event loop on it yet. For other situations I agree that this would be a problem, but it would work in all of the situations it is expected to work (i.e. if something else already ran an event loop, we likely wouldn't be given a window pointer anyway). |
@rdrpenguin04 if you're given with a window you're not the one handling events for it, so you basically have a |
Fair; that was a terminology mistake, as that was entirely what I meant. |
Yeah, then use https://github.com/rust-windowing/raw-window-handle/ which is what is used for such things and what wgpu/glutin use, they don't use |
Let me catch you up. Some plugin APIs, such as VST, pass the application a window handle in some platform-specific manner. If I want to use winit for a VST, I need to create a |
If you don't have event loop winit is useless. If the platform relies on hijacking global events, then winit can't help either and it's not crossplatform anyway. I'm not sure why you need winit in a first place. |
The plugin will be passed a window handle, and it can attach an event loop to that. I would like to use winit specifically to manage the event loop and give useful input abstractions. |
VST plugins are Windows specific, right? Or does it work on other platforms? If so, which ones? |
VST3 is cross-platform, but even VST2 was ported to Linux IIRC. LV2 has a very similar setup, as does clap, and all of these are just audio plugin specifications I know about; I'm sure other types of plugins have similar setups as well. |
And what kind of functionality do you want to access on the window? |
@madsmtm on Wayland you can't do anything like that at all, so it's just straight not working. The only thing you can get is |
Yeah, I was mostly thinking if there is feasibly some sort of platform-specific extension that would make sense for this (like, some of this would be possible on macOS, even though I heavily dislike it), or if we should consider closing the issue as "wontfix" |
Looking at the LV2 specification, the plugin will be given one of the following:
For the GUI extension to clap, the plugin will either be given one of the above or it will declare that it will create its own window, which is required on Wayland. I'm not finding information on VST3's GUI system; I know that VST2 is the same as LV2, but without supporting macOS. My proposal would be simply to accept a |
The problem, as you hinted at yourself, is that this requires a lot of infrastructure changes. Theoretically simple, yes, but the reality is quite different. I can only really speak for the macOS backend here, but there, we have the concept of a root Which in turn means we're quite limited in the events we'd be able to set up. Depends on whether we're allowed to install a new For now though, the platforms you mentioned seems like the same ones In the future, if we do the backend splitting as is discussed in #3367, it might become easier for specific platforms to support this, by exposing their internals? Unsure, and not sure I'd want to take on the maintenance burden of that (supporting windows in more states is always difficult). |
Alright, |
Is it possible to use winit to get a
Window
struct representing an existing window (not created by winit), given aRawWindowHandle
?i.e. an equivalent to the .NET NativeWindow.FromHandle(IntPtr) method
The text was updated successfully, but these errors were encountered: