From http://www.jwz.org/xscreensaver/xscreensaver-5.37.tar.gz
[xscreensaver] / hacks / glx / gflux.c
index 80310cc285efe7b7e950b5721daaf002be94798d..69636f276d18f9a8f436f8b0978565addfda9426 100644 (file)
 #ifdef STANDALONE
 #define DEFAULTS                        "*delay:               20000\n" \
                                                                                "*showFPS:      False\n" \
-                                        "*mode:         light\n" \
-                                        "*useSHM:       True \n" 
-
+                                        "*mode:         grab\n"  \
+                                        "*useSHM:       True \n" \
+                                                                               "*suppressRotationAnimation: True\n" \
 
 # define refresh_gflux 0
+# define release_gflux 0
 # include "xlockmore.h"                                /* from the xscreensaver distribution */
 #else /* !STANDALONE */
 # include "xlock.h"                                    /* from the xlockmore distribution */
@@ -168,7 +169,7 @@ ENTRYPOINT ModeSpecOpt gflux_opts = {countof(opts), opts, countof(vars), vars, d
 
 #ifdef USE_MODULES
 ModStruct   gflux_description =
-{"gflux", "init_gflux", "draw_gflux", "release_gflux",
+{"gflux", "init_gflux", "draw_gflux", NULL,
  "draw_gflux", "init_gflux", NULL, &gflux_opts,
  1000, 1, 2, 1, 4, 1.0, "",
  "GFlux: an OpenGL gflux", 0, NULL};
@@ -240,38 +241,16 @@ gflux_handle_event (ModeInfo *mi, XEvent *event)
 {
   gfluxstruct *gp = &gfluxes[MI_SCREEN(mi)];
 
-  if (event->xany.type == ButtonPress &&
-      event->xbutton.button == Button1)
-    {
-      gp->button_down_p = True;
-      gltrackball_start (gp->trackball,
-                         event->xbutton.x, event->xbutton.y,
-                         MI_WIDTH (mi), MI_HEIGHT (mi));
-      return True;
-    }
-  else if (event->xany.type == ButtonRelease &&
-           event->xbutton.button == Button1)
-    {
-      gp->button_down_p = False;
-      return True;
-    }
-  else if (event->xany.type == ButtonPress &&
-           (event->xbutton.button == Button4 ||
-            event->xbutton.button == Button5 ||
-            event->xbutton.button == Button6 ||
-            event->xbutton.button == Button7))
-    {
-      gltrackball_mousewheel (gp->trackball, event->xbutton.button, 10,
-                              !!event->xbutton.state);
-      return True;
-    }
-  else if (event->xany.type == MotionNotify &&
-           gp->button_down_p)
+  if (gltrackball_event_handler (event, gp->trackball,
+                                 MI_WIDTH (mi), MI_HEIGHT (mi),
+                                 &gp->button_down_p))
+    return True;
+  else if (screenhack_event_helper (MI_DISPLAY(mi), MI_WINDOW(mi), event))
     {
-      gltrackball_track (gp->trackball,
-                         event->xmotion.x, event->xmotion.y,
-                         MI_WIDTH (mi), MI_HEIGHT (mi));
-      return True;
+      if (_draw == grab) {
+        grabTexture(gp);
+        return True;
+      }
     }
 
   return False;
@@ -305,23 +284,26 @@ ENTRYPOINT void draw_gflux(ModeInfo * mi)
 }
 
 
-/* reset the projection matrix */
-static void resetProjection(void) 
+/* Standard reshape function */
+ENTRYPOINT void
+reshape_gflux(ModeInfo *mi, int width, int height)
 {
+    glViewport( 0, 0, width, height );
     glMatrixMode(GL_PROJECTION);
     glLoadIdentity();
     glFrustum(-_zoom,_zoom,-0.8*_zoom,0.8*_zoom,2,6);
     glTranslatef(0.0,0.0,-4.0);
     glMatrixMode(GL_MODELVIEW);
     glLoadIdentity();
-}
 
-/* Standard reshape function */
-ENTRYPOINT void
-reshape_gflux(ModeInfo *mi, int width, int height)
-{
-    glViewport( 0, 0, width, height );
-    resetProjection();
+# ifdef HAVE_MOBILE    /* Keep it the same relative size when rotated. */
+    {
+      GLfloat h = MI_HEIGHT(mi) / (GLfloat) MI_WIDTH(mi);
+      int o = (int) current_device_rotation();
+      if (o != 0 && o != 180 && o != -180)
+        glScalef (1/h, 1/h, 1/h);
+    }
+# endif
 }
 
 
@@ -377,20 +359,16 @@ ENTRYPOINT void init_gflux(ModeInfo * mi)
     int screen = MI_SCREEN(mi);
     gfluxstruct *gp;
 
-    if (gfluxes == NULL) {
-        if ((gfluxes = (gfluxstruct *) 
-                 calloc(MI_NUM_SCREENS(mi), sizeof (gfluxstruct))) == NULL)
-            return;
-    }
+    MI_INIT(mi, gfluxes, NULL);
     gp = &gfluxes[screen];
 
-    gp->trackball = gltrackball_init ();
+    gp->trackball = gltrackball_init (True);
 
     gp->time = frand(1000.0);  /* don't run two screens in lockstep */
 
     {
       char *s = get_string_resource (mi->dpy, "mode", "Mode");
-      if (!s || !*s)                       _draw = wire;
+      if (!s || !*s)                       _draw = grab;
       else if (!strcasecmp (s, "wire"))    _draw = wire;
       else if (!strcasecmp (s, "solid"))   _draw = solid;
       else if (!strcasecmp (s, "light"))   _draw = light;
@@ -416,16 +394,6 @@ ENTRYPOINT void init_gflux(ModeInfo * mi)
     }
 }
 
-/* cleanup code */
-ENTRYPOINT void release_gflux(ModeInfo * mi)
-{
-    if (gfluxes != NULL) {
-      free((void *) gfluxes);
-      gfluxes = NULL;
-    }
-    FreeAllGL(mi);
-}
-
 
 static void createTexture(gfluxstruct *gp)
 {