From http://www.jwz.org/xscreensaver/xscreensaver-5.16.tar.gz
[xscreensaver] / hacks / glx / crackberg.c
index 95787ab08ab6a534f0141d2babaf3df80ececc9f..c4e925c73670fdcc389bce8954db781cad9f0004 100644 (file)
@@ -1,8 +1,10 @@
 /***************************
  ** crackberg; Matus Telgarsky [ catachresis@cmu.edu ] 2005 
  ** */
-#define XK_MISCELLANY
-#include <X11/keysymdef.h>
+#ifndef HAVE_COCOA
+# define XK_MISCELLANY
+# include <X11/keysymdef.h>
+#endif
 
 #define DEFAULTS    "*delay:        20000       \n" \
                     "*showFPS:      False       \n" \
@@ -18,9 +20,9 @@
 #define DEF_NSUBDIVS   "4"
 #define DEF_BORING     "False"
 #define DEF_CRACK      "True"
-#define DEF_NOWATER    "False"
+#define DEF_WATER      "True"
 #define DEF_FLAT       "True"
-#define DEF_COLOR      "plain"
+#define DEF_COLOR      "random"
 #define DEF_LIT        "True"
 #define DEF_VISIBILITY "0.6"
 #define DEF_LETTERBOX  "False"
@@ -138,7 +140,7 @@ struct _cberg_state {
  ** */
 
 static unsigned int nsubdivs;
-static Bool crack, boring, nowater, flat, lit, letterbox;
+static Bool crack, boring, do_water, flat, lit, letterbox;
 static float visibility;
 static char *color;
 
@@ -149,8 +151,8 @@ static XrmOptionDescRec opts[] = {
   {"-boring",     ".boring",     XrmoptionNoArg,  "True"},
   {"-crack",      ".crack",      XrmoptionNoArg,  "True"},
   {"-no-crack",   ".crack",      XrmoptionNoArg,  "False"},
-  {"-water",      ".nowater",    XrmoptionNoArg,  "False"},
-  {"-no-water",   ".nowater",    XrmoptionNoArg,  "True"},
+  {"-water",      ".water",      XrmoptionNoArg,  "True"},
+  {"-no-water",   ".water",      XrmoptionNoArg,  "False"},
   {"-flat",       ".flat",       XrmoptionNoArg,  "True"},
   {"-no-flat",    ".flat",       XrmoptionNoArg,  "False"},
   {"-color",      ".color",      XrmoptionSepArg, 0},
@@ -164,7 +166,7 @@ static argtype vars[] = {
   {&nsubdivs,   "nsubdivs",   "nsubdivs",   DEF_NSUBDIVS,   t_Int},
   {&boring,     "boring",     "boring",     DEF_BORING,     t_Bool},
   {&crack,      "crack",      "crack",      DEF_CRACK,      t_Bool},
-  {&nowater,    "nowater",    "nowater",    DEF_NOWATER,    t_Bool},
+  {&do_water,   "water",      "water",      DEF_WATER,      t_Bool},
   {&flat,       "flat",       "flat",       DEF_FLAT,       t_Bool},
   {&color,      "color",      "color",      DEF_COLOR,      t_String},
   {&lit,        "lit",        "lit",        DEF_LIT,        t_Bool},
@@ -430,7 +432,7 @@ static inline void trile_draw_vertex(cberg_state *cberg, unsigned int ix,
 {
     glColor3d(0.0, 0.0, 0.0); /* don't ask. my card breaks otherwise. */
     
-    if (!nowater && zcur <= 0.0) {
+    if (do_water && zcur <= 0.0) {
         cberg->color->water(cberg, zcur); /* XXX use average-of-3 for color when flat?*/
         if (lit) glNormal3d(0.0,0.0,1.0);
         glVertex3d(x, y, 0.0); 
@@ -1244,11 +1246,17 @@ ENTRYPOINT void reshape_crackberg (ModeInfo *mi, int w, int h)
 ENTRYPOINT Bool crackberg_handle_event (ModeInfo *mi, XEvent *ev)
 {
     cberg_state *cberg = &cbergs[MI_SCREEN(mi)];
+    KeySym keysym = 0;
+    char c = 0;
+    if (ev->xany.type == KeyPress || ev->xany.type == KeyRelease)
+      XLookupString (&ev->xkey, &c, 1, &keysym, 0);
 
     if (ev->xany.type == KeyPress) {
-        switch (XKeycodeToKeysym(mi->dpy, ev->xkey.keycode, 0)) {
+        switch (keysym) {
             case XK_Left:   cberg->motion_state |= MOTION_LROT;  break;
             case XK_Right:  cberg->motion_state |= MOTION_RROT;  break;
+            case XK_Down:   cberg->motion_state |= MOTION_BACK;  break;
+            case XK_Up:     cberg->motion_state |= MOTION_FORW;  break;
             case '1':       cberg->motion_state |= MOTION_DEC;   break; 
             case '2':       cberg->motion_state |= MOTION_INC;   break;
             case 'a':       cberg->motion_state |= MOTION_LEFT;  break;
@@ -1272,9 +1280,11 @@ ENTRYPOINT Bool crackberg_handle_event (ModeInfo *mi, XEvent *ev)
         }
 #endif
 
-        switch (XKeycodeToKeysym(mi->dpy, ev->xkey.keycode, 0)) {
+        switch (keysym) {
             case XK_Left:   cberg->motion_state &= ~MOTION_LROT;  break;
             case XK_Right:  cberg->motion_state &= ~MOTION_RROT;  break;
+            case XK_Down:   cberg->motion_state &= ~MOTION_BACK;  break;
+            case XK_Up:     cberg->motion_state &= ~MOTION_FORW;  break;
             case '1':       cberg->motion_state &= ~MOTION_DEC;   break; 
             case '2':       cberg->motion_state &= ~MOTION_INC;   break;
             case 'a':       cberg->motion_state &= ~MOTION_LEFT;  break;
@@ -1367,6 +1377,7 @@ ENTRYPOINT void draw_crackberg (ModeInfo *mi)
         
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     glLoadIdentity();
+    glRotatef(current_device_rotation(), 0, 0, 1);
     gluLookAt(0,0,0, 1,0,0, 0,0,1);
     glLightfv(GL_LIGHT0, GL_POSITION, lpos);
     /*glRotated(cberg->roll, 1,0,0); / * XXX blah broken and unused for now..* /