Navigation Menu

Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Fixed X11 error when running under window managers that don't support…
Browse files Browse the repository at this point in the history
… the _NET_SUPPORTING_WM_CHECK protocol.
  • Loading branch information
slouken committed Jul 20, 2010
1 parent eceab3f commit 545c43e
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/video/x11/SDL_x11video.c
Expand Up @@ -241,6 +241,16 @@ VideoBootStrap X11_bootstrap = {
X11_Available, X11_CreateDevice
};

static int (*handler) (Display *, XErrorEvent *) = NULL;
static int
X11_CheckWindowManagerErrorHandler(Display * d, XErrorEvent * e)
{
if (e->error_code == BadWindow) {
return (0);
} else {
return (handler(d, e));
}
}

static void
X11_CheckWindowManager(_THIS)
Expand All @@ -257,12 +267,32 @@ X11_CheckWindowManager(_THIS)
char *wm_name;
#endif

/* Set up a handler to gracefully catch errors */
XSync(display, False);
handler = XSetErrorHandler(X11_CheckWindowManagerErrorHandler);

_NET_SUPPORTING_WM_CHECK = XInternAtom(display, "_NET_SUPPORTING_WM_CHECK", False);
status = XGetWindowProperty(display, DefaultRootWindow(display), _NET_SUPPORTING_WM_CHECK, 0L, 1L, False, XA_WINDOW, &real_type, &real_format, &items_read, &items_left, &propdata);
if (status == Success && items_read) {
wm_window = ((Window*)propdata)[0];
}
XFree(propdata);
if (propdata) {
XFree(propdata);
}

if (wm_window) {
status = XGetWindowProperty(display, wm_window, _NET_SUPPORTING_WM_CHECK, 0L, 1L, False, XA_WINDOW, &real_type, &real_format, &items_read, &items_left, &propdata);
if (status != Success || !items_read || wm_window != ((Window*)propdata)[0]) {
wm_window = None;
}
if (propdata) {
XFree(propdata);
}
}

/* Reset the error handler, we're done checking */
XSync(display, False);
XSetErrorHandler(handler);

if (!wm_window) {
#ifdef DEBUG_WINDOW_MANAGER
Expand Down

0 comments on commit 545c43e

Please sign in to comment.