#include <iostream>
#include "glws.hpp"
+
#include "glproc.hpp"
}
}
-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:
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;
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
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) {
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);
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);
bool
processEvents(void) {
- XFlush(display);
while (XPending(display) > 0) {
XEvent event;
XNextEvent(display, &event);