unoplatform / uno

Build Mobile, Desktop and WebAssembly apps with C# and XAML. Today. Open source and professionally supported.
https://platform.uno
Apache License 2.0
8.59k stars 694 forks source link

[X11] Add support for get the Uno's X11 window IntPtr #17194

Open lindexi opened 2 weeks ago

lindexi commented 2 weeks ago

What would you like to be added

Add support for get the Uno's X11 window IntPtr

Why is this needed

Now, we can use GetNativeWindow to get the Uno native window. But The GetNativeWindow will return the internal Uno.WinUI.Runtime.Skia.X11.X11Window type on X11 platform. And we can not easy to use it without reflection:

#if HAS_UNO
        var x11Window = unoWindow.GetNativeWindow()!;
        var x11WindowType = x11Window.GetType();

        var x11WindowIntPtr =
            (IntPtr) x11WindowType.GetProperty("Window", BindingFlags.Instance | BindingFlags.Public)!.GetMethod!.Invoke(
                x11Window, null)!;
#else

You can find the above code in my demo: https://github.com/lindexi/lindexi_gd/tree/0f1d39d4f2bde2e60d790cb14302b5397ca0ae9c/UnoDemo/ChuchejairqaibalNallnowequyalgaw

For which platform

Skia.X11

Anything else we need to know?

No response

ramezgerges commented 2 weeks ago

@lindexi I'm curious, what use case do you have for this?

lindexi commented 2 weeks ago

Thank you @ramezgerges . I use it to set the owner window, and move the window now.

Set the owner window: XSetTransientForHint(Display, a, b);

Move window: XMoveWindow(display, handle, x, y);

jeromelaban commented 2 weeks ago

@lindexi thanks. Do you need those two APIs because there are missing APIs in Uno?

lindexi commented 2 weeks ago

@jeromelaban Yeah, and I fire the issues here: https://github.com/unoplatform/uno/issues/17098

But the XSetTransientForHint is the same behavoir as WPF's Window.Owner

jeromelaban commented 2 weeks ago

Great, thanks!