]> Pileus Git - ~andy/gtk/blobdiff - tests/testxinerama.c
stylecontext: Do invalidation on first resize container
[~andy/gtk] / tests / testxinerama.c
index 2f6e05ea23a6bacde136e3153e4a2b834e51d411..67a7e32e5c48e9a17d3d07959e5de88d182b3cc9 100644 (file)
@@ -1,34 +1,71 @@
+/* testmultidisplay.c
+ * Copyright (C) 2001 Sun Microsystems Inc.
+ * Author: Erwann Chenede <erwann.chenede@sun.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
 #include <stdlib.h>
 #include <gtk/gtk.h>
 
 static gint num_monitors;
+static gint primary_monitor;
 
 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);
+  GdkScreen *screen = gtk_widget_get_screen (widget);
+  gint i = gdk_screen_get_monitor_at_window (screen,
+                                             gtk_widget_get_window (widget));
 
   if (i < 0)
     str = g_strdup ("<big><span foreground='white' background='black'>Not on a monitor </span></big>");
   else
     {
       GdkRectangle monitor;
-      gdk_screen_get_monitor_geometry (gtk_widget_get_screen (widget), i, &monitor);
+
+      gdk_screen_get_monitor_geometry (screen,
+                                       i, &monitor);
+      primary_monitor = gdk_screen_get_primary_monitor (screen);
+
       str = g_strdup_printf ("<big><span foreground='white' background='black'>"
                             "Monitor %d of %d</span></big>\n"
                             "<i>Width - Height       </i>: (%d,%d)\n"
-                            "<i>Top left coordinate </i>: (%d,%d)",i+1, num_monitors,
-                            monitor.width, monitor.height, monitor.x, monitor.y);
+                            "<i>Top left coordinate </i>: (%d,%d)\n"
+                             "<i>Primary monitor: %d</i>",
+                             i + 1, num_monitors,
+                            monitor.width, monitor.height,
+                             monitor.x, monitor.y,
+                             primary_monitor);
     }
-  
+
   gtk_label_set_markup (GTK_LABEL (user_data), str);
   g_free (str);
 }
 
+static void
+monitors_changed_cb (GdkScreen *screen,
+                     gpointer   data)
+{
+  GtkWidget *label = (GtkWidget *)data;
+
+  request (label, label);
+}
+
 int
 main (int argc, char *argv[])
 {
@@ -38,13 +75,15 @@ main (int argc, char *argv[])
 
   gtk_init (&argc, &argv);
 
-  screen = gdk_get_default_screen ();
+  screen = gdk_screen_get_default ();
 
   num_monitors = gdk_screen_get_n_monitors (screen);
   if (num_monitors == 1)
-    g_warning ("The current display does not support xinerama.");
-  
-  for (i=0; i<num_monitors; i++)
+    g_warning ("The default screen of the current display only has one monitor.");
+
+  primary_monitor = gdk_screen_get_primary_monitor (screen);
+
+  for (i = 0; i < num_monitors; i++)
     {
       GdkRectangle monitor; 
       gchar *str;
@@ -60,20 +99,30 @@ main (int argc, char *argv[])
       str = g_strdup_printf ("<big><span foreground='white' background='black'>"
                             "Monitor %d of %d</span></big>\n"
                             "<i>Width - Height       </i>: (%d,%d)\n"
-                            "<i>Top left coordinate </i>: (%d,%d)",i+1, num_monitors,
-                            monitor.width, monitor.height, monitor.x, monitor.y);
+                            "<i>Top left coordinate </i>: (%d,%d)\n"
+                             "<i>Primary monitor: %d</i>",
+                             i + 1, num_monitors,
+                            monitor.width, monitor.height,
+                             monitor.x, monitor.y,
+                             primary_monitor);
       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);
+      vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 1);
+      gtk_box_set_homogeneous (GTK_BOX (vbox), TRUE);
       gtk_container_add (GTK_CONTAINER (window), vbox);
       gtk_container_add (GTK_CONTAINER (vbox), label);
+      button = gtk_button_new_with_label ("Query current monitor");
+      g_signal_connect (button, "clicked", G_CALLBACK (request), label);
+      gtk_container_add (GTK_CONTAINER (vbox), button);
+      button = gtk_button_new_with_label ("Close");
+      g_signal_connect (button, "clicked", G_CALLBACK (gtk_main_quit), NULL);
       gtk_container_add (GTK_CONTAINER (vbox), button);
       gtk_widget_show_all (window);
+
+      g_signal_connect (screen, "monitors-changed",
+                        G_CALLBACK (monitors_changed_cb), label);
     }
-  
+
   gtk_main ();
 
   return 0;