diff -ur xine-lib/src/dxr3/video_out_dxr3.c xine-lib-new/src/dxr3/video_out_dxr3.c
--- xine-lib/src/dxr3/video_out_dxr3.c	Sat Aug 17 18:09:33 2002
+++ xine-lib-new/src/dxr3/video_out_dxr3.c	Sat Aug 17 18:27:34 2002
@@ -158,6 +158,13 @@
   this->vo_driver.gui_data_exchange    = dxr3_gui_data_exchange;
   this->vo_driver.exit                 = dxr3_exit;
   
+#if HAVE_X11
+  this->x11_lock_display      = visual->lock_display_cb   ? visual->lock_display_cb
+                                                          : XLockDisplay;
+  this->x11_unlock_display    = visual->unlock_display_cb ? visual->unlock_display_cb
+                                                          : XUnlockDisplay;
+#endif
+ 
   pthread_mutex_init(&this->spu_device_lock, NULL);
   
   this->config                         = config;
@@ -372,7 +379,7 @@
       printf("video_out_dxr3: switching to overlay mode failed.\n");
   }
 #endif
-  
+ 
   return &this->vo_driver;
 }
 
@@ -1284,11 +1291,11 @@
       this->height = gui_height;
       
       /* fill video window with keycolor */
-      XLockDisplay(this->display);
+      this->x11_lock_display(this->display);
       XSetForeground(this->display, this->gc, this->color.pixel);
       XFillRectangle(this->display, this->win, this->gc,
         win_off_x, win_off_y, this->width, this->height);
-      XUnlockDisplay(this->display);
+      this->x11_unlock_display(this->display);
       this->need_redraw = 0;
       
       /* is some part of the picture visible? */
diff -ur xine-lib/src/dxr3/video_out_dxr3.h xine-lib-new/src/dxr3/video_out_dxr3.h
--- xine-lib/src/dxr3/video_out_dxr3.h	Sat Aug 17 18:09:33 2002
+++ xine-lib-new/src/dxr3/video_out_dxr3.h	Sat Aug 17 18:24:30 2002
@@ -118,6 +118,9 @@
                      int *dest_x, int *dest_y,
                      int *dest_height, int *dest_width,
                      int *win_x, int *win_y);
+
+  void           (*x11_lock_display)(Display *display);
+  void           (*x11_unlock_display)(Display *display);
 } dxr3_driver_t;
 
 typedef struct dxr3_frame_s {
diff -ur xine-lib/src/video_out/video_out_opengl.c xine-lib-new/src/video_out/video_out_opengl.c
--- xine-lib/src/video_out/video_out_opengl.c	Sat Aug 10 22:25:20 2002
+++ xine-lib-new/src/video_out/video_out_opengl.c	Sat Aug 17 18:17:54 2002
@@ -193,6 +193,9 @@
 			  int video_width, int video_height, 
 			  int *dest_width, int *dest_height);
 
+    void (*x11_lock_display)   (Display *);
+    void (*x11_unlock_display) (Display *);
+
 } opengl_driver_t;
 
 
@@ -258,14 +261,14 @@
     DEBUGF ((stderr, "*** frame_dispose ***\n"));
     if (frame)
     {
-	XLockDisplay (this->display);
+	this->x11_lock_display (this->display);
 	free (frame->texture);
 	free (frame->chunk[0]);
 	free (frame->chunk[1]);
 	free (frame->chunk[2]);
 	frame->texture = NULL;
 	frame->chunk[0] = frame->chunk[1] = frame->chunk[2] = NULL;
-	XUnlockDisplay (this->display);
+	this->x11_unlock_display (this->display);
     }
     free (frame);
 }
@@ -326,7 +329,7 @@
 
 	/* update frame allocated data */
 
-	XLockDisplay (this->display);
+	this->x11_lock_display (this->display);
 
 	free (frame->texture);
 	free (frame->chunk[0]);
@@ -380,7 +383,7 @@
 	frame->format = format;
 	frame->flags  = flags;
 	
-	XUnlockDisplay (this->display);
+	this->x11_unlock_display (this->display);
     }
 
     frame->ratio_code = ratio_code;
@@ -803,9 +806,9 @@
 	this->cur_frame->vo_frame.displayed (&this->cur_frame->vo_frame);
     this->cur_frame = frame;
 
-    XLockDisplay (this->display);
+    this->x11_lock_display (this->display);
     opengl_render_image (this, frame, NULL);
-    XUnlockDisplay (this->display);
+    this->x11_unlock_display (this->display);
     
     /* Theoretically, the frame data is not used immedeately, and the
      * graphics system might address altered data - but only if we
@@ -945,9 +948,9 @@
     switch (data_type) {
     case GUI_SELECT_VISUAL:
 	DEBUGF ((stderr, "*** gui_select_visual ***\n"));
-	XLockDisplay (this->display);
+	this->x11_lock_display (this->display);
 	this->vinfo = glXChooseVisual (this->display, this->screen, glxAttrib);
-	XUnlockDisplay (this->display);
+	this->x11_unlock_display (this->display);
 	if (this->vinfo == NULL)
 	    fprintf (stderr, "video_out_opengl: no OpenGL support available (glXChooseVisual)\n");
 	*(XVisualInfo**)data = this->vinfo;
@@ -970,7 +973,7 @@
 
     case GUI_DATA_EX_DRAWABLE_CHANGED:
 	DEBUGF ((stderr, "*** gui_drawable_changed: %ld\n", (Drawable) data));
-	XLockDisplay (this->display);
+	this->x11_lock_display (this->display);
 	/* Unfortunately, the last drawable is already gone, so we cannot
 	 * destroy the former context. This is a memory leak. Unfortunately. */
 	/* Even if the drawable remains the same, this does not seem to
@@ -987,7 +990,7 @@
 	if (this->context_state == CONTEXT_BAD)
 	    DEBUGF ((stderr, "*** drawable changed, state now bad\n"));
 	this->drawable = (Drawable) data;
-	XUnlockDisplay (this->display);
+	this->x11_unlock_display (this->display);
 	break;
 
     case GUI_DATA_EX_TRANSLATE_GUI_TO_VIDEO:
@@ -1020,10 +1023,10 @@
 static void opengl_exit (vo_driver_t *this_gen) {
     opengl_driver_t *this = (opengl_driver_t *) this_gen;
 
-    XLockDisplay (this->display);
+    this->x11_lock_display (this->display);
     if (this->cur_frame)
 	this->cur_frame->vo_frame.dispose (&this->cur_frame->vo_frame);
-    XUnlockDisplay (this->display);
+    this->x11_unlock_display (this->display);
 
     glXMakeCurrent (this->display, None, NULL);
     glXDestroyContext (this->display, this->context);
@@ -1073,6 +1076,10 @@
     this->drawable	    = None;      /* We need a different one with a dedicated visual anyway */
     this->context_state       = CONTEXT_BAD;
     this->cur_frame           = NULL;
+    this->x11_lock_display    = visual->lock_display_cb   ? visual->lock_display_cb
+                                                          : XLockDisplay
+    this->x11_unlock_display  = visual->unlock_display_cb ? visual->unlock_display_cb
+                                                          : XUnlockDisplay;
 
     this->vo_driver.get_capabilities     = opengl_get_capabilities;
     this->vo_driver.alloc_frame          = opengl_alloc_frame;
diff -ur xine-lib/src/video_out/video_out_pgx64.c xine-lib-new/src/video_out/video_out_pgx64.c
--- xine-lib/src/video_out/video_out_pgx64.c	Fri Aug 16 15:56:42 2002
+++ xine-lib-new/src/video_out/video_out_pgx64.c	Sat Aug 17 18:22:35 2002
@@ -120,6 +120,10 @@
   int win_x, win_y, old_win_x, old_win_y;
   int display_width, display_height, display_xoffset, display_yoffset;
   int correct_width, correct_height;
+
+  void (*x11_lock_display)   (Display *);
+  void (*x11_unlock_display) (Display *);
+
 } pgx64_driver_t;
 
 typedef struct {
@@ -367,9 +371,9 @@
       (this->win_y == 0)) {
     Window temp_window;
 
-    XLockDisplay(this->display);
+    this->x11_lock_display(this->display);
     XTranslateCoordinates(this->display, this->drawable, this->root, 0, 0, &this->win_x, &this->win_y, &temp_window);
-    XUnlockDisplay(this->display);
+    this->x11_unlock_display(this->display);
   }
 
   if ((this->force_update) ||
@@ -396,7 +400,7 @@
     this->display_xoffset = (this->dest_width - this->display_width) / 2 + this->dest_x;
     this->display_yoffset = (this->dest_height - this->display_height) / 2 + this->dest_y;
 
-    XLockDisplay(this->display);
+    this->x11_lock_display(this->display);
     XSetForeground(this->display, this->gc, BlackPixel(this->display, this->screen));
     XFillRectangle(this->display, this->drawable, this->gc, this->dest_x, this->dest_y, this->display_width, this->display_yoffset - this->dest_y);
     XFillRectangle(this->display, this->drawable, this->gc, this->dest_x, this->display_yoffset + this->display_height, this->dest_width, this->dest_height - (this->display_yoffset + this->display_height));
@@ -405,7 +409,7 @@
     XSetForeground(this->display, this->gc, this->colour_key);
     XFillRectangle(this->display, this->drawable, this->gc, this->display_xoffset, this->display_yoffset, this->display_width, this->display_height);
     XFlush(this->display);
-    XUnlockDisplay(this->display);
+    this->x11_unlock_display(this->display);
 
     write_reg(this, VIDEO_FORMAT, (frame->format == IMGFMT_YUY2) ? VIDEO_FORMAT_YUY2 : VIDEO_FORMAT_YUV12);
     write_reg(this, SCALER_BUF0_OFFSET, this->buf_y);
@@ -588,9 +592,9 @@
   switch (data_type) {
     case GUI_DATA_EX_DRAWABLE_CHANGED: {
       this->drawable = (Drawable)data;
-      XLockDisplay(this->display);
+      this->x11_lock_display(this->display);
       this->gc = XCreateGC(this->display, this->drawable, 0, NULL);
-      XUnlockDisplay(this->display);
+      this->x11_unlock_display(this->display);
     }
     break;
 
@@ -702,6 +706,11 @@
   this->fbbase = baseaddr;
   this->fbregs = baseaddr + REGBASE;
 
+  this->x11_lock_display    = visual->lock_display_cb   ? visual->lock_display_cb
+                                                        : XLockDisplay
+  this->x11_unlock_display  = visual->unlock_display_cb ? visual->unlock_display_cb
+                                                        : XUnlockDisplay;
+
   set_reg_bits(this, BUS_CNTL, BUS_EXT_REG_EN);
   write_reg(this, OVERLAY_SCALE_CNTL, 0x04000000);
   write_reg(this, SCALER_H_COEFF0, SCALER_H_COEFF0_DEFAULT);
diff -ur xine-lib/src/video_out/video_out_syncfb.c xine-lib-new/src/video_out/video_out_syncfb.c
--- xine-lib/src/video_out/video_out_syncfb.c	Sat Aug 17 18:09:34 2002
+++ xine-lib-new/src/video_out/video_out_syncfb.c	Sat Aug 17 18:20:08 2002
@@ -117,6 +117,9 @@
 
   int                video_win_visibility;
 
+  void (*x11_lock_display)   (Display *);
+  void (*x11_unlock_display) (Display *);
+
 };
 
 /*
@@ -329,14 +332,14 @@
 
 static void syncfb_clean_output_area(syncfb_driver_t* this)
 {
-  XLockDisplay (this->display);
+  this->x11_lock_display (this->display);
 
   XSetForeground (this->display, this->gc, this->black.pixel);
 
   XFillRectangle(this->display, this->drawable, this->gc,
 		 this->sc.gui_x, this->sc.gui_y, this->sc.gui_width, this->sc.gui_height);
 
-  XUnlockDisplay (this->display);
+  this->x11_unlock_display (this->display);
 }
 
 
@@ -948,6 +951,10 @@
   vo_scale_init( &this->sc, visual->display_ratio, 1, 0 );
   this->sc.frame_output_cb   = visual->frame_output_cb;
   this->sc.user_data         = visual->user_data;
+  this->x11_lock_display     = visual->lock_display_cb   ? visual->lock_display_cb
+                                                         : XLockDisplay;
+  this->x11_unlock_display   = visual->unlock_display_cb ? visual->unlock_display_cb
+                                                         : XUnlockDisplay;
 
   this->overlay              = NULL;
   this->screen               = visual->screen;   
diff -ur xine-lib/src/video_out/video_out_x11.h xine-lib-new/src/video_out/video_out_x11.h
--- xine-lib/src/video_out/video_out_x11.h	Thu Mar 21 18:29:51 2002
+++ xine-lib-new/src/video_out/video_out_x11.h	Sat Aug 17 18:12:30 2002
@@ -92,6 +92,19 @@
 			   int *dest_width, int *dest_height,
 			   int *win_x, int *win_y);
 
+  /*
+   * lock and unlock callbacks
+   *
+   * Some front-end tool-kits require you to use different
+   * locking functions than the X library's XLockDisplay
+   * and XUnlockDisplay to control multi-threaded access of
+   * the X display.  Set these callbacks if you wish to use
+   * your own locking functions.
+   */
+
+  void (*lock_display_cb) (Display *display);
+  void (*unlock_display_cb) (Display *display);
+
 } x11_visual_t;
 
 /*
diff -ur xine-lib/src/video_out/video_out_xshm.c xine-lib-new/src/video_out/video_out_xshm.c
--- xine-lib/src/video_out/video_out_xshm.c	Thu Aug 15 19:24:14 2002
+++ xine-lib-new/src/video_out/video_out_xshm.c	Sat Aug 17 18:16:16 2002
@@ -118,6 +118,8 @@
   vo_overlay_t      *overlay;
 
   int (*x11_old_error_handler)  (Display *, XErrorEvent *);
+  void (*x11_lock_display)      (Display *);
+  void (*x11_unlock_display)      (Display *);
 
 } xshm_driver_t;
 
@@ -351,9 +353,9 @@
   xshm_driver_t *this = (xshm_driver_t *) vo_img->driver;
 
   if (frame->image) {
-    XLockDisplay (this->display); 
+    this->x11_lock_display (this->display); 
     dispose_ximage (this, &frame->shminfo, frame->image);
-    XUnlockDisplay (this->display); 
+    this->x11_unlock_display (this->display); 
   }
 
   free (frame);
@@ -490,7 +492,7 @@
 	    frame->sc.output_width, frame->sc.output_height);
 #endif
 
-    XLockDisplay (this->display); 
+    this->x11_lock_display (this->display); 
 
     /*
      * (re-) allocate XImage
@@ -519,7 +521,7 @@
     frame->image = create_ximage (this, &frame->shminfo,
 				  frame->sc.output_width, frame->sc.output_height);
 
-    XUnlockDisplay (this->display); 
+    this->x11_unlock_display (this->display); 
 
     if (format == IMGFMT_YV12) {
       frame->vo_frame.pitches[0] = 8*((width + 7) / 8);
@@ -635,7 +637,7 @@
   
   memcpy( this->sc.border, frame->sc.border, sizeof(this->sc.border) );
   
-  XLockDisplay (this->display);
+  this->x11_lock_display (this->display);
 
   XSetForeground (this->display, this->gc, this->black.pixel);
   
@@ -646,7 +648,7 @@
                      this->sc.border[i].w, this->sc.border[i].h);
   }
 
-  XUnlockDisplay (this->display);
+  this->x11_unlock_display (this->display);
 }
 
 static int xshm_redraw_needed (vo_driver_t *this_gen) {
@@ -715,7 +717,7 @@
 
     this->cur_frame = frame;
     
-    XLockDisplay (this->display);
+    this->x11_lock_display (this->display);
 #ifdef LOG
     printf ("video_out_xshm: display locked...\n");
 #endif
@@ -748,7 +750,7 @@
       XFlush(this->display);
     }
 
-    XUnlockDisplay (this->display);
+    this->x11_unlock_display (this->display);
 
   }
 
@@ -856,7 +858,7 @@
       if (xev->count == 0) {
 	int i;
 	
-	XLockDisplay (this->display);
+	this->x11_lock_display (this->display);
 	
 	  if (this->use_shm) {
 	    
@@ -885,7 +887,7 @@
 
 	XFlush (this->display);
 	
-	XUnlockDisplay (this->display);
+	this->x11_unlock_display (this->display);
       }
       
     }
@@ -1044,6 +1046,10 @@
 					 0, NULL);
 
   this->x11_old_error_handler = NULL;
+  this->x11_lock_display      = visual->lock_display_cb   ? visual->lock_display_cb
+                                                          : XLockDisplay;
+  this->x11_unlock_display    = visual->unlock_display_cb ? visual->unlock_display_cb
+                                                          : XUnlockDisplay;
 
   this->vo_driver.get_capabilities     = xshm_get_capabilities;
   this->vo_driver.alloc_frame          = xshm_alloc_frame;
diff -ur xine-lib/src/video_out/video_out_xv.c xine-lib-new/src/video_out/video_out_xv.c
--- xine-lib/src/video_out/video_out_xv.c	Thu Aug 15 19:24:14 2002
+++ xine-lib-new/src/video_out/video_out_xv.c	Sat Aug 17 18:14:55 2002
@@ -134,6 +134,8 @@
   uint32_t           colorkey;
 
   int (*x11_old_error_handler)  (Display *, XErrorEvent *);
+  void (*x11_lock_display)      (Display *);
+  void (*x11_unlock_display)      (Display *);
 };
 
 int gX11Fail;
@@ -157,18 +159,18 @@
   if (frame->image) {
     
     if (this->use_shm) {
-      XLockDisplay (this->display);
+      this->x11_lock_display (this->display);
       XShmDetach (this->display, &frame->shminfo);
       XFree (frame->image);
-      XUnlockDisplay (this->display);
+      this->x11_unlock_display (this->display);
 
       shmdt (frame->shminfo.shmaddr);
       shmctl (frame->shminfo.shmid, IPC_RMID, NULL);
     }
     else {
-      XLockDisplay (this->display);
+      this->x11_lock_display (this->display);
       XFree (frame->image);
-      XUnlockDisplay (this->display);
+      this->x11_unlock_display (this->display);
     }
   }
 
@@ -389,7 +391,7 @@
 
     /* printf ("video_out_xv: updating frame to %d x %d (ratio=%d, format=%08x)\n",width,height,ratio_code,format); */
 
-    XLockDisplay (this->display);
+    this->x11_lock_display (this->display);
 
     /*
      * (re-) allocate xvimage
@@ -413,7 +415,7 @@
     frame->height = height;
     frame->format = format;
 
-    XUnlockDisplay (this->display);
+    this->x11_unlock_display (this->display);
   }
 
   frame->ratio_code = ratio_code;
@@ -433,7 +435,7 @@
        || (frame->width != this->deinterlace_frame.width)
        || (frame->height / xvscaling != this->deinterlace_frame.height )
        || (frame->format != this->deinterlace_frame.format)) {
-    XLockDisplay (this->display);
+    this->x11_lock_display (this->display);
 
     if( this->deinterlace_frame.image )
       dispose_ximage (this, &this->deinterlace_frame.shminfo,
@@ -446,7 +448,7 @@
     this->deinterlace_frame.height = frame->height / xvscaling;
     this->deinterlace_frame.format = frame->format;
 
-    XUnlockDisplay (this->display);
+    this->x11_unlock_display (this->display);
   }
 
   
@@ -523,7 +525,7 @@
 
 static void xv_clean_output_area (xv_driver_t *this) {
 
-  XLockDisplay (this->display);
+  this->x11_lock_display (this->display);
 
   XSetForeground (this->display, this->gc, this->black.pixel);
 
@@ -537,7 +539,7 @@
 		    this->sc.output_width, this->sc.output_height);
   }
   
-  XUnlockDisplay (this->display);
+  this->x11_unlock_display (this->display);
 }
 
 /*
@@ -691,7 +693,7 @@
      */
     xv_redraw_needed (this_gen);
 
-    XLockDisplay (this->display);
+    this->x11_lock_display (this->display);
 
     if (this->use_shm) {
       XvShmPutImage(this->display, this->xv_port,
@@ -713,7 +715,7 @@
 
     XFlush(this->display);
 
-    XUnlockDisplay (this->display);
+    this->x11_unlock_display (this->display);
     
   }
   /*
@@ -850,7 +852,7 @@
     if (this->cur_frame) {
       int i;
       
-      XLockDisplay (this->display);
+      this->x11_lock_display (this->display);
       
       if (this->use_shm) {
 	XvShmPutImage(this->display, this->xv_port,
@@ -879,7 +881,7 @@
 
       XFlush(this->display);
       
-      XUnlockDisplay (this->display);
+      this->x11_unlock_display (this->display);
     }
   }
   break;
@@ -923,11 +925,11 @@
     this->deinterlace_frame.image = NULL;
   }
 
-  XLockDisplay (this->display);
+  this->x11_lock_display (this->display);
   if(XvUngrabPort (this->display, this->xv_port, CurrentTime) != Success) {
     printf ("video_out_xv: xv_exit: XvUngrabPort() failed.\n");
   }
-  XUnlockDisplay (this->display);
+  this->x11_unlock_display (this->display);
 
   for( i=0; i < VO_NUM_RECENT_FRAMES; i++ )
   {
@@ -1147,6 +1149,10 @@
   this->use_colorkey      = 0;
   this->colorkey          = 0;
   this->x11_old_error_handler = NULL;
+  this->x11_lock_display      = visual->lock_display_cb   ? visual->lock_display_cb
+                                                          : XLockDisplay;
+  this->x11_unlock_display    = visual->unlock_display_cb ? visual->unlock_display_cb
+                                                          : XUnlockDisplay;
 
   XAllocNamedColor(this->display,
 		   DefaultColormap(this->display, this->screen),
