/* prints out details about screens connected to this X display * compile with: * gcc -o enum-displays enum-displays.c `pkg-config gtk+-2.0 gdk-2.0 --cflags --libs` */ #include #include static void show_display_config (GdkDisplay * gdpy) { gint i, j, nscreens, nmonitors; GdkScreen *gscreen; gchar *display_name; GdkRectangle geom; nscreens = gdk_display_get_n_screens (gdpy); g_print ("This display has %d screen%s.\n\n", nscreens, nscreens > 1 ? "s" : ""); for (i = 0; i < nscreens; ++i) { gscreen = gdk_display_get_screen (gdpy, i); g_print ("Screen %d:\n", i); display_name = gdk_screen_make_display_name (gscreen); g_print (" Name: %s\n Size: %dx%d\n", display_name, gdk_screen_get_width (gscreen), gdk_screen_get_height (gscreen)); g_free (display_name); nmonitors = gdk_screen_get_n_monitors (gscreen); g_print (" %d monitor%s connected:\n", nmonitors, nmonitors > 1 ? "s" : ""); for (j = 0; j < nmonitors; ++j) { gdk_screen_get_monitor_geometry (gscreen, j, &geom); g_print (" Monitor %d: %dx%d+%d+%d\n", j, geom.width, geom.height, geom.x, geom.y); } } } static void monitors_changed_cb (GdkScreen * gscreen, gpointer data) { GdkDisplay *gdpy; gdpy = (GdkDisplay *) data; g_return_if_fail (gdpy); g_warning ("Monitoring changed notification on screen %s\n", gdk_screen_make_display_name (gscreen)); g_print ("New configuration: "); show_display_config (gdpy); } int main (int argc, char **argv) { gint i, nscreens; GdkDisplay *gdpy; GdkScreen *gscreen; gdk_init (&argc, &argv); gdpy = gdk_display_get_default (); show_display_config (gdpy); if (gtk_major_version > 2 || (gtk_major_version == 2 && gtk_minor_version >= 13)) { g_print ("Monitoring monitors changed events, press Ctrl-C to interrupt\n"); nscreens = gdk_display_get_n_screens (gdpy); for (i = 0; i < nscreens; ++i) { gscreen = gdk_display_get_screen (gdpy, i); g_signal_connect (G_OBJECT (gscreen), "monitors-changed", G_CALLBACK (monitors_changed_cb), (gpointer) gdpy); } gtk_main (); } return 0; }