testxinerama.c 3.38 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/* 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, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

21
#include <config.h>
22 23 24 25 26 27 28 29 30 31 32 33
#include <stdlib.h>
#include <gtk/gtk.h>

static gint num_monitors;

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),
34
					     widget->window);
35 36 37 38 39

  if (i < 0)
    str = g_strdup ("<big><span foreground='white' background='black'>Not on a monitor </span></big>");
  else
    {
40 41
      GdkRectangle monitor;
      gdk_screen_get_monitor_geometry (gtk_widget_get_screen (widget), i, &monitor);
42 43 44 45
      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,
46
			     monitor.width, monitor.height, monitor.x, monitor.y);
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
    }
  
  gtk_label_set_markup (GTK_LABEL (user_data), str);
  g_free (str);
}

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
62
  screen = gdk_screen_get_default ();
63 64 65

  num_monitors = gdk_screen_get_n_monitors (screen);
  if (num_monitors == 1)
66
    g_warning ("The default screen of the current display only has one monitor.");
67 68 69
  
  for (i=0; i<num_monitors; i++)
    {
70
      GdkRectangle monitor; 
71 72 73 74
      gchar *str;
      
      window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
      
75
      gdk_screen_get_monitor_geometry (screen, i, &monitor);
76
      gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);
77 78
      gtk_window_move (GTK_WINDOW (window), (monitor.width - 200) / 2 + monitor.x,
		       (monitor.height - 200) / 2 + monitor.y);
79 80 81 82 83 84
      
      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"
			     "<i>Top left coordinate </i>: (%d,%d)",i+1, num_monitors,
85
			     monitor.width, monitor.height, monitor.x, monitor.y);
86 87 88
      gtk_label_set_markup (GTK_LABEL (label), str);
      g_free (str);
      button = gtk_button_new_with_label ("Close");
Manish Singh's avatar
Manish Singh committed
89 90
      g_signal_connect (button, "clicked", G_CALLBACK (gtk_main_quit), NULL);
      g_signal_connect (window, "configure-event", G_CALLBACK (request), label);
91 92 93 94 95 96 97 98 99 100 101
      vbox = gtk_vbox_new (TRUE, 1);
      gtk_container_add (GTK_CONTAINER (window), vbox);
      gtk_container_add (GTK_CONTAINER (vbox), label);
      gtk_container_add (GTK_CONTAINER (vbox), button);
      gtk_widget_show_all (window);
    }
  
  gtk_main ();

  return 0;
}