2005-07-13 05:44:22 +00:00
|
|
|
/* 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
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2005-07-13 05:44:22 +00:00
|
|
|
*/
|
|
|
|
|
2008-06-22 14:28:52 +00:00
|
|
|
#include "config.h"
|
2002-04-30 18:32:08 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
static gint num_monitors;
|
2009-12-08 17:27:02 +00:00
|
|
|
static gint primary_monitor;
|
2002-04-30 18:32:08 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
request (GtkWidget *widget,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
gchar *str;
|
2009-12-08 17:27:02 +00:00
|
|
|
GdkScreen *screen = gtk_widget_get_screen (widget);
|
|
|
|
gint i = gdk_screen_get_monitor_at_window (screen,
|
2010-08-15 22:31:12 +00:00
|
|
|
gtk_widget_get_window (widget));
|
2002-04-30 18:32:08 +00:00
|
|
|
|
|
|
|
if (i < 0)
|
|
|
|
str = g_strdup ("<big><span foreground='white' background='black'>Not on a monitor </span></big>");
|
|
|
|
else
|
|
|
|
{
|
2002-05-01 17:22:54 +00:00
|
|
|
GdkRectangle monitor;
|
2009-12-08 17:27:02 +00:00
|
|
|
|
|
|
|
gdk_screen_get_monitor_geometry (screen,
|
|
|
|
i, &monitor);
|
|
|
|
primary_monitor = gdk_screen_get_primary_monitor (screen);
|
|
|
|
|
2002-04-30 18:32:08 +00:00
|
|
|
str = g_strdup_printf ("<big><span foreground='white' background='black'>"
|
|
|
|
"Monitor %d of %d</span></big>\n"
|
|
|
|
"<i>Width - Height </i>: (%d,%d)\n"
|
2009-12-08 17:27:02 +00:00
|
|
|
"<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);
|
2002-04-30 18:32:08 +00:00
|
|
|
}
|
2009-12-08 17:27:02 +00:00
|
|
|
|
2002-04-30 18:32:08 +00:00
|
|
|
gtk_label_set_markup (GTK_LABEL (user_data), str);
|
|
|
|
g_free (str);
|
|
|
|
}
|
|
|
|
|
2009-12-08 17:27:02 +00:00
|
|
|
static void
|
|
|
|
monitors_changed_cb (GdkScreen *screen,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkWidget *label = (GtkWidget *)data;
|
|
|
|
|
|
|
|
request (label, label);
|
|
|
|
}
|
|
|
|
|
2002-04-30 18:32:08 +00:00
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
|
|
|
GtkWidget *window, *label, *vbox, *button;
|
|
|
|
GdkScreen *screen;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
gtk_init (&argc, &argv);
|
|
|
|
|
2002-06-20 23:59:27 +00:00
|
|
|
screen = gdk_screen_get_default ();
|
2002-04-30 18:32:08 +00:00
|
|
|
|
|
|
|
num_monitors = gdk_screen_get_n_monitors (screen);
|
|
|
|
if (num_monitors == 1)
|
2002-05-02 16:18:24 +00:00
|
|
|
g_warning ("The default screen of the current display only has one monitor.");
|
2009-12-08 17:27:02 +00:00
|
|
|
|
|
|
|
primary_monitor = gdk_screen_get_primary_monitor (screen);
|
|
|
|
|
|
|
|
for (i = 0; i < num_monitors; i++)
|
2002-04-30 18:32:08 +00:00
|
|
|
{
|
2002-05-01 17:22:54 +00:00
|
|
|
GdkRectangle monitor;
|
2002-04-30 18:32:08 +00:00
|
|
|
gchar *str;
|
|
|
|
|
|
|
|
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
|
|
|
|
2002-05-01 17:22:54 +00:00
|
|
|
gdk_screen_get_monitor_geometry (screen, i, &monitor);
|
2002-04-30 18:32:08 +00:00
|
|
|
gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);
|
2002-05-01 17:22:54 +00:00
|
|
|
gtk_window_move (GTK_WINDOW (window), (monitor.width - 200) / 2 + monitor.x,
|
|
|
|
(monitor.height - 200) / 2 + monitor.y);
|
2002-04-30 18:32:08 +00:00
|
|
|
|
|
|
|
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"
|
2009-12-08 17:27:02 +00:00
|
|
|
"<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);
|
2002-04-30 18:32:08 +00:00
|
|
|
gtk_label_set_markup (GTK_LABEL (label), str);
|
|
|
|
g_free (str);
|
2010-10-31 17:07:20 +00:00
|
|
|
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 1);
|
|
|
|
gtk_box_set_homogeneous (GTK_BOX (vbox), TRUE);
|
2002-04-30 18:32:08 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (window), vbox);
|
|
|
|
gtk_container_add (GTK_CONTAINER (vbox), label);
|
2007-10-16 17:29:30 +00:00
|
|
|
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);
|
2002-04-30 18:32:08 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (vbox), button);
|
|
|
|
gtk_widget_show_all (window);
|
2009-12-08 17:27:02 +00:00
|
|
|
|
|
|
|
g_signal_connect (screen, "monitors-changed",
|
|
|
|
G_CALLBACK (monitors_changed_cb), label);
|
2002-04-30 18:32:08 +00:00
|
|
|
}
|
2009-12-08 17:27:02 +00:00
|
|
|
|
2002-04-30 18:32:08 +00:00
|
|
|
gtk_main ();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|