0

I was wondering how I could get the X11 window ID for a Gtk Window in gtk4. I have seen other answers before regarding gtk3, but they don't seem to work in the latest gtk4. I found gdk_x11_surface_get_xid, but I can't pass a GtkWidget to that. I tried using the GDK_SURFACE cast, but I get:

invalid cast from 'GtkApplicationWindow' to 'GdkSurface'

Is there any way to resolve this, and get the x11 window id from a GtkWindow?

Ank i zle
  • 2,089
  • 3
  • 14
  • 36
  • Could you please add a minimal and reproducible example, so we can see how you are casting? – BobMorane Mar 14 '22 at 10:55
  • Highly related: https://stackoverflow.com/questions/68516898/gtkmm-4-how-to-get-x-window-id-from-inside-widget – BobMorane Mar 14 '22 at 11:17
  • 1
    A `GtkApplicationWindow` *has* a `GdkSurface`, it does not inherit from one, so you cannot cast the former to the latter. Though what you're asking smells like trying to port some *very* old GTK2 or GTK3 code to GTK4, which is usually not trivially possible. You should provide more context and information about what you're trying to achieve. – ebassi Mar 14 '22 at 19:19
  • I was casting using the traditional `GDK_SURFACE(window_widget)` cast. As for what I am trying to do with this, I was experimenting with a bit of low level X11, and wanting to try adding some GTK to the mix, as a test. Also, thank you BobMorane for pointing me to the correct answer! I am now using `gdk_x11_surface_get_xid(gtk_native_get_surface(GTK_NATIVE(window)))` to get an XID from a GTK window widget. – Ank i zle Mar 15 '22 at 02:10

0 Answers0