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, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
25 static gint num_monitors;
26 static gint primary_monitor;
29 request (GtkWidget *widget,
33 GdkScreen *screen = gtk_widget_get_screen (widget);
34 gint i = gdk_screen_get_monitor_at_window (screen,
35 gtk_widget_get_window (widget));
38 str = g_strdup ("<big><span foreground='white' background='black'>Not on a monitor </span></big>");
43 gdk_screen_get_monitor_geometry (screen,
45 primary_monitor = gdk_screen_get_primary_monitor (screen);
47 str = g_strdup_printf ("<big><span foreground='white' background='black'>"
48 "Monitor %d of %d</span></big>\n"
49 "<i>Width - Height </i>: (%d,%d)\n"
50 "<i>Top left coordinate </i>: (%d,%d)\n"
51 "<i>Primary monitor: %d</i>",
53 monitor.width, monitor.height,
58 gtk_label_set_markup (GTK_LABEL (user_data), str);
63 monitors_changed_cb (GdkScreen *screen,
66 GtkWidget *label = (GtkWidget *)data;
68 request (label, label);
72 main (int argc, char *argv[])
74 GtkWidget *window, *label, *vbox, *button;
78 gtk_init (&argc, &argv);
80 screen = gdk_screen_get_default ();
82 num_monitors = gdk_screen_get_n_monitors (screen);
83 if (num_monitors == 1)
84 g_warning ("The default screen of the current display only has one monitor.");
86 primary_monitor = gdk_screen_get_primary_monitor (screen);
88 for (i = 0; i < num_monitors; i++)
93 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
95 gdk_screen_get_monitor_geometry (screen, i, &monitor);
96 gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);
97 gtk_window_move (GTK_WINDOW (window), (monitor.width - 200) / 2 + monitor.x,
98 (monitor.height - 200) / 2 + monitor.y);
100 label = gtk_label_new (NULL);
101 str = g_strdup_printf ("<big><span foreground='white' background='black'>"
102 "Monitor %d of %d</span></big>\n"
103 "<i>Width - Height </i>: (%d,%d)\n"
104 "<i>Top left coordinate </i>: (%d,%d)\n"
105 "<i>Primary monitor: %d</i>",
107 monitor.width, monitor.height,
108 monitor.x, monitor.y,
110 gtk_label_set_markup (GTK_LABEL (label), str);
112 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, TRUE, 1);
113 gtk_container_add (GTK_CONTAINER (window), vbox);
114 gtk_container_add (GTK_CONTAINER (vbox), label);
115 button = gtk_button_new_with_label ("Query current monitor");
116 g_signal_connect (button, "clicked", G_CALLBACK (request), label);
117 gtk_container_add (GTK_CONTAINER (vbox), button);
118 button = gtk_button_new_with_label ("Close");
119 g_signal_connect (button, "clicked", G_CALLBACK (gtk_main_quit), NULL);
120 gtk_container_add (GTK_CONTAINER (vbox), button);
121 gtk_widget_show_all (window);
123 g_signal_connect (screen, "monitors-changed",
124 G_CALLBACK (monitors_changed_cb), label);