chiark / gitweb /
keystrokes
authorIan Jackson <ian@davenant.relativity.greenend.org.uk>
Mon, 31 Dec 2007 16:03:29 +0000 (16:03 +0000)
committerIan Jackson <ian@davenant.relativity.greenend.org.uk>
Mon, 31 Dec 2007 16:03:29 +0000 (16:03 +0000)
view.c

diff --git a/view.c b/view.c
index abecc7c..712623c 100644 (file)
--- a/view.c
+++ b/view.c
@@ -120,6 +120,8 @@ XVisualInfo visinfo;
 static double sizeadj_scale= 0.3, eyes_apart, scale_wmindim;
 static double eye_z= -10, eye_x=0;
 static double cut_z= -9;
+static const double eyes_apart_preferred=0.05, eyes_apart_min= -0.02;
+
 
 static void drawtriangle(const Triangle *t) {
   XPoint points[4];
@@ -146,7 +148,8 @@ static void drawtriangle(const Triangle *t) {
 }
 
 static const unsigned long core_event_mask=
-  ButtonPressMask|ButtonReleaseMask|StructureNotifyMask|ButtonMotionMask;
+  ButtonPressMask|ButtonReleaseMask|StructureNotifyMask|ButtonMotionMask|
+  KeyPressMask;
 
 static void mkpixmaps(void) {
   for (currentbuffer=0; currentbuffer<2; currentbuffer++) {
@@ -214,11 +217,13 @@ static void display_conformation(void) {
   XA( XFillRectangle(display,pixmap,dmwhite.fillgc,0,0,wwidth,wheight) );
 
   if (eyes_apart > 0) {
-    const double preferred=0.05, beyond=0.07;
+    const double stationary= 0.07;
 
-    eye_x= eyes_apart < preferred ? eyes_apart :
-           eyes_apart < beyond ? preferred :
-           eyes_apart - (beyond - preferred);
+    eye_x= eyes_apart < eyes_apart_preferred
+              ? eyes_apart :
+           eyes_apart < (eyes_apart_preferred + stationary)
+              ? eyes_apart_preferred
+              : eyes_apart - stationary;
     eye_x /= sizeadj_scale;
     drawtriangles(&dmblue);
     eye_x= -eye_x;
@@ -407,9 +412,8 @@ static void drag_sizeadj_delta(double dx, double dy) {
 DRAG_SAVING(sizeadj, sizeadj_scale);
 
 static void drag_3d_delta(double dx, double dy) {
-  const double min_eyes_apart= -0.02;
   eyes_apart += dx * 0.1;
-  if (eyes_apart < min_eyes_apart) eyes_apart= min_eyes_apart;
+  if (eyes_apart < eyes_apart_min) eyes_apart= eyes_apart_min;
   printf("sizeadj eyes_apart %g\n", eyes_apart);
   show();
 }
@@ -461,6 +465,26 @@ static void event_motion(int x, int y) {
   drag_position(x,y);
 }
 
+static void event_key(XKeyEvent *e) {
+  KeySym ks;
+  char buf[10];
+  int r;
+
+  r= XLookupString(e,buf,sizeof(buf)-1,&ks,0);
+  if (!r) {
+    printf("XLookupString keycode=%u state=0x%x gave %d\n",
+          e->keycode, e->state, r);
+    return;
+  }
+
+  if (!strcmp(buf,"q")) exit(0);
+  if (!strcmp(buf,"d")) {
+    eyes_apart= eyes_apart>0 ? eyes_apart_min : eyes_apart_preferred;
+    show();
+    return;
+  }
+}
+
 static void event_config(XConfigureEvent *e) {
   if (e->width == wwidth && e->height == wheight)
     return;
@@ -555,6 +579,8 @@ int main(int argc, const char *const *argv) {
     case ButtonPress:
     case ButtonRelease:     event_button(&event.xbutton);     break;
       
+    case KeyPress:          event_key(&event.xkey);           break;
+
     case ConfigureNotify:   event_config(&event.xconfigure);  break;
 
     case MotionNotify: