grab the server while getting the pixmap for the window, and make sure the window...
authorDana Jansens <danakj@orodu.net>
Sat, 9 Feb 2008 04:13:39 +0000 (23:13 -0500)
committerDana Jansens <danakj@orodu.net>
Sat, 9 Feb 2008 04:13:39 +0000 (23:13 -0500)
loco/loco.c

index 29a2b30..b28f4ef 100644 (file)
@@ -125,10 +125,17 @@ static void timeadd(GTimeVal *t, glong microseconds)
     }
 }
 
+static Bool look_for_destroy_notify(Display *d, XEvent *e, XPointer arg)
+{
+    const Window w = (Window)*arg;
+    return e->type == DestroyNotify && e->xdestroywindow.window == w;
+}
+
 gboolean create_glxpixmap(LocoWindow *lw)
 {
     static const int attrs[] =
         { GLX_TEXTURE_FORMAT_EXT, GLX_TEXTURE_FORMAT_RGBA_EXT, None };
+    XEvent ce;
 
     if (!glxFBConfig[lw->depth]) {
         printf("no glxFBConfig for depth %d for window 0x%lx\n",
@@ -136,14 +143,25 @@ gboolean create_glxpixmap(LocoWindow *lw)
         return FALSE;
     }
 
-    lw->pixmap = XCompositeNameWindowPixmap(obt_display, lw->id);
-    lw->glpixmap = glXCreatePixmap(obt_display, glxFBConfig[lw->depth],
-                                   lw->pixmap, attrs);
-    if (!lw->glpixmap) {
-        XFreePixmap(obt_display, lw->pixmap);
-        lw->pixmap = None;
+    /* make sure the window exists */
+    XGrabServer(obt_display);
+    XSync(obt_display, FALSE);
+
+    if (!XCheckIfEvent(obt_display, &ce, look_for_destroy_notify,
+                       (XPointer)&lw->id))
+    {
+        lw->pixmap = XCompositeNameWindowPixmap(obt_display, lw->id);
+        lw->glpixmap = glXCreatePixmap(obt_display, glxFBConfig[lw->depth],
+                                       lw->pixmap, attrs);
+        if (!lw->glpixmap) {
+            XFreePixmap(obt_display, lw->pixmap);
+            lw->pixmap = None;
+        }
     }
 
+    XUngrabServer(obt_display);
+    XFlush(obt_display);
+
     return !!lw->glpixmap;
 }