gtk2/tests/testxinerama.c

133 lines
4.4 KiB
C
Raw Normal View History

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
*/
#include "config.h"
#include <stdlib.h>
#include <gtk/gtk.h>
2016-09-04 19:13:41 +00:00
static void
label_set_text_for_monitor (GtkLabel *label,
GdkMonitor *monitor)
{
GdkRectangle monitor_geom;
gchar *str;
gdk_monitor_get_geometry (monitor, &monitor_geom);
str = g_strdup_printf ("<big><span foreground='white' background='black'>"
"%s %s</span></big>\n"
"<i>Width - Height </i>: (%d,%d)\n"
"<i>Top left coordinate </i>: (%d,%d)\n"
"<i>Primary monitor</i>: %s",
gdk_monitor_get_manufacturer (monitor),
gdk_monitor_get_model (monitor),
monitor_geom.width, monitor_geom.height,
monitor_geom.x, monitor_geom.y,
gdk_monitor_is_primary (monitor) ? "YES" : "no");
gtk_label_set_markup (label, str);
g_free (str);
}
static void
request (GtkWidget *widget,
gpointer user_data)
{
2016-09-04 19:13:41 +00:00
GdkDisplay *display = gtk_widget_get_display (widget);
GdkSurface: Rename various functions and variables This is an automatic rename of various things related to the window->surface rename. Public symbols changed by this is: GDK_MODE_WINDOW gdk_device_get_window_at_position gdk_device_get_window_at_position_double gdk_device_get_last_event_window gdk_display_get_monitor_at_window gdk_drag_context_get_source_window gdk_drag_context_get_dest_window gdk_drag_context_get_drag_window gdk_draw_context_get_window gdk_drawing_context_get_window gdk_gl_context_get_window gdk_synthesize_window_state gdk_surface_get_window_type gdk_x11_display_set_window_scale gsk_renderer_new_for_window gsk_renderer_get_window gtk_text_view_buffer_to_window_coords gtk_tree_view_convert_widget_to_bin_window_coords gtk_tree_view_convert_tree_to_bin_window_coords The commands that generated this are: git sed -f g "GDK window" "GDK surface" git sed -f g window_impl surface_impl (cd gdk; git sed -f g impl_window impl_surface) git sed -f g WINDOW_IMPL SURFACE_IMPL git sed -f g GDK_MODE_WINDOW GDK_MODE_SURFACE git sed -f g gdk_draw_context_get_window gdk_draw_context_get_surface git sed -f g gdk_drawing_context_get_window gdk_drawing_context_get_surface git sed -f g gdk_gl_context_get_window gdk_gl_context_get_surface git sed -f g gsk_renderer_get_window gsk_renderer_get_surface git sed -f g gsk_renderer_new_for_window gsk_renderer_new_for_surface (cd gdk; git sed -f g window_type surface_type) git sed -f g gdk_surface_get_window_type gdk_surface_get_surface_type git sed -f g window_at_position surface_at_position git sed -f g event_window event_surface git sed -f g window_coord surface_coord git sed -f g window_state surface_state git sed -f g window_cursor surface_cursor git sed -f g window_scale surface_scale git sed -f g window_events surface_events git sed -f g monitor_at_window monitor_at_surface git sed -f g window_under_pointer surface_under_pointer (cd gdk; git sed -f g for_window for_surface) git sed -f g window_anchor surface_anchor git sed -f g WINDOW_IS_TOPLEVEL SURFACE_IS_TOPLEVEL git sed -f g native_window native_surface git sed -f g source_window source_surface git sed -f g dest_window dest_surface git sed -f g drag_window drag_surface git sed -f g input_window input_surface git checkout NEWS* po-properties po docs/reference/gtk/migrating-3to4.xml
2018-03-20 11:05:26 +00:00
GdkMonitor *monitor = gdk_display_get_monitor_at_surface (display,
gtk_widget_get_surface (widget));
2016-09-04 19:13:41 +00:00
if (monitor == NULL)
gtk_label_set_markup (GTK_LABEL (user_data),
"<big><span foreground='white' background='black'>Not on a monitor </span></big>");
else
2016-09-04 19:13:41 +00:00
label_set_text_for_monitor (GTK_LABEL (user_data), monitor);
}
2016-09-04 19:13:41 +00:00
static void
monitor_changed_cb (GdkMonitor *monitor,
GParamSpec *pspec,
GtkWidget *label)
{
request (label, label);
}
static void
2016-09-04 19:13:41 +00:00
monitor_added (GdkDisplay *display,
GdkMonitor *monitor,
gpointer unused)
{
2016-09-04 19:13:41 +00:00
GtkWidget *window, *label, *vbox, *button;
GdkRectangle monitor_geom;
2016-09-04 19:13:41 +00:00
gdk_monitor_get_geometry (monitor, &monitor_geom);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);
gtk_window_move (GTK_WINDOW (window), (monitor_geom.width - 200) / 2 + monitor_geom.x,
(monitor_geom.height - 200) / 2 + monitor_geom.y);
label = gtk_label_new (NULL);
label_set_text_for_monitor (GTK_LABEL (label), monitor);
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);
2017-01-19 09:02:04 +00:00
gtk_widget_show (window);
2016-09-04 19:13:41 +00:00
g_signal_connect (monitor, "notify",
G_CALLBACK (monitor_changed_cb), label);
g_signal_connect_swapped (monitor, "invalidate",
G_CALLBACK (gtk_widget_destroy), window);
}
int
main (int argc, char *argv[])
{
2016-09-04 19:13:41 +00:00
GdkDisplay *display;
gint i, num_monitors;
gtk_init ();
2016-09-04 19:13:41 +00:00
display = gdk_display_get_default ();
2016-09-04 19:13:41 +00:00
g_signal_connect (display, "monitor-added", G_CALLBACK (monitor_added), NULL);
2016-09-04 19:13:41 +00:00
num_monitors = gdk_display_get_n_monitors (display);
if (num_monitors == 1)
g_warning ("The current display only has one monitor.");
for (i = 0; i < num_monitors; i++)
{
2016-09-04 19:13:41 +00:00
GdkMonitor *monitor;
2016-09-04 19:13:41 +00:00
monitor = gdk_display_get_monitor (display, i);
monitor_added (display, monitor, NULL);
}
gtk_main ();
return 0;
}