AvaloniaUI / Avalonia

Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The most popular .NET UI client technology
https://avaloniaui.net
MIT License
25.22k stars 2.18k forks source link

Drawing content over NativeControlHost #6605

Open Symbai opened 2 years ago

Symbai commented 2 years ago

Is your feature request related to a problem? Please describe. Currently it is not possible to draw content over NativeControlHost. But it is possible on WPF (using airhack), so it would be nice if we can add controls which renders above NativeControlHost.

Describe the solution you'd like ^ See above

Describe alternatives you've considered I haven't found any

Additional context On WPF this can be done using modified second WPF Window with some transparency and tracking of parent See https://github.com/kolorowezworki/Airhack Or https://code.videolan.org/videolan/LibVLCSharp/-/blob/3.x/src/LibVLCSharp.WPF/ForegroundWindow.cs However WPF uses a different rendering engine. So maybe Avalonia can already render over native controls and it just needs some code changes, or Avalonia is unable to. Unfortunately I have no idea how Avalonia's rendering works and also unable to port the airspace hack from WPF.

maxkatz6 commented 2 years ago

@kekekeks is airhack possible on macos/linux?

kekekeks commented 2 years ago

It might be, but I'd rather not have something like this in the core repository. Especially since window transparency can be turned off and on system-wide under certain circumstances on Linux.

Symbai commented 2 years ago

Instead of airhack isn't it possible for Avalonia to just draw Avalonia controls on top of it (since your rendering engine is self made right?)? Or is the NativeControlHost a 1:1 copy of WPF?

kekekeks commented 2 years ago

NativeControlHost places native controls over Avalonia content just like WPF one does. So it suffers from the same airspace problem.

kekekeks commented 2 years ago

Well, with Win8+ we could use WS_EX_LAYERED for child windows. This would provide a transparent child window at the top of embedded one. However WS_EX_LAYERED is awfully slow. For OSX we could do the same with NSView since NSView supports transparency out of the box. X11 is more tricky, but we could use XComposite extension to act as a compositing window manager for our own child windows. I did an experiment with scaling a Wine app embedded into QWidget back in 2012 and it worked quite well. So technically, with X11 we can redirect embedded window content to a normal Avalonia control and even control mouse events for completely seamless integration.

Geektoolkit commented 2 years ago

Would this enable overays on top of VLCSharp? It'd be really handy to be able to overlay UI on top of VLC playback, which from what I can tell is using this control

Sorien commented 2 years ago

I thought that you should be able to get frame data and copy it to the image or there should be some kind of texture sharing ... first video players were using some transparent window for subtitles displaying like 20 years ago ...

Geektoolkit commented 2 years ago

I can get the frame data but haven't found how to inject into it. But ideally the vlc control that supports avalonia would allow for controls placed on top of it without having to edit the frame data which would be much more user friendly (and similar to how WPF handled things). I just realized this is linked from: https://code.videolan.org/videolan/LibVLCSharp/-/issues/408 but I'm not clear on the status of either or if there's a solution. I see alot of mentions of creating windows, but I'm not clear on if I can put a window on top of VLC when it's in full screen mode

Synirrr commented 2 years ago

Well, with Win8+ we could use WS_EX_LAYERED for child windows. This would provide a transparent child window at the top of embedded one. However WS_EX_LAYERED is awfully slow. For OSX we could do the same with NSView since NSView supports transparency out of the box. X11 is more tricky, but we could use XComposite extension to act as a compositing window manager for our own child windows. I did an experiment with scaling a Wine app embedded into QWidget back in 2012 and it worked quite well. So technically, with X11 we can redirect embedded window content to a normal Avalonia control and even control mouse events for completely seamless integration.

This would enable amazing functionality. Right now the inability to propagate mouse events or boundry events really limits what you can do with embedded windows using the NativeControlHost.

radiolondra commented 1 year ago

Please give a look to my posts here for a possible solution. Cheers.