testxinerama.c 4.32 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/* 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
Javier Jardón's avatar
Javier Jardón committed
16
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
17 18
 */

19
#include "config.h"
20 21 22 23
#include <stdlib.h>
#include <gtk/gtk.h>

static gint num_monitors;
24
static gint primary_monitor;
25 26 27 28 29 30

static void
request (GtkWidget      *widget,
	 gpointer        user_data)
{
  gchar *str;
31 32
  GdkScreen *screen = gtk_widget_get_screen (widget);
  gint i = gdk_screen_get_monitor_at_window (screen,
33
                                             gtk_widget_get_window (widget));
34 35 36 37 38

  if (i < 0)
    str = g_strdup ("<big><span foreground='white' background='black'>Not on a monitor </span></big>");
  else
    {
39
      GdkRectangle monitor;
40 41 42 43 44

      gdk_screen_get_monitor_geometry (screen,
                                       i, &monitor);
      primary_monitor = gdk_screen_get_primary_monitor (screen);

45 46 47
      str = g_strdup_printf ("<big><span foreground='white' background='black'>"
			     "Monitor %d of %d</span></big>\n"
			     "<i>Width - Height       </i>: (%d,%d)\n"
48 49 50 51 52 53
			     "<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);
54
    }
55

56 57 58 59
  gtk_label_set_markup (GTK_LABEL (user_data), str);
  g_free (str);
}

60 61 62 63 64 65 66 67 68
static void
monitors_changed_cb (GdkScreen *screen,
                     gpointer   data)
{
  GtkWidget *label = (GtkWidget *)data;

  request (label, label);
}

69 70 71 72 73 74 75 76 77
int
main (int argc, char *argv[])
{
  GtkWidget *window, *label, *vbox, *button;
  GdkScreen *screen;
  gint i;

  gtk_init (&argc, &argv);

Owen Taylor's avatar
Owen Taylor committed
78
  screen = gdk_screen_get_default ();
79 80 81

  num_monitors = gdk_screen_get_n_monitors (screen);
  if (num_monitors == 1)
82
    g_warning ("The default screen of the current display only has one monitor.");
83 84 85 86

  primary_monitor = gdk_screen_get_primary_monitor (screen);

  for (i = 0; i < num_monitors; i++)
87
    {
88
      GdkRectangle monitor; 
89 90 91 92
      gchar *str;
      
      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 96
      gtk_window_move (GTK_WINDOW (window), (monitor.width - 200) / 2 + monitor.x,
		       (monitor.height - 200) / 2 + monitor.y);
97 98 99 100 101
      
      label = gtk_label_new (NULL);
      str = g_strdup_printf ("<big><span foreground='white' background='black'>"
			     "Monitor %d of %d</span></big>\n"
			     "<i>Width - Height       </i>: (%d,%d)\n"
102 103 104 105 106 107
			     "<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);
108 109
      gtk_label_set_markup (GTK_LABEL (label), str);
      g_free (str);
110 111
      vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 1);
      gtk_box_set_homogeneous (GTK_BOX (vbox), TRUE);
112 113
      gtk_container_add (GTK_CONTAINER (window), vbox);
      gtk_container_add (GTK_CONTAINER (vbox), label);
114 115 116 117 118
      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);
119 120
      gtk_container_add (GTK_CONTAINER (vbox), button);
      gtk_widget_show_all (window);
121 122 123

      g_signal_connect (screen, "monitors-changed",
                        G_CALLBACK (monitors_changed_cb), label);
124
    }
125

126 127 128 129
  gtk_main ();

  return 0;
}