#include #include static gint num_monitors; static void request (GtkWidget *widget, GdkEventMotion *event, gpointer user_data) { gchar *str; gint i = gdk_screen_get_monitor_at_window (gtk_widget_get_screen (widget), widget->window); if (i < 0) str = g_strdup ("Not on a monitor "); else { GdkRectangle monitor; gdk_screen_get_monitor_geometry (gtk_widget_get_screen (widget), i, &monitor); str = g_strdup_printf ("" "Monitor %d of %d\n" "Width - Height : (%d,%d)\n" "Top left coordinate : (%d,%d)",i+1, num_monitors, monitor.width, monitor.height, monitor.x, monitor.y); } gtk_label_set_markup (GTK_LABEL (user_data), str); g_free (str); } int main (int argc, char *argv[]) { GtkWidget *window, *label, *vbox, *button; GdkScreen *screen; gint i; gtk_init (&argc, &argv); screen = gdk_screen_get_default (); num_monitors = gdk_screen_get_n_monitors (screen); if (num_monitors == 1) g_warning ("The default screen of the current display only has one monitor."); for (i=0; i" "Monitor %d of %d\n" "Width - Height : (%d,%d)\n" "Top left coordinate : (%d,%d)",i+1, num_monitors, monitor.width, monitor.height, monitor.x, monitor.y); gtk_label_set_markup (GTK_LABEL (label), str); g_free (str); button = gtk_button_new_with_label ("Close"); g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (gtk_main_quit), NULL); g_signal_connect (G_OBJECT (window), "configure-event", G_CALLBACK (request), label); vbox = gtk_vbox_new (TRUE, 1); gtk_container_add (GTK_CONTAINER (window), vbox); gtk_container_add (GTK_CONTAINER (vbox), label); gtk_container_add (GTK_CONTAINER (vbox), button); gtk_widget_show_all (window); } gtk_main (); return 0; }