Get X Display for GdkDisplay

How can I find out the X Display (Display defined in X header files) that corresponds to a GdkDisplay?

You can use GDK_DISPLAY_XDISPLAY(), from

See the Description section for what you need to do to use that call, and how to make it conditional on the X11 backend.

Chris, thanks,
your reply made me realise my question is lacking. I am using gtk2 in a different language environment, and i’m basically binding to gtk2 myself, so using macros is not an option.
Actually, it seems that my task can be accomplished as simply as:
which is
If only I could somehow figure out the offset of the xdisplay field, that would do. Any ideas what the offset is, or how I could figure it out?

You can call gdk_x11_display_get_xdisplay(), which is defined in gdkx.h.

The real question is why on earth are you writing bindings for GTK2 in 2020.

Thanks a lot, it did the trick!

gtk2 in 2020?

Why wouldn’t I? My whole IDE - compiler, debugger, vaious tool, sophisticated text editor - with several source files open is more compact than the last photo you took on your smartphone - just over 1MB of RAM. It is built with gtk2, and gtk2 does the job it has just fine.

Now, I am adding a feature: I want the keyboard language be indicated by the color of caret in my text editor. Setting the color is no problem; obtaining the keyboard language is a problem.

I figure out the keyboard language by checking GdkKeymapX11.current_group_atom followed by gdk_x11_get_xatom_name(). Works fine as long as I switch the KB lang with a KB shortcut; but when I do it with a mouse thru the language indicator in the system tray, .current_group_atom is not updated. I’ve tried calling gdk_keymap_get_caps_lock_state() and gdk_keymap_get_direction() before checking .current_group_atom - same result.

What do i need to do to know the exact KB language at any given time?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.