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 1faa827..459f033 100644
--- a/gdk/x11/gdkscreen-x11.c
+++ b/gdk/x11/gdkscreen-x11.c
@@ -354,6 +354,24 @@ gdk_screen_get_n_monitors (GdkScreen *screen)
   return GDK_SCREEN_X11 (screen)->n_monitors;
 }
 
+/**
+ * gdk_screen_get_primary_monitor:
+ * @screen: a #GdkScreen.
+ *
+ * Gets the primary monitor for @screen.
+ *
+ * Returns: An integer index for the primary monitor.
+ *
+ * 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;
+}
+
 static GdkX11Monitor *
 get_monitor (GdkScreen *screen,
 	     int	monitor_num)
@@ -712,6 +730,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;
@@ -723,15 +742,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");
 
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..b7a065c 100644
--- a/tests/testxinerama.c
+++ b/tests/testxinerama.c
@@ -23,6 +23,7 @@
 #include <gtk/gtk.h>
 
 static gint num_monitors;
+static gint primary_monitor;
 
 static void
 request (GtkWidget      *widget,
@@ -63,7 +64,9 @@ 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.");
-  
+
+  primary_monitor = gdk_screen_get_primary_monitor (screen);
+
   for (i=0; i<num_monitors; i++)
     {
       GdkRectangle monitor; 
@@ -80,8 +83,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);
