2 * Copyright (C) 2001 Sun Microsystems Inc.
3 * Author: Erwann Chenede <erwann.chenede@sun.com>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
23 static gint num_monitors;
24 static gint primary_monitor;
27 request (GtkWidget *widget,
31 GdkScreen *screen = gtk_widget_get_screen (widget);
32 gint i = gdk_screen_get_monitor_at_window (screen,
33 gtk_widget_get_window (widget));
36 str = g_strdup ("<big><span foreground='white' background='black'>Not on a monitor </span></big>");
41 gdk_screen_get_monitor_geometry (screen,
43 primary_monitor = gdk_screen_get_primary_monitor (screen);
45 str = g_strdup_printf ("<big><span foreground='white' background='black'>"
46 "Monitor %d of %d</span></big>\n"
47 "<i>Width - Height </i>: (%d,%d)\n"
48 "<i>Top left coordinate </i>: (%d,%d)\n"
49 "<i>Primary monitor: %d</i>",
51 monitor.width, monitor.height,
56 gtk_label_set_markup (GTK_LABEL (user_data), str);
61 monitors_changed_cb (GdkScreen *screen,
64 GtkWidget *label = (GtkWidget *)data;
66 request (label, label);
70 main (int argc, char *argv[])
72 GtkWidget *window, *label, *vbox, *button;
76 gtk_init (&argc, &argv);
78 screen = gdk_screen_get_default ();
80 num_monitors = gdk_screen_get_n_monitors (screen);
81 if (num_monitors == 1)
82 g_warning ("The default screen of the current display only has one monitor.");
84 primary_monitor = gdk_screen_get_primary_monitor (screen);
86 for (i = 0; i < num_monitors; i++)
91 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
93 gdk_screen_get_monitor_geometry (screen, i, &monitor);
94 gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);
95 gtk_window_move (GTK_WINDOW (window), (monitor.width - 200) / 2 + monitor.x,
96 (monitor.height - 200) / 2 + monitor.y);
98 label = gtk_label_new (NULL);
99 str = g_strdup_printf ("<big><span foreground='white' background='black'>"
100 "Monitor %d of %d</span></big>\n"
101 "<i>Width - Height </i>: (%d,%d)\n"
102 "<i>Top left coordinate </i>: (%d,%d)\n"
103 "<i>Primary monitor: %d</i>",
105 monitor.width, monitor.height,
106 monitor.x, monitor.y,
108 gtk_label_set_markup (GTK_LABEL (label), str);
110 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 1);
111 gtk_box_set_homogeneous (GTK_BOX (vbox), TRUE);
112 gtk_container_add (GTK_CONTAINER (window), vbox);
113 gtk_container_add (GTK_CONTAINER (vbox), label);
114 button = gtk_button_new_with_label ("Query current monitor");
115 g_signal_connect (button, "clicked", G_CALLBACK (request), label);
116 gtk_container_add (GTK_CONTAINER (vbox), button);
117 button = gtk_button_new_with_label ("Close");
118 g_signal_connect (button, "clicked", G_CALLBACK (gtk_main_quit), NULL);
119 gtk_container_add (GTK_CONTAINER (vbox), button);
120 gtk_widget_show_all (window);
122 g_signal_connect (screen, "monitors-changed",
123 G_CALLBACK (monitors_changed_cb), label);