Search code examples
cgtkxlib

C GTK - How to set :display.screen for gtk application window to appear


I am using gtk.h for a C application under GNU/Linux and I would like to open my gtk window under a specific display.screen without exporting any environmental variables. The reason I don't want to set the DISPLAY variable and export it is I don't want to lose control of what was the default display in the first place.

I thought about wrapping the application with an X window and mapping it in the display.screen I want but I dont know if thats a good idea. Right now I am trying to set the display via gdk, but unfortunately I can only get x properties like windowid or current display number with my current knowledge. Also, I dont have a problem with the solution being linux specific.

Another crucial detail about why Im not setting the DISPLAY environmental variable is maybe I want to open multiple gtk windows from the application at :2.0 & :2.1.


Solution

  • It was in the gtk documentation after all, I guess I missed it because I was trying to find a native xlib solution. Here is the related documentation page:

    For GTK 4: https://docs.gtk.org/gtk4/method.Window.set_display.html

    For GTK 2.2 - 3: https://docs.gtk.org/gtk3/method.Window.set_screen.html

    So in the end, you'll have to set GdkDisplay / GdkScreen somehow and pass it to gtk.