comparison src/video/x11/SDL_x11video.c @ 4559:f8c3870af5a2

Fixed X11 error when running under window managers that don't support the _NET_SUPPORTING_WM_CHECK protocol.
author Sam Lantinga <slouken@libsdl.org>
date Tue, 20 Jul 2010 00:57:01 -0700
parents a956a315fe67
children c24ba2cc9583
comparison
equal deleted inserted replaced
4558:4d95152d9e39 4559:f8c3870af5a2
239 VideoBootStrap X11_bootstrap = { 239 VideoBootStrap X11_bootstrap = {
240 "x11", "SDL X11 video driver", 240 "x11", "SDL X11 video driver",
241 X11_Available, X11_CreateDevice 241 X11_Available, X11_CreateDevice
242 }; 242 };
243 243
244 static int (*handler) (Display *, XErrorEvent *) = NULL;
245 static int
246 X11_CheckWindowManagerErrorHandler(Display * d, XErrorEvent * e)
247 {
248 if (e->error_code == BadWindow) {
249 return (0);
250 } else {
251 return (handler(d, e));
252 }
253 }
244 254
245 static void 255 static void
246 X11_CheckWindowManager(_THIS) 256 X11_CheckWindowManager(_THIS)
247 { 257 {
248 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; 258 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
255 Window wm_window = 0; 265 Window wm_window = 0;
256 #ifdef DEBUG_WINDOW_MANAGER 266 #ifdef DEBUG_WINDOW_MANAGER
257 char *wm_name; 267 char *wm_name;
258 #endif 268 #endif
259 269
270 /* Set up a handler to gracefully catch errors */
271 XSync(display, False);
272 handler = XSetErrorHandler(X11_CheckWindowManagerErrorHandler);
273
260 _NET_SUPPORTING_WM_CHECK = XInternAtom(display, "_NET_SUPPORTING_WM_CHECK", False); 274 _NET_SUPPORTING_WM_CHECK = XInternAtom(display, "_NET_SUPPORTING_WM_CHECK", False);
261 status = XGetWindowProperty(display, DefaultRootWindow(display), _NET_SUPPORTING_WM_CHECK, 0L, 1L, False, XA_WINDOW, &real_type, &real_format, &items_read, &items_left, &propdata); 275 status = XGetWindowProperty(display, DefaultRootWindow(display), _NET_SUPPORTING_WM_CHECK, 0L, 1L, False, XA_WINDOW, &real_type, &real_format, &items_read, &items_left, &propdata);
262 if (status == Success && items_read) { 276 if (status == Success && items_read) {
263 wm_window = ((Window*)propdata)[0]; 277 wm_window = ((Window*)propdata)[0];
264 } 278 }
265 XFree(propdata); 279 if (propdata) {
280 XFree(propdata);
281 }
282
283 if (wm_window) {
284 status = XGetWindowProperty(display, wm_window, _NET_SUPPORTING_WM_CHECK, 0L, 1L, False, XA_WINDOW, &real_type, &real_format, &items_read, &items_left, &propdata);
285 if (status != Success || !items_read || wm_window != ((Window*)propdata)[0]) {
286 wm_window = None;
287 }
288 if (propdata) {
289 XFree(propdata);
290 }
291 }
292
293 /* Reset the error handler, we're done checking */
294 XSync(display, False);
295 XSetErrorHandler(handler);
266 296
267 if (!wm_window) { 297 if (!wm_window) {
268 #ifdef DEBUG_WINDOW_MANAGER 298 #ifdef DEBUG_WINDOW_MANAGER
269 printf("Couldn't get _NET_SUPPORTING_WM_CHECK property\n"); 299 printf("Couldn't get _NET_SUPPORTING_WM_CHECK property\n");
270 #endif 300 #endif