From 1d17fa69c3b677f50bb2f7debfd959c9ae6c168e Mon Sep 17 00:00:00 2001 From: arpi Date: Fri, 9 Aug 2002 17:43:49 +0000 Subject: [PATCH] ignore BadAccess error at XSelectInput() (grabbing mouse etc) with warning patch Kazunori Ueno git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@6954 b3059339-0415-0410-9bf9-f77b7e298cf2 --- libvo/vo_gl.c | 2 +- libvo/vo_gl2.c | 2 +- libvo/vo_x11.c | 4 ++-- libvo/vo_xmga.c | 2 +- libvo/vo_xv.c | 4 ++-- libvo/vo_xvidix.c | 2 +- libvo/x11_common.c | 28 ++++++++++++++++++++++++++++ libvo/x11_common.h | 1 + 8 files changed, 37 insertions(+), 8 deletions(-) diff --git a/libvo/vo_gl.c b/libvo/vo_gl.c index f5c704b594..bee1767d45 100644 --- a/libvo/vo_gl.c +++ b/libvo/vo_gl.c @@ -204,7 +204,7 @@ config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uin // 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 diff --git a/libvo/vo_gl2.c b/libvo/vo_gl2.c index eb1cb65dba..800dc4a442 100644 --- a/libvo/vo_gl2.c +++ b/libvo/vo_gl2.c @@ -708,7 +708,7 @@ config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uin 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 diff --git a/libvo/vo_x11.c b/libvo/vo_x11.c index 4426401342..6675379b16 100644 --- a/libvo/vo_x11.c +++ b/libvo/vo_x11.c @@ -332,7 +332,7 @@ static uint32_t config( uint32_t width,uint32_t height,uint32_t d_width,uint32_t { 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 @@ static uint32_t config( uint32_t width,uint32_t height,uint32_t d_width,uint32_t 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 diff --git a/libvo/vo_xmga.c b/libvo/vo_xmga.c index bb55b88063..d98962dea4 100644 --- a/libvo/vo_xmga.c +++ b/libvo/vo_xmga.c @@ -293,7 +293,7 @@ static uint32_t config( uint32_t width, uint32_t height, uint32_t d_width, uint3 { 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 diff --git a/libvo/vo_xv.c b/libvo/vo_xv.c index d7d3fc96c6..5f23ec9206 100644 --- a/libvo/vo_xv.c +++ b/libvo/vo_xv.c @@ -383,7 +383,7 @@ static uint32_t config(uint32_t width, uint32_t height, uint32_t d_width, uint32 { 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 @@ static uint32_t config(uint32_t width, uint32_t height, uint32_t d_width, uint32 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 diff --git a/libvo/vo_xvidix.c b/libvo/vo_xvidix.c index 52db61e167..c606bd0ae8 100644 --- a/libvo/vo_xvidix.c +++ b/libvo/vo_xvidix.c @@ -292,7 +292,7 @@ else { 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 diff --git a/libvo/x11_common.c b/libvo/x11_common.c index 8536b29626..b51b272d85 100644 --- a/libvo/x11_common.c +++ b/libvo/x11_common.c @@ -840,7 +840,35 @@ void saver_off(Display *mDisplay) { // 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) diff --git a/libvo/x11_common.h b/libvo/x11_common.h index 89e976094e..e8b2516dfa 100644 --- a/libvo/x11_common.h +++ b/libvo/x11_common.h @@ -33,6 +33,7 @@ extern void vo_x11_decoration( Display * vo_Display,Window w,int d ); 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();