gtk-rs / gtk3-rs

Rust bindings for GTK 3
https://gtk-rs.org
MIT License
507 stars 90 forks source link

[gdkx11] Get pointer to xlib xdisplay #346

Open emigr2k1 opened 3 years ago

emigr2k1 commented 3 years ago

I'm trying to use GDK_DISPLAY_XDISPLAY() or gdk_x11_display_get_xdisplay () but I can't find a way to get a raw pointer to the xlib display using gdkx11.

The purpose of this is to use it in raw-window-handle

How can I do it?

Thanks!

sdroege commented 3 years ago

You can get the display by calling https://gtk-rs.org/docs/gdkx11/struct.X11Window.html#method.get_display

emigr2k1 commented 3 years ago

But I need a pointer to the xlib display, something I can use across FFI boundaries for programs that expect an xlib display structure.

I believe get_display only returns a Rust type which is a wrapper around the actual pointer? Unless I'm misunderstanding something.

sdroege commented 3 years ago

It returns an x11::xlib::Display. I don't actually know how to use that or how to get the underlying raw pointer out of that again.

@GuillaumeGomez ?

bilelmoussaoui commented 3 years ago

xlib crate doesn't provide any safe bindings, just raw pointers so that should be fine for your use case?

sdroege commented 3 years ago

How does this even work then? The function returns a Display, not a *mut Display. And Display is an opaque enum Display {} :)

Maybe the function should actually return a *mut Display?

That's also UB btw, enum Display {} has no variants, so there can't be a value of that type and you also can't have a pointer to such a value (because such a value can't exist!). Not our bug, but maybe something to fix in the x11 crate...

sdroege commented 3 years ago

Also why is there no get_display() in git anymore?

bilelmoussaoui commented 3 years ago

Also why is there no get_display() in git anymore?

it was never there https://github.com/gtk-rs/gtk-rs/blob/46ed982c1698e6657e455ebc697cc3596ebb4da0/gdkx11/Gir.toml#L96

sdroege commented 3 years ago

Why does it exist in the docs then: https://gtk-rs.org/docs/gdkx11/struct.X11Window.html#method.get_display ?

emigr2k1 commented 3 years ago

It returns an x11::xlib::Display. I don't actually know how to use that or how to get the underlying raw pointer out of that again.

Oh. I was checking the docs here and here it says it returns a gdk::Display.

I'll see if I can make it work

sdroege commented 3 years ago

@emi2k01 Any updates here?

bilelmoussaoui commented 3 years ago

Should be very similar to the changes at https://github.com/gtk-rs/gtk4-rs/pull/281 btw :)

wusyong commented 3 years ago

I was trying to get the pointer in similar manner this morning. Here's how I did it if anyone is interested https://github.com/wusyong/gtk-widget-in-x11-window/blob/main/src/main.rs#L17