]> Pileus Git - ~andy/gtk/blob - tests/testxinerama.c
stylecontext: Do invalidation on first resize container
[~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, see <http://www.gnu.org/licenses/>.
17  */
18
19 #include "config.h"
20 #include <stdlib.h>
21 #include <gtk/gtk.h>
22
23 static gint num_monitors;
24 static gint primary_monitor;
25
26 static void
27 request (GtkWidget      *widget,
28          gpointer        user_data)
29 {
30   gchar *str;
31   GdkScreen *screen = gtk_widget_get_screen (widget);
32   gint i = gdk_screen_get_monitor_at_window (screen,
33                                              gtk_widget_get_window (widget));
34
35   if (i < 0)
36     str = g_strdup ("<big><span foreground='white' background='black'>Not on a monitor </span></big>");
37   else
38     {
39       GdkRectangle monitor;
40
41       gdk_screen_get_monitor_geometry (screen,
42                                        i, &monitor);
43       primary_monitor = gdk_screen_get_primary_monitor (screen);
44
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>",
50                              i + 1, num_monitors,
51                              monitor.width, monitor.height,
52                              monitor.x, monitor.y,
53                              primary_monitor);
54     }
55
56   gtk_label_set_markup (GTK_LABEL (user_data), str);
57   g_free (str);
58 }
59
60 static void
61 monitors_changed_cb (GdkScreen *screen,
62                      gpointer   data)
63 {
64   GtkWidget *label = (GtkWidget *)data;
65
66   request (label, label);
67 }
68
69 int
70 main (int argc, char *argv[])
71 {
72   GtkWidget *window, *label, *vbox, *button;
73   GdkScreen *screen;
74   gint i;
75
76   gtk_init (&argc, &argv);
77
78   screen = gdk_screen_get_default ();
79
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.");
83
84   primary_monitor = gdk_screen_get_primary_monitor (screen);
85
86   for (i = 0; i < num_monitors; i++)
87     {
88       GdkRectangle monitor; 
89       gchar *str;
90       
91       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
92       
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);
97       
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>",
104                              i + 1, num_monitors,
105                              monitor.width, monitor.height,
106                              monitor.x, monitor.y,
107                              primary_monitor);
108       gtk_label_set_markup (GTK_LABEL (label), str);
109       g_free (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);
121
122       g_signal_connect (screen, "monitors-changed",
123                         G_CALLBACK (monitors_changed_cb), label);
124     }
125
126   gtk_main ();
127
128   return 0;
129 }