summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Paul <brian.paul@tungstengraphics.com>2008-06-04 16:11:24 -0600
committerBrian Paul <brian.paul@tungstengraphics.com>2008-06-04 16:11:24 -0600
commit4c7a17c2517510a608da853f0b6b3b8b2cae52d2 (patch)
tree9fa06fca479ae1a10cb2f4f508ae1d6097319c6b
parent6d9c3fa0c2aee1bcddc414781ef5ab54873e4de8 (diff)
fix event handling issues (such as when resizing when not animating)
-rw-r--r--progs/xdemos/glxgears.c32
1 files changed, 22 insertions, 10 deletions
diff --git a/progs/xdemos/glxgears.c b/progs/xdemos/glxgears.c
index f8c6c75ce5..c98c3157b5 100644
--- a/progs/xdemos/glxgears.c
+++ b/progs/xdemos/glxgears.c
@@ -88,6 +88,11 @@ current_time(void)
#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;
@@ -322,10 +327,12 @@ draw_frame(Display *dpy, Window win)
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);
@@ -471,6 +478,7 @@ make_window( Display *dpy, const char *name,
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;
@@ -506,15 +514,14 @@ make_window( Display *dpy, const char *name,
/**
* 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;
@@ -540,15 +547,16 @@ handle_event(Display *dpy, Window win, XEvent *event)
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;
}
@@ -556,11 +564,15 @@ static void
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);