Index: sys/ximage/ximagesink.c
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-base/sys/ximage/ximagesink.c,v
retrieving revision 1.167
diff -p -u -B -r1.167 ximagesink.c
--- sys/ximage/ximagesink.c	14 Nov 2006 11:54:14 -0000	1.167
+++ sys/ximage/ximagesink.c	30 Nov 2006 19:24:47 -0000
@@ -162,6 +162,7 @@ enum
 {
   PROP_0,
   PROP_DISPLAY,
+  PROP_SCREEN,
   PROP_SYNCHRONOUS,
   PROP_PIXEL_ASPECT_RATIO,
   PROP_FORCE_ASPECT_RATIO
@@ -1076,10 +1077,19 @@ gst_ximagesink_xcontext_get (GstXImageSi
     return NULL;
   }
 
-  xcontext->screen = DefaultScreenOfDisplay (xcontext->disp);
-  xcontext->screen_num = DefaultScreen (xcontext->disp);
+  if (ximagesink->screen_num >= ScreenCount (xcontext->disp)) {
+    g_mutex_unlock (ximagesink->x_lock);
+    g_free (xcontext);
+    GST_ELEMENT_ERROR (ximagesink, RESOURCE, WRITE,
+        ("Could not initialise X output"), ("Display %s has no screen %d",
+	ximagesink->display_name, ximagesink->screen_num));
+    return NULL;
+  }
+
+  xcontext->screen_num = ximagesink->screen_num;
+  xcontext->screen = ScreenOfDisplay (xcontext->disp, xcontext->screen_num);
   xcontext->visual = DefaultVisual (xcontext->disp, xcontext->screen_num);
-  xcontext->root = DefaultRootWindow (xcontext->disp);
+  xcontext->root = RootWindow (xcontext->disp, xcontext->screen_num);
   xcontext->white = XWhitePixel (xcontext->disp, xcontext->screen_num);
   xcontext->black = XBlackPixel (xcontext->disp, xcontext->screen_num);
   xcontext->depth = DefaultDepthOfScreen (xcontext->screen);
@@ -1866,8 +1876,19 @@ gst_ximagesink_set_property (GObject * o
 
   switch (prop_id) {
     case PROP_DISPLAY:
+      gst_ximagesink_xcontext_clear (ximagesink);
       ximagesink->display_name = g_strdup (g_value_get_string (value));
       break;
+    case PROP_SCREEN: {
+      gint screen_num;
+
+      screen_num = g_value_get_int (value);
+      if (screen_num != ximagesink->screen_num) {
+        gst_ximagesink_xcontext_clear (ximagesink);
+	ximagesink->screen_num = screen_num;
+      }
+      break;
+    }
     case PROP_SYNCHRONOUS:
       ximagesink->synchronous = g_value_get_boolean (value);
       if (ximagesink->xcontext) {
@@ -1921,6 +1942,9 @@ gst_ximagesink_get_property (GObject * o
     case PROP_DISPLAY:
       g_value_set_string (value, ximagesink->display_name);
       break;
+    case PROP_SCREEN:
+      g_value_set_int (value, ximagesink->screen_num);
+      break;
     case PROP_SYNCHRONOUS:
       g_value_set_boolean (value, ximagesink->synchronous);
       break;
@@ -2026,6 +2050,9 @@ gst_ximagesink_class_init (GstXImageSink
   g_object_class_install_property (gobject_class, PROP_DISPLAY,
       g_param_spec_string ("display", "Display", "X Display name",
           NULL, G_PARAM_READWRITE));
+  g_object_class_install_property (gobject_class, PROP_SCREEN,
+      g_param_spec_int ("screen", "Screen", "The X display's screen to use", 0, G_MAXINT, 0,
+          G_PARAM_READWRITE));
   g_object_class_install_property (gobject_class, PROP_SYNCHRONOUS,
       g_param_spec_boolean ("synchronous", "Synchronous", "When enabled, runs "
           "the X display in synchronous mode. (used only for debugging)", FALSE,
Index: sys/ximage/ximagesink.h
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-base/sys/ximage/ximagesink.h,v
retrieving revision 1.38
diff -p -u -B -r1.38 ximagesink.h
--- sys/ximage/ximagesink.h	1 Jun 2006 19:19:51 -0000	1.38
+++ sys/ximage/ximagesink.h	30 Nov 2006 19:24:47 -0000
@@ -187,6 +187,7 @@ struct _GstXImageSink {
   GstVideoSink videosink;
 
   char *display_name;
+  gint screen_num;
 
   GstXContext *xcontext;
   GstXWindow *xwindow;
Index: sys/xvimage/xvimagesink.c
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-base/sys/xvimage/xvimagesink.c,v
retrieving revision 1.171
diff -p -u -B -r1.171 xvimagesink.c
--- sys/xvimage/xvimagesink.c	24 Nov 2006 08:35:23 -0000	1.171
+++ sys/xvimage/xvimagesink.c	30 Nov 2006 19:24:49 -0000
@@ -186,6 +186,7 @@ enum
   ARG_HUE,
   ARG_SATURATION,
   ARG_DISPLAY,
+  ARG_SCREEN,
   ARG_SYNCHRONOUS,
   ARG_PIXEL_ASPECT_RATIO,
   ARG_FORCE_ASPECT_RATIO
@@ -1470,10 +1471,19 @@ gst_xvimagesink_xcontext_get (GstXvImage
     return NULL;
   }
 
-  xcontext->screen = DefaultScreenOfDisplay (xcontext->disp);
-  xcontext->screen_num = DefaultScreen (xcontext->disp);
+  if (xvimagesink->screen_num >= ScreenCount (xcontext->disp)) {
+    g_mutex_unlock (xvimagesink->x_lock);
+    g_free (xcontext);
+    GST_ELEMENT_ERROR (xvimagesink, RESOURCE, WRITE,
+        ("Could not initialise Xv output"), ("Display %s has no screen %d",
+	xvimagesink->display_name, xvimagesink->screen_num));
+    return NULL;
+  }
+
+  xcontext->screen_num = xvimagesink->screen_num;
+  xcontext->screen = ScreenOfDisplay (xcontext->disp, xcontext->screen_num);
   xcontext->visual = DefaultVisual (xcontext->disp, xcontext->screen_num);
-  xcontext->root = DefaultRootWindow (xcontext->disp);
+  xcontext->root = RootWindow (xcontext->disp, xcontext->screen_num);
   xcontext->white = XWhitePixel (xcontext->disp, xcontext->screen_num);
   xcontext->black = XBlackPixel (xcontext->disp, xcontext->screen_num);
   xcontext->depth = DefaultDepthOfScreen (xcontext->screen);
@@ -2526,8 +2536,19 @@ gst_xvimagesink_set_property (GObject * 
       gst_xvimagesink_update_colorbalance (xvimagesink);
       break;
     case ARG_DISPLAY:
+      gst_xvimagesink_xcontext_clear (xvimagesink);
       xvimagesink->display_name = g_strdup (g_value_get_string (value));
       break;
+    case ARG_SCREEN: {
+      gint screen_num;
+
+      screen_num = g_value_get_int (value);
+      if (screen_num != xvimagesink->screen_num) {
+        gst_xvimagesink_xcontext_clear (xvimagesink);
+	xvimagesink->screen_num = screen_num;
+      }
+      break;
+    }
     case ARG_SYNCHRONOUS:
       xvimagesink->synchronous = g_value_get_boolean (value);
       if (xvimagesink->xcontext) {
@@ -2583,6 +2604,9 @@ gst_xvimagesink_get_property (GObject * 
     case ARG_DISPLAY:
       g_value_set_string (value, xvimagesink->display_name);
       break;
+    case ARG_SCREEN:
+      g_value_set_int (value, xvimagesink->screen_num);
+      break;
     case ARG_SYNCHRONOUS:
       g_value_set_boolean (value, xvimagesink->synchronous);
       break;
@@ -2706,6 +2730,9 @@ gst_xvimagesink_class_init (GstXvImageSi
   g_object_class_install_property (gobject_class, ARG_DISPLAY,
       g_param_spec_string ("display", "Display", "X Display name", NULL,
           G_PARAM_READWRITE));
+  g_object_class_install_property (gobject_class, ARG_SCREEN,
+      g_param_spec_int ("screen", "Screen", "The X display's screen to use", 0, G_MAXINT, 0,
+          G_PARAM_READWRITE));
   g_object_class_install_property (gobject_class, ARG_SYNCHRONOUS,
       g_param_spec_boolean ("synchronous", "Synchronous",
           "When enabled, runs "
Index: sys/xvimage/xvimagesink.h
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-base/sys/xvimage/xvimagesink.h,v
retrieving revision 1.37
diff -p -u -B -r1.37 xvimagesink.h
--- sys/xvimage/xvimagesink.h	1 Jun 2006 19:19:51 -0000	1.37
+++ sys/xvimage/xvimagesink.h	30 Nov 2006 19:24:52 -0000
@@ -224,6 +224,7 @@ struct _GstXvImageSink {
   GstVideoSink videosink;
 
   char *display_name;
+  gint screen_num;
 
   GstXContext *xcontext;
   GstXWindow *xwindow;
