summaryrefslogtreecommitdiff
path: root/progs
diff options
context:
space:
mode:
authorBrian Paul <brian.paul@tungstengraphics.com>2004-07-02 14:35:05 +0000
committerBrian Paul <brian.paul@tungstengraphics.com>2004-07-02 14:35:05 +0000
commitd07859e718767ef1dfd86ab5a80675aed0acf231 (patch)
tree2cb965e7269b4de98a6205f6b7bbe5650fe48c84 /progs
parent3bdc8535fc7be3e0524e9dd728ef9f63532fd789 (diff)
redo the event loop to make event response better
Diffstat (limited to 'progs')
-rw-r--r--progs/xdemos/glthreads.c50
1 files changed, 23 insertions, 27 deletions
diff --git a/progs/xdemos/glthreads.c b/progs/xdemos/glthreads.c
index 63a94c5568..e3d71ed0ad 100644
--- a/progs/xdemos/glthreads.c
+++ b/progs/xdemos/glthreads.c
@@ -1,4 +1,3 @@
-
/*
* Copyright (C) 2000 Brian Paul All Rights Reserved.
*
@@ -60,7 +59,7 @@ struct winthread {
#define MAX_WINTHREADS 100
static struct winthread WinThreads[MAX_WINTHREADS];
static int NumWinThreads = 0;
-static GLboolean ExitFlag = GL_FALSE;
+static volatile GLboolean ExitFlag = GL_FALSE;
@@ -186,33 +185,30 @@ draw_loop(struct winthread *wt)
static void
event_loop(Display *dpy)
{
- while (!ExitFlag) {
- static long mask = StructureNotifyMask | ExposureMask | KeyPressMask;
- XEvent event;
- int i;
+ XEvent event;
+ int i;
- for (i = 0; i < NumWinThreads; i++) {
- struct winthread *wt = &WinThreads[i];
- while (XCheckWindowEvent(dpy, wt->Win, mask, &event)) {
- if (event.xany.window == wt->Win) {
- switch (event.type) {
- case ConfigureNotify:
- resize(wt, event.xconfigure.width,
- event.xconfigure.height);
- break;
- case KeyPress:
- /* tell all threads to exit */
- ExitFlag = GL_TRUE;
- /*printf("exit draw_loop %d\n", wt->Index);*/
- return;
- default:
- /*no-op*/ ;
+ while (!ExitFlag) {
+ XNextEvent(dpy, &event);
+ switch (event.type) {
+ case ConfigureNotify:
+ /* Find winthread for this event's window */
+ for (i = 0; i < NumWinThreads; i++) {
+ struct winthread *wt = &WinThreads[i];
+ if (event.xconfigure.window == wt->Win) {
+ resize(wt, event.xconfigure.width,
+ event.xconfigure.height);
+ break;
}
}
- else {
- printf("window mismatch\n");
- }
- }
+ break;
+ case KeyPress:
+ /* tell all threads to exit */
+ ExitFlag = GL_TRUE;
+ /*printf("exit draw_loop %d\n", wt->Index);*/
+ return;
+ default:
+ /*no-op*/ ;
}
}
}
@@ -391,7 +387,7 @@ main(int argc, char *argv[])
for (i = 0; i < numThreads; i++) {
pthread_create(&WinThreads[i].Thread, NULL, thread_function,
(void*) &WinThreads[i]);
- printf("Created Thread %p\n", WinThreads[i].Thread);
+ printf("Created Thread %d\n", (int) WinThreads[i].Thread);
}
event_loop(dpy);