chiark / gitweb /
allow pausing updates
authorIan Jackson <ian@davenant.relativity.greenend.org.uk>
Fri, 4 Jan 2008 19:21:00 +0000 (19:21 +0000)
committerIan Jackson <ian@davenant.relativity.greenend.org.uk>
Fri, 4 Jan 2008 19:21:00 +0000 (19:21 +0000)
view.c

diff --git a/view.c b/view.c
index 8983f622be5abed2d5f6bb9e5949bc781cd8967b..cc86803594841154686a48adb5c77aff1bb5b316 100644 (file)
--- a/view.c
+++ b/view.c
@@ -25,6 +25,7 @@ static GSL_MATRIX(transform);
 static FILE *input_f;
 static struct stat input_stab;
 static const char *input_filename;
+static int pause_updates;
 
 static void read_input(void) {
   int r;
@@ -173,7 +174,7 @@ static void drawtriangle(const Triangle *t) {
 
 static const unsigned long core_event_mask=
   ButtonPressMask|ButtonReleaseMask|StructureNotifyMask|ButtonMotionMask|
-  KeyPressMask;
+  KeyPressMask|SubstructureNotifyMask;
 
 static void mkpixmaps(void) {
   for (currentbuffer=0; currentbuffer<2; currentbuffer++) {
@@ -553,16 +554,22 @@ static void event_key(XKeyEvent *e) {
     return;
   }
 
-  if (!strcmp(buf,"q")) exit(0);
-  if (!strcmp(buf,"w")) {
+  if (!strcmp(buf,"q"))
+    exit(0);
+  else if (!strcmp(buf,"p"))
+    pause_updates= !pause_updates;
+  else if (!strcmp(buf,"w")) {
     wireframe= !wireframe;
     show();
     return;
-  }
-  if (!strcmp(buf,"d")) {
+  } else if (!strcmp(buf,"d")) {
     eyes_apart= eyes_apart>0 ? eyes_apart_min : eyes_apart_preferred;
     show();
     return;
+  } else {
+    printf("unknown key keycode=%d state=0x%x char=%c 0x%02x\n",
+          e->keycode, e->state, buf[0]>' ' && buf[0]<127 ? buf[0] : '?',
+          buf[0]);
   }
 }
 
@@ -658,7 +665,7 @@ int main(int argc, const char *const *argv) {
     polls[i].fd= ConnectionNumber(display);
     polls[i].events= wantedevents;
 
-    r= poll(polls, nxfds+1, motion_deferred ? 0 : 200);
+    r= poll(polls, nxfds+1, motion_deferred ? 0 : pause_updates ? -1 : 200);
     if (r<0) {
       if (errno==EINTR) continue;
       diee("poll");
@@ -674,7 +681,8 @@ int main(int argc, const char *const *argv) {
        event_motion(motion_x, motion_y);
        motion_deferred=0;
       }
-      check_input();
+      if (!pause_updates)
+       check_input();
       continue;
     }