Catch X11 extension errors...since most of these are notifications that we

queried for a missing extension (such as the XiG vidmode one that most
 people don't have), and default Xlib behaviour is to write notification to
 stderr, this tends to generate incorrect bug reports.

Since we'll actually deal with the missing extension when querying for it,
 we ignore these errors in our hook. The rest continue to pass through to
 the default handler.

Fixes Bugzilla #42.

--ryan.

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%401251
This commit is contained in:
Ryan C. Gordon 2006-01-14 08:15:38 +00:00
parent 0eb1d37f73
commit 37f6992829
3 changed files with 31 additions and 2 deletions

View file

@ -57,6 +57,7 @@ extern "C" {
typedef Bool (*SDL_X11_XESetWireToEventRetType)(Display*,XEvent*,xEvent*);
typedef int (*SDL_X11_XSynchronizeRetType)(Display*);
typedef Status (*SDL_X11_XESetEventToWireRetType)(Display*,XEvent*,xEvent*);
typedef int (*SDL_X11_XSetExtensionErrorHandlerType)(Display *,char *,char *);
#define SDL_X11_SYM(req,ret,fn,params) extern ret (*p##fn) params;
#include "SDL_x11sym.h"

View file

@ -113,6 +113,8 @@ SDL_X11_SYM(1,void,XextDestroyExtension,(XExtensionInfo*))
SDL_X11_SYM(1,XExtDisplayInfo*,XextFindDisplay,(XExtensionInfo*,Display*))
SDL_X11_SYM(1,int,XextRemoveDisplay,(XExtensionInfo*,Display*))
SDL_X11_SYM(1,Bool,XQueryExtension,(Display*,_Xconst char*,int*,int*,int*))
SDL_X11_SYM(1,char *,XDisplayString,(Display*))
SDL_X11_SYM(1,int,XGetErrorText,(Display*,int,char*,int))
#ifdef X_HAVE_UTF8_STRING
SDL_X11_SYM(1,int,Xutf8TextListToTextProperty,(Display*,char**,int,XICCEncodingStyle,XTextProperty*))
@ -159,6 +161,7 @@ SDL_X11_SYM(1,Bool,XShmQueryExtension,(Display*))
SDL_X11_SYM(1,SDL_X11_XSynchronizeRetType,XSynchronize,(Display*,Bool))
SDL_X11_SYM(1,SDL_X11_XESetWireToEventRetType,XESetWireToEvent,(Display*,int,SDL_X11_XESetWireToEventRetType))
SDL_X11_SYM(1,SDL_X11_XESetEventToWireRetType,XESetEventToWire,(Display*,int,SDL_X11_XESetEventToWireRetType))
SDL_X11_SYM(1,SDL_X11_XSetExtensionErrorHandlerType,XSetExtensionErrorHandler,(SDL_X11_XSetExtensionErrorHandlerType))
/* end of SDL_x11sym.h ... */

View file

@ -220,7 +220,7 @@ static int x_errhandler(Display *d, XErrorEvent *e)
(e->error_code <= (vm_error+XF86VidModeNumberErrors)))) ) {
#ifdef XFREE86_DEBUG
{ char errmsg[1024];
XGetErrorText(d, e->error_code, errmsg, sizeof(errmsg));
pXGetErrorText(d, e->error_code, errmsg, sizeof(errmsg));
printf("VidMode error: %s\n", errmsg);
}
#endif
@ -235,7 +235,7 @@ printf("VidMode error: %s\n", errmsg);
(e->error_code <= (dga_error+XF86DGANumberErrors))) ) {
#ifdef XFREE86_DEBUG
{ char errmsg[1024];
XGetErrorText(d, e->error_code, errmsg, sizeof(errmsg));
pXGetErrorText(d, e->error_code, errmsg, sizeof(errmsg));
printf("DGA error: %s\n", errmsg);
}
#endif
@ -262,6 +262,28 @@ static int xio_errhandler(Display *d)
return(XIO_handler(d));
}
static int (*Xext_handler)(Display *,char *,char *) = NULL;
static int xext_errhandler(Display *d, char *ext_name, char *reason)
{
#ifdef XFREE86_DEBUG
printf("Xext error inside SDL (may be harmless):\n");
printf(" Extension \"%s\" %s on display \"%s\".\n",
ext_name, reason, pXDisplayString(d));
#endif
if (strcmp(reason, "missing") == 0) {
/*
* Since the query itself, elsewhere, can handle a missing extension
* and the default behaviour in Xlib is to write to stderr, which
* generates unnecessary bug reports, we just ignore these.
*/
return 0;
}
/* Everything else goes to the default handler... */
return Xext_handler(d, ext_name, reason);
}
/* Create auxiliary (toplevel) windows with the current visual */
static void create_aux_windows(_THIS)
{
@ -438,6 +460,9 @@ static int X11_VideoInit(_THIS, SDL_PixelFormat *vformat)
/* Set the error handler if we lose the X display */
XIO_handler = pXSetIOErrorHandler(xio_errhandler);
/* Set the X extension error handler */
Xext_handler = pXSetExtensionErrorHandler(xext_errhandler);
/* use default screen (from $DISPLAY) */
SDL_Screen = DefaultScreen(SDL_Display);