From http://www.jwz.org/xscreensaver/xscreensaver-5.37.tar.gz
[xscreensaver] / hacks / glx / b_lockglue.c
index f322be2caf9b54d2cd9c285a8e4c01450bb03ae0..a6236c64a9320cf4ec4a664323b8bf1984d8e22d 100644 (file)
@@ -42,6 +42,7 @@ struct glb_config glb_config =
                        "*showFPS:      False   \n"
 
 # define refresh_bubble3d 0
+# define release_bubble3d 0
 # define bubble3d_handle_event 0
 #include "xlockmore.h"
 #else
@@ -53,7 +54,7 @@ struct glb_config glb_config =
 
 
 #define DEF_TRANSPARENT "True"
-#define DEF_COLOR "random"
+#define DEF_BUBBLECOLOR "random"
 
 static Bool transparent_p;
 static char *bubble_color_str;
@@ -64,12 +65,12 @@ static char *bubble_color_str;
 static XrmOptionDescRec opts[] = {
   { "-transparent",  ".transparent",   XrmoptionNoArg, "True" },
   { "+transparent",  ".transparent",   XrmoptionNoArg, "False" },
-  { "-color",    ".bubble3d.bubblecolor", XrmoptionSepArg, 0 },
+  { "-color",        ".bubblecolor",   XrmoptionSepArg, 0 },
 };
 
 static argtype vars[] = {
   {&transparent_p,   "transparent", "Transparent", DEF_TRANSPARENT, t_Bool},
-  {&bubble_color_str,        "bubblecolor", "BubbleColor", DEF_COLOR, t_String},
+  {&bubble_color_str,        "bubblecolor", "BubbleColor", DEF_BUBBLECOLOR, t_String},
 };
 
 ENTRYPOINT ModeSpecOpt bubble3d_opts = {countof(opts), opts, countof(vars), vars, NULL};
@@ -79,7 +80,7 @@ ModStruct   bubbles3d_description =
 {"bubbles3d",
  "init_bubble3d",
  "draw_bubble3d",
"release_bubble3d",
NULL,
  "change_bubble3d",
  "init_bubble3d",
  NULL,
@@ -155,6 +156,8 @@ do_display(struct context *c)
        glb_draw_step(c->draw_context);
 }
 
+static void free_bubble3d(ModeInfo * mi);
+
 ENTRYPOINT void
 init_bubble3d(ModeInfo * mi)
 {
@@ -163,12 +166,7 @@ init_bubble3d(ModeInfo * mi)
        int         screen = MI_SCREEN(mi);
        struct context *c;
 
-       if (contexts == 0) {
-               contexts = (struct context *) calloc(sizeof (struct context), MI_NUM_SCREENS(mi));
-
-               if (contexts == 0)
-                       return;
-       }
+       MI_INIT (mi, contexts, free_bubble3d);
        c = &contexts[screen];
        c->glx_context = init_GL(mi);
        init_colors(mi);
@@ -198,7 +196,17 @@ draw_bubble3d(ModeInfo * mi)
 
         glb_config.polygon_count = 0;
         glPushMatrix();
-        glRotatef(current_device_rotation(), 0, 0, 1);
+
+# 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);
+          glRotatef(o, 0, 0, 1);
+        }
+# endif
+
        do_display(c);
         glPopMatrix();
         mi->polygon_count = glb_config.polygon_count;
@@ -216,20 +224,12 @@ change_bubble3d(ModeInfo * mi)
 }
 #endif /* !STANDALONE */
 
-ENTRYPOINT void
-release_bubble3d(ModeInfo * mi)
+static void
+free_bubble3d(ModeInfo * mi)
 {
-  if (contexts) {
-    int screen;
-    for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++) {
-      struct context *c = &contexts[screen];
-      if (c->draw_context)
-        glb_draw_end(c->draw_context);
-    }
-    free (contexts);
-    contexts = 0;
-  }
-  FreeAllGL(mi);
+  struct context *c = &contexts[MI_SCREEN(mi)];
+  if (c->draw_context)
+    glb_draw_end(c->draw_context);
 }
 
 XSCREENSAVER_MODULE ("Bubble3D", bubble3d)