]> Pileus Git - ~andy/gtk/blob - tests/testxinerama.c
8ecca105fd61a6710f6158de23b3654fa6e3b26e
[~andy/gtk] / tests / testxinerama.c
1 /* testmultidisplay.c
2  * Copyright (C) 2001 Sun Microsystems Inc.
3  * Author: Erwann Chenede <erwann.chenede@sun.com>
4  *
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.
9  *
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.
14  *
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.
19  */
20
21 #include "config.h"
22 #include <stdlib.h>
23 #include <gtk/gtk.h>
24
25 static gint num_monitors;
26 static gint primary_monitor;
27
28 static void
29 request (GtkWidget      *widget,
30          gpointer        user_data)
31 {
32   gchar *str;
33   GdkScreen *screen = gtk_widget_get_screen (widget);
34   gint i = gdk_screen_get_monitor_at_window (screen,
35                                              gtk_widget_get_window (widget));
36
37   if (i < 0)
38     str = g_strdup ("<big><span foreground='white' background='black'>Not on a monitor </span></big>");
39   else
40     {
41       GdkRectangle monitor;
42
43       gdk_screen_get_monitor_geometry (screen,
44                                        i, &monitor);
45       primary_monitor = gdk_screen_get_primary_monitor (screen);
46
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>",
52                              i + 1, num_monitors,
53                              monitor.width, monitor.height,
54                              monitor.x, monitor.y,
55                              primary_monitor);
56     }
57
58   gtk_label_set_markup (GTK_LABEL (user_data), str);
59   g_free (str);
60 }
61
62 static void
63 monitors_changed_cb (GdkScreen *screen,
64                      gpointer   data)
65 {
66   GtkWidget *label = (GtkWidget *)data;
67
68   request (label, label);
69 }
70
71 int
72 main (int argc, char *argv[])
73 {
74   GtkWidget *window, *label, *vbox, *button;
75   GdkScreen *screen;
76   gint i;
77
78   gtk_init (&argc, &argv);
79
80   screen = gdk_screen_get_default ();
81
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.");
85
86   primary_monitor = gdk_screen_get_primary_monitor (screen);
87
88   for (i = 0; i < num_monitors; i++)
89     {
90       GdkRectangle monitor; 
91       gchar *str;
92       
93       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
94       
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);
99       
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>",
106                              i + 1, num_monitors,
107                              monitor.width, monitor.height,
108                              monitor.x, monitor.y,
109                              primary_monitor);
110       gtk_label_set_markup (GTK_LABEL (label), str);
111       g_free (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);
122
123       g_signal_connect (screen, "monitors-changed",
124                         G_CALLBACK (monitors_changed_cb), label);
125     }
126
127   gtk_main ();
128
129   return 0;
130 }