[gtk+] Add gdk_screen_get_primary_monitor(). This fixes bug #601712
- From: Cody Russell <bratsche src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gtk+] Add gdk_screen_get_primary_monitor(). This fixes bug #601712
- Date: Tue, 8 Dec 2009 17:27:34 +0000 (UTC)
commit 662e69ad3ec7246c48f7117fc407f180c308d9ee
Author: Cody Russell <bratsche gnome org>
Date: Tue Dec 8 11:27:02 2009 -0600
Add gdk_screen_get_primary_monitor(). This fixes bug #601712
gdk/gdkscreen.h | 1 +
gdk/x11/gdkscreen-x11.c | 41 ++++++++++++++++++++++++++++++++++++++-
gdk/x11/gdkscreen-x11.h | 1 +
tests/testxinerama.c | 48 +++++++++++++++++++++++++++++++++++++---------
4 files changed, 79 insertions(+), 12 deletions(-)
---
diff --git a/gdk/gdkscreen.h b/gdk/gdkscreen.h
index 96ff8d4..4e3bb1c 100644
--- a/gdk/gdkscreen.h
+++ b/gdk/gdkscreen.h
@@ -91,6 +91,7 @@ GList * gdk_screen_get_toplevel_windows (GdkScreen *screen);
gchar * gdk_screen_make_display_name (GdkScreen *screen);
gint gdk_screen_get_n_monitors (GdkScreen *screen);
+gint gdk_screen_get_primary_monitor (GdkScreen *screen);
void gdk_screen_get_monitor_geometry (GdkScreen *screen,
gint monitor_num,
GdkRectangle *dest);
diff --git a/gdk/x11/gdkscreen-x11.c b/gdk/x11/gdkscreen-x11.c
index 987bcfc..3e7b8b9 100644
--- a/gdk/x11/gdkscreen-x11.c
+++ b/gdk/x11/gdkscreen-x11.c
@@ -355,6 +355,31 @@ gdk_screen_get_n_monitors (GdkScreen *screen)
}
/**
+ * gdk_screen_get_primary_monitor:
+ * @screen: a #GdkScreen.
+ *
+ * Gets the primary monitor for @screen. The primary monitor
+ * is considered the monitor where the 'main desktop' lives.
+ * While normal application windows typically allow the window
+ * manager to place the windows, specialized desktop applications
+ * such as panels should place themselves on the primary monitor.
+ *
+ * If no primary monitor is configured by the user, the return value
+ * will be 0, defaulting to the first monitor.
+ *
+ * Returns: An integer index for the primary monitor, or 0 if none is configured.
+ *
+ * Since: 2.20
+ */
+gint
+gdk_screen_get_primary_monitor (GdkScreen *screen)
+{
+ g_return_val_if_fail (GDK_IS_SCREEN (screen), 0);
+
+ return GDK_SCREEN_X11 (screen)->primary_monitor;
+}
+
+/**
* gdk_screen_get_monitor_width_mm:
* @screen: a #GdkScreen
* @monitor_num: number of the monitor, between 0 and gdk_screen_get_n_monitors (screen)
@@ -722,6 +747,7 @@ init_randr13 (GdkScreen *screen)
GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
Display *dpy = GDK_SCREEN_XDISPLAY (screen);
XRRScreenResources *resources;
+ RROutput primary_output;
int i;
GArray *monitors;
gboolean randr12_compat = FALSE;
@@ -733,15 +759,23 @@ init_randr13 (GdkScreen *screen)
screen_x11->xroot_window);
if (!resources)
return FALSE;
-
+
monitors = g_array_sized_new (FALSE, TRUE, sizeof (GdkX11Monitor),
resources->noutput);
+ primary_output = XRRGetOutputPrimary (screen_x11->xdisplay,
+ screen_x11->xroot_window);
+
for (i = 0; i < resources->noutput; ++i)
{
XRROutputInfo *output =
XRRGetOutputInfo (dpy, resources, resources->outputs[i]);
+ if (resources->outputs[i] == primary_output)
+ {
+ screen_x11->primary_monitor = i;
+ }
+
/* Non RandR1.2 X driver have output name "default" */
randr12_compat |= !g_strcmp0(output->name, "default");
@@ -1110,7 +1144,10 @@ _gdk_x11_screen_size_changed (GdkScreen *screen,
display_x11 = GDK_DISPLAY_X11 (gdk_screen_get_display (screen));
if (display_x11->have_randr13 && event->type == ConfigureNotify)
- return;
+ {
+ g_signal_emit_by_name (screen, "monitors-changed");
+ return;
+ }
XRRUpdateConfiguration (event);
#else
diff --git a/gdk/x11/gdkscreen-x11.h b/gdk/x11/gdkscreen-x11.h
index 0d1548c..3efee6a 100644
--- a/gdk/x11/gdkscreen-x11.h
+++ b/gdk/x11/gdkscreen-x11.h
@@ -93,6 +93,7 @@ struct _GdkScreenX11
/* Xinerama/RandR 1.2 */
gint n_monitors;
GdkX11Monitor *monitors;
+ gint primary_monitor;
/* Pango renderer object singleton */
PangoRenderer *renderer;
diff --git a/tests/testxinerama.c b/tests/testxinerama.c
index 56dcde3..d9d37a9 100644
--- a/tests/testxinerama.c
+++ b/tests/testxinerama.c
@@ -23,13 +23,15 @@
#include <gtk/gtk.h>
static gint num_monitors;
+static gint primary_monitor;
static void
request (GtkWidget *widget,
gpointer user_data)
{
gchar *str;
- gint i = gdk_screen_get_monitor_at_window (gtk_widget_get_screen (widget),
+ GdkScreen *screen = gtk_widget_get_screen (widget);
+ gint i = gdk_screen_get_monitor_at_window (screen,
widget->window);
if (i < 0)
@@ -37,18 +39,35 @@ request (GtkWidget *widget,
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[])
{
@@ -63,8 +82,10 @@ main (int argc, char *argv[])
num_monitors = gdk_screen_get_n_monitors (screen);
if (num_monitors == 1)
g_warning ("The default screen of the current display only has one monitor.");
-
- for (i=0; i<num_monitors; i++)
+
+ primary_monitor = gdk_screen_get_primary_monitor (screen);
+
+ for (i = 0; i < num_monitors; i++)
{
GdkRectangle monitor;
gchar *str;
@@ -80,8 +101,12 @@ 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);
vbox = gtk_vbox_new (TRUE, 1);
@@ -94,8 +119,11 @@ main (int argc, char *argv[])
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;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]