changeset 6953:ce67cc1f0beb

ignore BadAccess error at XSelectInput() (grabbing mouse etc) with warning patch Kazunori Ueno <jagarl@creator.club.ne.jp>
author arpi
date Fri, 09 Aug 2002 17:43:49 +0000
parents fc505cbab7ce
children 8e991cd2e727
files libvo/vo_gl.c libvo/vo_gl2.c libvo/vo_x11.c libvo/vo_xmga.c libvo/vo_xv.c libvo/vo_xvidix.c libvo/x11_common.c libvo/x11_common.h
diffstat 8 files changed, 37 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/libvo/vo_gl.c	Fri Aug 09 17:20:46 2002 +0000
+++ b/libvo/vo_gl.c	Fri Aug 09 17:43:49 2002 +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
--- a/libvo/vo_gl2.c	Fri Aug 09 17:20:46 2002 +0000
+++ b/libvo/vo_gl2.c	Fri Aug 09 17:43:49 2002 +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
--- a/libvo/vo_x11.c	Fri Aug 09 17:20:46 2002 +0000
+++ b/libvo/vo_x11.c	Fri Aug 09 17:43:49 2002 +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
--- a/libvo/vo_xmga.c	Fri Aug 09 17:20:46 2002 +0000
+++ b/libvo/vo_xmga.c	Fri Aug 09 17:43:49 2002 +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 
--- a/libvo/vo_xv.c	Fri Aug 09 17:20:46 2002 +0000
+++ b/libvo/vo_xv.c	Fri Aug 09 17:43:49 2002 +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
--- a/libvo/vo_xvidix.c	Fri Aug 09 17:20:46 2002 +0000
+++ b/libvo/vo_xvidix.c	Fri Aug 09 17:43:49 2002 +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
--- a/libvo/x11_common.c	Fri Aug 09 17:20:46 2002 +0000
+++ b/libvo/x11_common.c	Fri Aug 09 17:43:49 2002 +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)
--- a/libvo/x11_common.h	Fri Aug 09 17:20:46 2002 +0000
+++ b/libvo/x11_common.h	Fri Aug 09 17:43:49 2002 +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();