Avalonia icon indicating copy to clipboard operation
Avalonia copied to clipboard

Drawing content over NativeControlHost

Open Symbai opened this issue 2 years ago • 10 comments

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.

Symbai avatar Sep 16 '21 10:09 Symbai

@kekekeks is airhack possible on macos/linux?

maxkatz6 avatar Oct 15 '21 01:10 maxkatz6

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.

kekekeks avatar Oct 16 '21 08:10 kekekeks

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?

Symbai avatar Oct 16 '21 08:10 Symbai

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

kekekeks avatar Oct 16 '21 21:10 kekekeks

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.

kekekeks avatar Oct 16 '21 21:10 kekekeks

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

Geektoolkit avatar Feb 22 '22 10:02 Geektoolkit

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 ...

Sorien avatar Feb 22 '22 13:02 Sorien

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

Geektoolkit avatar Mar 06 '22 07:03 Geektoolkit

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.

Synirrr avatar May 06 '22 14:05 Synirrr

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

radiolondra avatar Sep 22 '22 16:09 radiolondra