Index: gst-libs/gst/interfaces/xoverlay.c
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-base/gst-libs/gst/interfaces/xoverlay.c,v
retrieving revision 1.20
diff -u -r1.20 xoverlay.c
--- gst-libs/gst/interfaces/xoverlay.c	8 Oct 2006 16:59:31 -0000	1.20
+++ gst-libs/gst/interfaces/xoverlay.c	3 Jan 2007 19:53:12 -0000
@@ -239,3 +239,28 @@
     klass->expose (overlay);
   }
 }
+
+/**
+ * gst_x_overlay_handle_events:
+ * @overlay: a #GstXOverlay to expose.
+ * @handle_events: a #gboolean indicating if events should be handled or not.
+ *
+ * Tell an overlay that it should handle events from the window system. These
+ * events are forwared upstream as navigation events. In some window system,
+ * events are not propagated in the window hierarchy if a client is listening
+ * for them. This method allows you to disable events handling completely
+ * from the XOverlay.
+ */
+void
+gst_x_overlay_handle_events (GstXOverlay * overlay, gboolean handle_events)
+{
+  GstXOverlayClass *klass;
+
+  g_return_if_fail (overlay != NULL);
+
+  klass = GST_X_OVERLAY_GET_CLASS (overlay);
+
+  if (klass->handle_events) {
+    klass->handle_events (overlay, handle_events);
+  }
+}
Index: gst-libs/gst/interfaces/xoverlay.h
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-base/gst-libs/gst/interfaces/xoverlay.h,v
retrieving revision 1.12
diff -u -r1.12 xoverlay.h
--- gst-libs/gst/interfaces/xoverlay.h	6 Dec 2005 19:42:00 -0000	1.12
+++ gst-libs/gst/interfaces/xoverlay.h	3 Jan 2007 19:53:12 -0000
@@ -51,6 +51,9 @@
                            gulong       xwindow_id);
 
   void (* expose)         (GstXOverlay *overlay);
+  
+  void (* handle_events)  (GstXOverlay *overlay,
+                           gboolean     handle_events);  
 
   /*< private >*/
   gpointer                 _gst_reserved[GST_PADDING];
@@ -63,6 +66,9 @@
 
 void gst_x_overlay_expose             (GstXOverlay *overlay);
 
+void gst_x_overlay_handle_events      (GstXOverlay *overlay,
+                                       gboolean     handle_events);
+
 /* public methods to dispatch bus messages */
 void gst_x_overlay_got_xwindow_id     (GstXOverlay *overlay, gulong xwindow_id);
 
Index: sys/ximage/ximagesink.c
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-base/sys/ximage/ximagesink.c,v
retrieving revision 1.168
diff -u -r1.168 ximagesink.c
--- sys/ximage/ximagesink.c	27 Dec 2006 12:08:12 -0000	1.168
+++ sys/ximage/ximagesink.c	3 Jan 2007 19:53:12 -0000
@@ -164,7 +164,8 @@
   PROP_DISPLAY,
   PROP_SYNCHRONOUS,
   PROP_PIXEL_ASPECT_RATIO,
-  PROP_FORCE_ASPECT_RATIO
+  PROP_FORCE_ASPECT_RATIO,
+  PROP_HANDLE_EVENTS
       /* FILL ME */
 };
 
@@ -771,9 +772,11 @@
      ConfigureNotify. This takes away flickering of video when resizing. */
   XSetWindowBackgroundPixmap (ximagesink->xcontext->disp, xwindow->win, None);
 
-  XSelectInput (ximagesink->xcontext->disp, xwindow->win, ExposureMask |
-      StructureNotifyMask | PointerMotionMask | KeyPressMask |
-      KeyReleaseMask | ButtonPressMask | ButtonReleaseMask);
+  if (ximagesink->handle_events) {
+    XSelectInput (ximagesink->xcontext->disp, xwindow->win, ExposureMask |
+        StructureNotifyMask | PointerMotionMask | KeyPressMask |
+        KeyReleaseMask | ButtonPressMask | ButtonReleaseMask);
+  }
 
   xwindow->gc = XCreateGC (ximagesink->xcontext->disp, xwindow->win,
       0, &values);
@@ -1817,9 +1820,11 @@
     xwindow->width = attr.width;
     xwindow->height = attr.height;
     xwindow->internal = FALSE;
-    XSelectInput (ximagesink->xcontext->disp, xwindow->win, ExposureMask |
-        StructureNotifyMask | PointerMotionMask | KeyPressMask |
-        KeyReleaseMask);
+    if (ximagesink->handle_events) {
+      XSelectInput (ximagesink->xcontext->disp, xwindow->win, ExposureMask |
+          StructureNotifyMask | PointerMotionMask | KeyPressMask |
+          KeyReleaseMask);
+    }
 
     xwindow->gc = XCreateGC (ximagesink->xcontext->disp, xwindow->win, 0, NULL);
     g_mutex_unlock (ximagesink->x_lock);
@@ -1843,10 +1848,43 @@
 }
 
 static void
+gst_ximagesink_set_event_handling (GstXOverlay * overlay,
+    gboolean handle_events)
+{
+  GstXImageSink *ximagesink = GST_XIMAGESINK (overlay);
+
+  ximagesink->handle_events = handle_events;
+  
+  if (!ximagesink->xwindow) 
+    return;
+  
+  g_mutex_lock (ximagesink->x_lock);
+
+  if (handle_events) {
+    if (ximagesink->xwindow->internal) {
+      XSelectInput (ximagesink->xcontext->disp, ximagesink->xwindow->win,
+          ExposureMask | StructureNotifyMask | PointerMotionMask |
+          KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask);
+    }
+    else {
+      XSelectInput (ximagesink->xcontext->disp, ximagesink->xwindow->win,
+          ExposureMask | StructureNotifyMask | PointerMotionMask |
+          KeyPressMask | KeyReleaseMask);
+    }
+  }
+  else {  
+    XSelectInput (ximagesink->xcontext->disp, ximagesink->xwindow->win, 0);
+  }
+  
+  g_mutex_unlock (ximagesink->x_lock);
+}
+
+static void
 gst_ximagesink_xoverlay_init (GstXOverlayClass * iface)
 {
   iface->set_xwindow_id = gst_ximagesink_set_xwindow_id;
   iface->expose = gst_ximagesink_expose;
+  iface->handle_events = gst_ximagesink_set_event_handling;
 }
 
 /* =========================================== */
@@ -1902,6 +1940,10 @@
       }
     }
       break;
+    case PROP_HANDLE_EVENTS:
+      gst_ximagesink_set_event_handling (GST_X_OVERLAY (ximagesink),
+          g_value_get_boolean (value));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -1932,6 +1974,9 @@
       if (ximagesink->par)
         g_value_transform (ximagesink->par, value);
       break;
+    case PROP_HANDLE_EVENTS:
+      g_value_set_boolean (value, ximagesink->handle_events);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -1994,6 +2039,7 @@
 
   ximagesink->synchronous = FALSE;
   ximagesink->keep_aspect = FALSE;
+  ximagesink->handle_events = TRUE;
 }
 
 static void
@@ -2038,6 +2084,10 @@
   g_object_class_install_property (gobject_class, PROP_PIXEL_ASPECT_RATIO,
       g_param_spec_string ("pixel-aspect-ratio", "Pixel Aspect Ratio",
           "The pixel aspect ratio of the device", "1/1", G_PARAM_READWRITE));
+  g_object_class_install_property (gobject_class, PROP_HANDLE_EVENTS,
+      g_param_spec_boolean ("handle-events", "Handle XEvents",
+          "When enabled, XEvents will be selected and handled", TRUE,
+          G_PARAM_READWRITE));
 
   gstelement_class->change_state = gst_ximagesink_change_state;
 
Index: sys/ximage/ximagesink.h
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-base/sys/ximage/ximagesink.h,v
retrieving revision 1.38
diff -u -r1.38 ximagesink.h
--- sys/ximage/ximagesink.h	1 Jun 2006 19:19:51 -0000	1.38
+++ sys/ximage/ximagesink.h	3 Jan 2007 19:53:12 -0000
@@ -179,6 +179,7 @@
  * debugging purpose only)
  * @keep_aspect: used to remember if reverse negotiation scaling should respect
  * aspect ratio
+ * @handle_events: used to know if we should handle select XEvents or not
  *
  * The #GstXImageSink data structure.
  */
@@ -211,6 +212,7 @@
 
   gboolean synchronous;
   gboolean keep_aspect;
+  gboolean handle_events;
 };
 
 struct _GstXImageSinkClass {
Index: sys/xvimage/xvimagesink.c
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-base/sys/xvimage/xvimagesink.c,v
retrieving revision 1.172
diff -u -r1.172 xvimagesink.c
--- sys/xvimage/xvimagesink.c	27 Dec 2006 12:08:12 -0000	1.172
+++ sys/xvimage/xvimagesink.c	3 Jan 2007 19:53:13 -0000
@@ -188,7 +188,8 @@
   ARG_DISPLAY,
   ARG_SYNCHRONOUS,
   ARG_PIXEL_ASPECT_RATIO,
-  ARG_FORCE_ASPECT_RATIO
+  ARG_FORCE_ASPECT_RATIO,
+  ARG_HANDLE_EVENTS
       /* FILL ME */
 };
 
@@ -829,9 +830,11 @@
    * ConfigureNotify. This takes away flickering of video when resizing. */
   XSetWindowBackgroundPixmap (xvimagesink->xcontext->disp, xwindow->win, None);
 
-  XSelectInput (xvimagesink->xcontext->disp, xwindow->win, ExposureMask |
-      StructureNotifyMask | PointerMotionMask | KeyPressMask |
-      KeyReleaseMask | ButtonPressMask | ButtonReleaseMask);
+  if (xvimagesink->handle_events) {
+    XSelectInput (xvimagesink->xcontext->disp, xwindow->win, ExposureMask |
+        StructureNotifyMask | PointerMotionMask | KeyPressMask |
+        KeyReleaseMask | ButtonPressMask | ButtonReleaseMask);
+  }
 
   xwindow->gc = XCreateGC (xvimagesink->xcontext->disp,
       xwindow->win, 0, &values);
@@ -2374,9 +2377,11 @@
     xwindow->width = attr.width;
     xwindow->height = attr.height;
     xwindow->internal = FALSE;
-    XSelectInput (xvimagesink->xcontext->disp, xwindow->win, ExposureMask |
-        StructureNotifyMask | PointerMotionMask | KeyPressMask |
-        KeyReleaseMask);
+    if (xvimagesink->handle_events) {
+      XSelectInput (xvimagesink->xcontext->disp, xwindow->win, ExposureMask |
+          StructureNotifyMask | PointerMotionMask | KeyPressMask |
+          KeyReleaseMask);
+    }
 
     xwindow->gc = XCreateGC (xvimagesink->xcontext->disp,
         xwindow->win, 0, NULL);
@@ -2401,10 +2406,43 @@
 }
 
 static void
+gst_xvimagesink_set_event_handling (GstXOverlay * overlay,
+    gboolean handle_events)
+{
+  GstXvImageSink *xvimagesink = GST_XVIMAGESINK (overlay);
+
+  xvimagesink->handle_events = handle_events;
+  
+  if (!xvimagesink->xwindow) 
+    return;
+  
+  g_mutex_lock (xvimagesink->x_lock);
+
+  if (handle_events) {
+    if (xvimagesink->xwindow->internal) {
+      XSelectInput (xvimagesink->xcontext->disp, xvimagesink->xwindow->win,
+          ExposureMask | StructureNotifyMask | PointerMotionMask |
+          KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask);
+    }
+    else {
+      XSelectInput (xvimagesink->xcontext->disp, xvimagesink->xwindow->win,
+          ExposureMask | StructureNotifyMask | PointerMotionMask |
+          KeyPressMask | KeyReleaseMask);
+    }
+  }
+  else {  
+    XSelectInput (xvimagesink->xcontext->disp, xvimagesink->xwindow->win, 0);
+  }
+  
+  g_mutex_unlock (xvimagesink->x_lock);
+}
+
+static void
 gst_xvimagesink_xoverlay_init (GstXOverlayClass * iface)
 {
   iface->set_xwindow_id = gst_xvimagesink_set_xwindow_id;
-  iface->expose = gst_xvimagesink_expose;
+  iface->expose = gst_xvimagesink_expose
+  ;iface->handle_events = gst_xvimagesink_set_event_handling;
 }
 
 static const GList *
@@ -2552,6 +2590,10 @@
     case ARG_FORCE_ASPECT_RATIO:
       xvimagesink->keep_aspect = g_value_get_boolean (value);
       break;
+    case ARG_HANDLE_EVENTS:
+      gst_xvimagesink_set_event_handling (GST_X_OVERLAY (xvimagesink),
+          g_value_get_boolean (value));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -2594,6 +2636,9 @@
     case ARG_FORCE_ASPECT_RATIO:
       g_value_set_boolean (value, xvimagesink->keep_aspect);
       break;
+    case ARG_HANDLE_EVENTS:
+      g_value_set_boolean (value, xvimagesink->handle_events);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -2662,6 +2707,7 @@
   xvimagesink->synchronous = FALSE;
   xvimagesink->running = FALSE;
   xvimagesink->keep_aspect = FALSE;
+  xvimagesink->handle_events = TRUE;
   xvimagesink->par = NULL;
 }
 
@@ -2719,6 +2765,10 @@
       g_param_spec_boolean ("force-aspect-ratio", "Force aspect ratio",
           "When enabled, scaling will respect original aspect ratio", FALSE,
           G_PARAM_READWRITE));
+  g_object_class_install_property (gobject_class, ARG_HANDLE_EVENTS,
+      g_param_spec_boolean ("handle-events", "Handle XEvents",
+          "When enabled, XEvents will be selected and handled", TRUE,
+          G_PARAM_READWRITE));
 
   gobject_class->finalize = gst_xvimagesink_finalize;
 
Index: sys/xvimage/xvimagesink.h
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-base/sys/xvimage/xvimagesink.h,v
retrieving revision 1.37
diff -u -r1.37 xvimagesink.h
--- sys/xvimage/xvimagesink.h	1 Jun 2006 19:19:51 -0000	1.37
+++ sys/xvimage/xvimagesink.h	3 Jan 2007 19:53:13 -0000
@@ -209,6 +209,7 @@
  * debugging purpose only)
  * @keep_aspect: used to remember if reverse negotiation scaling should respect
  * aspect ratio
+ * @handle_events: used to know if we should handle select XEvents or not
  * @brightness: used to store the user settings for color balance brightness
  * @contrast: used to store the user settings for color balance contrast
  * @hue: used to store the user settings for color balance hue
@@ -247,6 +248,7 @@
   
   gboolean synchronous;
   gboolean keep_aspect;
+  gboolean handle_events;
   
   gint brightness;
   gint contrast;
Index: tests/icles/stress-xoverlay.c
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-base/tests/icles/stress-xoverlay.c,v
retrieving revision 1.2
diff -u -r1.2 stress-xoverlay.c
--- tests/icles/stress-xoverlay.c	9 May 2006 11:59:13 -0000	1.2
+++ tests/icles/stress-xoverlay.c	3 Jan 2007 19:53:13 -0000
@@ -93,17 +93,39 @@
   return TRUE;
 }
 
+static gboolean
+toggle_events (GstXOverlay * ov)
+{
+  static gboolean events_toggled;
+
+  gst_x_overlay_handle_events (ov, events_toggled);
+
+  if (events_toggled) {
+    g_print ("Events are handled\n");
+    events_toggled = FALSE;
+  }
+  else {
+    g_print ("Events are NOT handled\n");
+    events_toggled = TRUE;
+  }
+
+  return TRUE;
+}
+
 static GstBusSyncReply
 create_window (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
 {
   XGCValues values;
   const GstStructure *s;
+  GstXOverlay *ov = NULL;
 
   s = gst_message_get_structure (message);
   if (!gst_structure_has_name (s, "prepare-xwindow-id")) {
     return GST_BUS_PASS;
   }
 
+  ov = GST_X_OVERLAY (GST_MESSAGE_SRC (message));
+
   g_print ("Creating our own window\n");
 
   win = XCreateSimpleWindow (disp, root, 0, 0, width, height, 0, 0, 0);
@@ -116,10 +138,11 @@
 
   XSync (disp, FALSE);
 
-  gst_x_overlay_set_xwindow_id (GST_X_OVERLAY (GST_MESSAGE_SRC (message)), win);
+  gst_x_overlay_set_xwindow_id (ov, win);
 
   g_timeout_add (50, (GSourceFunc) resize_window, pipeline);
   g_timeout_add (50, (GSourceFunc) move_window, pipeline);
+  g_timeout_add (2000, (GSourceFunc) toggle_events, ov);
 
   return GST_BUS_DROP;
 }
