[MPlayer-dev-eng] [patch] XSelectInput error handling

Kazunori Ueno jagarl at creator.club.ne.jp
Tue Aug 6 13:49:46 CEST 2002


Hello.

With -wid option, mplayer uses another application's window.
But mplayer catch BadAccess error when the application has
mouse control (ButtonPressMask) of the window.
( "Only one client can select a ButtonPress" ; from man XSelectInput.)

This patch changes the mplayer's behavier at this condition.

o Print the detailed information of the error.
  It must help a programmer when he uses mplayer in his application.

o Discards mouse control when this error occurs.

---
Kazunori Ueno / Univ. of Tokyo.
-------------- next part --------------
Index: libvo/x11_common.c
===================================================================
RCS file: /cvsroot/mplayer/main/libvo/x11_common.c,v
retrieving revision 1.93
diff -u -r1.93 x11_common.c
--- libvo/x11_common.c	12 Jun 2002 22:57:58 -0000	1.93
+++ libvo/x11_common.c	6 Aug 2002 12:03:09 -0000
@@ -840,7 +840,35 @@
 		    // turning off screensaver
 }
 
+static XErrorHandler old_handler = NULL;
+static int selectinput_err = 0;
+static int x11_selectinput_errorhandler(Display *display, XErrorEvent *event)
+{
+	if (event->error_code == BadAccess) {
+		selectinput_err = 1;
+		mp_msg(MSGT_VO, MSGL_ERR, "X11 error : BadAccess during XSelectInput Call\n");
+		mp_msg(MSGT_VO, MSGL_ERR, "X11 error : The 'ButtonPressMask' mask of specified window has probably already used by another appication(see man XSelectInput) \n");
+		/* If you think mplayer should shutdown with this error, comments out following line */
+		return 0;
+	}
+	if (old_handler != NULL) old_handler(display, event);
+	else x11_errorhandler(display, event);
+	return 0;
+}
 
+void vo_x11_selectinput_witherr(Display *display, Window w, long event_mask)
+{
+	XSync(display, False);
+	old_handler = XSetErrorHandler(x11_selectinput_errorhandler);
+	selectinput_err = 0;
+	XSelectInput(display, w, event_mask);
+	XSync(display, False);
+	XSetErrorHandler(old_handler);
+	if (selectinput_err) {
+		mp_msg(MSGT_VO, MSGL_ERR, "X11 error : Mplayer discards mouse control and retry XSelectInput...\n");
+		XSelectInput(display, w, event_mask & (~(ButtonPressMask | ButtonReleaseMask | PointerMotionMask)) );
+	}
+}
 
 #ifdef HAVE_XINERAMA
 void vo_x11_xinerama_move(Display *dsp, Window w)
Index: libvo/vo_gl.c
===================================================================
RCS file: /cvsroot/mplayer/main/libvo/vo_gl.c,v
retrieving revision 1.27
diff -u -r1.27 vo_gl.c
--- libvo/vo_gl.c	27 May 2002 17:47:10 -0000	1.27
+++ libvo/vo_gl.c	6 Aug 2002 12:03:08 -0000
@@ -204,7 +204,7 @@
 //	bpp = myximage->bits_per_pixel;
 
 	//XSelectInput(mDisplay, vo_window, StructureNotifyMask); // !!!!
-        XSelectInput(mDisplay, vo_window, StructureNotifyMask | KeyPressMask | PointerMotionMask
+	vo_x11_selectinput_witherr(mDisplay, vo_window, StructureNotifyMask | KeyPressMask | PointerMotionMask
 #ifdef HAVE_NEW_INPUT
 		     | ButtonPressMask | ButtonReleaseMask
 #endif
Index: libvo/vo_gl2.c
===================================================================
RCS file: /cvsroot/mplayer/main/libvo/vo_gl2.c,v
retrieving revision 1.20
diff -u -r1.20 vo_gl2.c
--- libvo/vo_gl2.c	27 May 2002 17:48:54 -0000	1.20
+++ libvo/vo_gl2.c	6 Aug 2002 12:03:09 -0000
@@ -708,7 +708,7 @@
 	XSync(mDisplay, False);
 
 	//XSelectInput(mDisplay, vo_window, StructureNotifyMask); // !!!!
-        XSelectInput(mDisplay, vo_window, StructureNotifyMask | KeyPressMask | PointerMotionMask
+        vo_x11_selectinput_witherr(mDisplay, vo_window, StructureNotifyMask | KeyPressMask | PointerMotionMask
 #ifdef HAVE_NEW_INPUT
 		 | ButtonPressMask | ButtonReleaseMask
 #endif
Index: libvo/vo_x11.c
===================================================================
RCS file: /cvsroot/mplayer/main/libvo/vo_x11.c,v
retrieving revision 1.114
diff -u -r1.114 vo_x11.c
--- libvo/vo_x11.c	31 Jul 2002 19:40:33 -0000	1.114
+++ libvo/vo_x11.c	6 Aug 2002 12:03:09 -0000
@@ -332,7 +332,7 @@
        {
         XUnmapWindow( mDisplay,vo_window );
         XChangeWindowAttributes( mDisplay,vo_window,xswamask,&xswa );
-	XSelectInput( mDisplay,vo_window,StructureNotifyMask | KeyPressMask | PropertyChangeMask | PointerMotionMask | ButtonPressMask | ButtonReleaseMask | ExposureMask );
+	vo_x11_selectinput_witherr( mDisplay,vo_window,StructureNotifyMask | KeyPressMask | PropertyChangeMask | PointerMotionMask | ButtonPressMask | ButtonReleaseMask | ExposureMask );
 	XMapWindow( mDisplay,vo_window );
        } else XSelectInput( mDisplay,vo_window,ExposureMask );
     }
@@ -362,7 +362,7 @@
     XSync( mDisplay,False );
 
     // we cannot grab mouse events on root window :(
-    XSelectInput( mDisplay,vo_window,StructureNotifyMask | KeyPressMask | PropertyChangeMask | ExposureMask |
+    vo_x11_selectinput_witherr( mDisplay,vo_window,StructureNotifyMask | KeyPressMask | PropertyChangeMask | ExposureMask |
 	((WinID==0)?0:(ButtonPressMask | ButtonReleaseMask | PointerMotionMask)) );
 
 #ifdef HAVE_XF86VM
Index: libvo/vo_xmga.c
===================================================================
RCS file: /cvsroot/mplayer/main/libvo/vo_xmga.c,v
retrieving revision 1.74
diff -u -r1.74 vo_xmga.c
--- libvo/vo_xmga.c	19 Jul 2002 20:51:47 -0000	1.74
+++ libvo/vo_xmga.c	6 Aug 2002 12:03:09 -0000
@@ -293,7 +293,7 @@
        {
         XUnmapWindow( mDisplay,vo_window );
         XChangeWindowAttributes( mDisplay,vo_window,xswamask,&xWAttribs);
-        XSelectInput( mDisplay,vo_window,StructureNotifyMask | KeyPressMask | PropertyChangeMask | PointerMotionMask | ButtonPressMask | ButtonReleaseMask | ExposureMask );
+        vo_x11_selectinput_witherr( mDisplay,vo_window,StructureNotifyMask | KeyPressMask | PropertyChangeMask | PointerMotionMask | ButtonPressMask | ButtonReleaseMask | ExposureMask );
        } else XSelectInput( mDisplay,vo_window,ExposureMask );
        
     } else 
Index: libvo/vo_xv.c
===================================================================
RCS file: /cvsroot/mplayer/main/libvo/vo_xv.c,v
retrieving revision 1.111
diff -u -r1.111 vo_xv.c
--- libvo/vo_xv.c	25 Jul 2002 20:23:18 -0000	1.111
+++ libvo/vo_xv.c	6 Aug 2002 12:03:09 -0000
@@ -383,7 +383,7 @@
        {
         XUnmapWindow( mDisplay,vo_window );
         XChangeWindowAttributes( mDisplay,vo_window,xswamask,&xswa );
-	XSelectInput( mDisplay,vo_window,StructureNotifyMask | KeyPressMask | PropertyChangeMask | PointerMotionMask | ButtonPressMask | ButtonReleaseMask | ExposureMask );
+	vo_x11_selectinput_witherr( mDisplay,vo_window,StructureNotifyMask | KeyPressMask | PropertyChangeMask | PointerMotionMask | ButtonPressMask | ButtonReleaseMask | ExposureMask );
         XMapWindow( mDisplay,vo_window );
        } else { drwX=vo_dx; drwY=vo_dy; }
     } else 
@@ -395,7 +395,7 @@
         vo_x11_classhint( mDisplay,vo_window,"xv" );
         vo_hidecursor(mDisplay,vo_window);
 
-        XSelectInput(mDisplay, vo_window, StructureNotifyMask | KeyPressMask | PropertyChangeMask |
+        vo_x11_selectinput_witherr(mDisplay, vo_window, StructureNotifyMask | KeyPressMask | PropertyChangeMask |
 	((WinID==0) ? 0 : (PointerMotionMask
 #ifdef HAVE_NEW_INPUT
 		| ButtonPressMask | ButtonReleaseMask
Index: libvo/vo_xvidix.c
===================================================================
RCS file: /cvsroot/mplayer/main/libvo/vo_xvidix.c,v
retrieving revision 1.49
diff -u -r1.49 vo_xvidix.c
--- libvo/vo_xvidix.c	30 Jul 2002 16:40:42 -0000	1.49
+++ libvo/vo_xvidix.c	6 Aug 2002 12:03:09 -0000
@@ -292,7 +292,7 @@
 	 {
 	  XUnmapWindow(mDisplay, vo_window);
 	  XChangeWindowAttributes(mDisplay, vo_window, xswamask, &xswa);
-	  XSelectInput( mDisplay,vo_window,StructureNotifyMask | KeyPressMask | PropertyChangeMask | PointerMotionMask | ButtonPressMask | ButtonReleaseMask | ExposureMask );
+	  vo_x11_selectinput_witherr( mDisplay,vo_window,StructureNotifyMask | KeyPressMask | PropertyChangeMask | PointerMotionMask | ButtonPressMask | ButtonReleaseMask | ExposureMask );
 	 } else XSelectInput( mDisplay,vo_window,ExposureMask );
     }
     else
Index: libvo/x11_common.h
===================================================================
RCS file: /cvsroot/mplayer/main/libvo/x11_common.h,v
retrieving revision 1.25
diff -u -r1.25 x11_common.h
--- libvo/x11_common.h	13 Jun 2002 00:26:17 -0000	1.25
+++ libvo/x11_common.h	6 Aug 2002 12:03:09 -0000
@@ -33,6 +33,7 @@
 extern void vo_x11_classhint( Display * display,Window window,char *name );
 extern void vo_x11_sizehint( int x, int y, int width, int height, int max );
 extern int vo_x11_check_events(Display *mydisplay);
+extern void vo_x11_selectinput_witherr(Display *display, Window w, long event_mask);
 extern void vo_x11_fullscreen( void );
 extern void vo_x11_uninit();
 


More information about the MPlayer-dev-eng mailing list