The following approach is a bit convoluted, but it is what I'd use. It should be robust even when there is complex interaction between the window manager and GTK+ when a window is mapped -- for example, when some of the panels are automatically hidden.
The basic idea is to create a transparent decorationless maximized window for each screen, obtain its geometry (size and position) when it gets mapped (for example, using a map-event
callback), and immediately destroy them. That gets you the usable area within each screen. You can then use your existing gdk_screen_get_monitor_geometry()
approach to determine how the usable area is split between monitors, if any.
In detail:
Use gdk_display_get_default()
to get the default display, then gdk_display_get_n_screens()
to find out how many screens it has.
Create a new window for each screen using gtk_window_new()
, moving the windows to their respective screens using gtk_window_set_screen()
. Undecorate the windows using gtk_window_set_decorated(,FALSE)
, maximuze them using gtk_window_maximize(,TRUE)
, and make them transparent using gtk_window_set_opacity(,0.0)
. Connect the map-event
signal to a callback handler (using g_signal_connect()
). Show the window using gtk_widget_show()
.
The signal handler needs to call gtk_window_get_position()
and/or gtk_window_get_size()
to get the position and/or size of the newly-mapped window, and then destroy the window using gtk_widget_destroy()
.
Note that in practice, you only need one window. I would personally use a simple loop. I suspect that due to window manager oddities/bugs, it is much more robust to create a new window for each screen, rather than just move the same window between screens. It turns out it is easier, too, as you can use a single simple callback function to obtain the usable area for each screen.
Like I said, this is quite convoluted. On the other hand, a standard application should not care about the screen sizes; it should simply do what the user or window manager asks. Because of that, I would not be surprised if there are no better facilities to find out this information. Screen size may change at any point, for example if the user rotates their display, or changes the display resolution.