Skip to content
This repository has been archived by the owner on Mar 4, 2024. It is now read-only.

[gdkx11] Get pointer to xlib xdisplay #346

Open
emigr2k1 opened this issue Mar 11, 2021 · 12 comments
Open

[gdkx11] Get pointer to xlib xdisplay #346

emigr2k1 opened this issue Mar 11, 2021 · 12 comments
Labels

Comments

@emigr2k1
Copy link

emigr2k1 commented Mar 11, 2021

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
Copy link
Member

sdroege commented Mar 11, 2021

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

@sdroege sdroege closed this as completed Mar 11, 2021
@emigr2k1
Copy link
Author

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
Copy link
Member

sdroege commented Mar 11, 2021

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 ?

@sdroege sdroege reopened this Mar 11, 2021
@sdroege sdroege added the gdk label Mar 11, 2021
@bilelmoussaoui
Copy link
Member

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

@sdroege
Copy link
Member

sdroege commented Mar 11, 2021

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
Copy link
Member

sdroege commented Mar 11, 2021

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

@bilelmoussaoui
Copy link
Member

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
Copy link
Member

sdroege commented Mar 11, 2021

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

@emigr2k1
Copy link
Author

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 sdroege added this to the 0.14.0 milestone Apr 7, 2021
@sdroege
Copy link
Member

sdroege commented May 9, 2021

@emi2k01 Any updates here?

@bilelmoussaoui
Copy link
Member

Should be very similar to the changes at gtk-rs/gtk4-rs#281 btw :)

@sdroege sdroege removed this from the 0.14.0 milestone Jun 2, 2021
@wusyong
Copy link

wusyong commented Nov 4, 2021

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants