]> git.cworth.org Git - apitrace/blobdiff - glws_glx.cpp
apitrace: Replace tracedump program with new "apitrace dump" command
[apitrace] / glws_glx.cpp
index 23b4082d0a577414522a67f6c62d0d1ee224ec60..3c49de81309dd25983da7a3eca51efee5d14f3a1 100644 (file)
@@ -29,6 +29,7 @@
 #include <iostream>
 
 #include "glws.hpp"
+
 #include "glproc.hpp"
 
 
@@ -86,17 +87,6 @@ static void describeEvent(const XEvent &event) {
     }
 }
 
-static void waitForEvent(Window window, int type) {
-    XFlush(display);
-    XEvent event;
-    do {
-        XNextEvent(display, &event);
-        describeEvent(event);
-    } while (event.type != type ||
-             event.xany.window != window);
-}
-
-
 class GlxDrawable : public Drawable
 {
 public:
@@ -114,7 +104,7 @@ public:
         attr.background_pixel = 0;
         attr.border_pixel = 0;
         attr.colormap = XCreateColormap(display, root, visinfo->visual, AllocNone);
-        attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
+        attr.event_mask = StructureNotifyMask;
 
         unsigned long mask;
         mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
@@ -147,12 +137,24 @@ public:
         glXWaitX();
     }
 
+    void waitForEvent(int type) {
+        XEvent event;
+        do {
+            XWindowEvent(display, window, StructureNotifyMask, &event);
+            describeEvent(event);
+        } while (event.type != type);
+    }
+
     ~GlxDrawable() {
         XDestroyWindow(display, window);
     }
 
     void
     resize(int w, int h) {
+        if (w == width && h == height) {
+            return;
+        }
+
         glXWaitGL();
 
         // We need to ensure that pending events are processed here, and XSync
@@ -165,27 +167,31 @@ public:
         XResizeWindow(display, window, w, h);
 
         // Tell the window manager to respect the requested size
-        XSizeHints *size_hints;
-        size_hints = XAllocSizeHints();
-        size_hints->max_width  = size_hints->min_width  = w;
-        size_hints->max_height = size_hints->min_height = h;
-        size_hints->flags = PMinSize | PMaxSize;
-        XSetWMNormalHints(display, window, size_hints);
-        XFree(size_hints);
+        XSizeHints size_hints;
+        size_hints.max_width  = size_hints.min_width  = w;
+        size_hints.max_height = size_hints.min_height = h;
+        size_hints.flags = PMinSize | PMaxSize;
+        XSetWMNormalHints(display, window, &size_hints);
 
-        waitForEvent(window, ConfigureNotify);
+        waitForEvent(ConfigureNotify);
 
         glXWaitX();
     }
 
     void show(void) {
-        if (!visible) {
-            XMapWindow(display, window);
+        if (visible) {
+            return;
+        }
 
-            waitForEvent(window, Expose);
+        glXWaitGL();
 
-            Drawable::show();
-        }
+        XMapWindow(display, window);
+
+        waitForEvent(MapNotify);
+
+        glXWaitX();
+
+        Drawable::show();
     }
 
     void swapBuffers(void) {
@@ -297,7 +303,6 @@ createContext(const Visual *_visual, Context *shareContext)
         share_context = dynamic_cast<GlxContext*>(shareContext)->context;
     }
 
-
     if (glxVersion >= 0x0104 && has_GLX_ARB_create_context) {
         Attributes<int> attribs;
         attribs.add(GLX_RENDER_TYPE, GLX_RGBA_TYPE);
@@ -307,7 +312,8 @@ createContext(const Visual *_visual, Context *shareContext)
         attribs.end();
 
         context = glXCreateContextAttribsARB(display, visual->fbconfig, share_context, True, attribs);
-    } else if (glxVersion >= 0x103) {
+    } else 
+           if (glxVersion >= 0x103) {
         context = glXCreateNewContext(display, visual->fbconfig, GLX_RGBA_TYPE, share_context, True);
     } else {
         context = glXCreateContext(display, visual->visinfo, share_context, True);
@@ -331,7 +337,6 @@ makeCurrent(Drawable *drawable, Context *context)
 
 bool
 processEvents(void) {
-    XFlush(display);
     while (XPending(display) > 0) {
         XEvent event;
         XNextEvent(display, &event);