#endif
+/** Event handler results: */
+#define NOP 0
+#define EXIT 1
+#define DRAW 2
+
static GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0;
static GLint gear1, gear2, gear3;
static GLfloat angle = 0.0;
dt = t - tRot0;
tRot0 = t;
- /* advance rotation for next frame */
- angle += 70.0 * dt; /* 70 degrees per second */
- if (angle > 3600.0)
- angle -= 3600.0;
+ if (animate) {
+ /* advance rotation for next frame */
+ angle += 70.0 * dt; /* 70 degrees per second */
+ if (angle > 3600.0)
+ angle -= 3600.0;
+ }
draw_gears();
glXSwapBuffers(dpy, win);
attr.border_pixel = 0;
attr.colormap = XCreateColormap( dpy, root, visinfo->visual, AllocNone);
attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
+ /* XXX this is a bad way to get a borderless window! */
attr.override_redirect = fullscreen;
mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask | CWOverrideRedirect;
/**
* Handle one X event.
- * \return 1 if time to exit, 0 otherwise
+ * \return NOP, EXIT or DRAW
*/
static int
handle_event(Display *dpy, Window win, XEvent *event)
{
switch (event->type) {
case Expose:
- /* we'll redraw below */
- break;
+ return DRAW;
case ConfigureNotify:
reshape(event->xconfigure.width, event->xconfigure.height);
break;
NULL, NULL);
if (buffer[0] == 27) {
/* escape */
- return 1;
+ return EXIT;
}
else if (buffer[0] == 'a' || buffer[0] == 'A') {
animate = !animate;
}
}
+ return DRAW;
}
}
- return 0;
+ return NOP;
}
event_loop(Display *dpy, Window win)
{
while (1) {
+ int op;
while (!animate || XPending(dpy) > 0) {
XEvent event;
XNextEvent(dpy, &event);
- if (handle_event(dpy, win, &event))
+ op = handle_event(dpy, win, &event);
+ if (op == EXIT)
return;
+ else if (op == DRAW)
+ break;
}
draw_frame(dpy, win);