http://packetstormsecurity.org/UNIX/admin/xscreensaver-4.01.tar.gz
[xscreensaver] / hacks / xlockmore.c
index ff18c4a0764f0ee8dd332166c99379157381f2b9..28828beb1e25439958dcd026bb421fb0f645630c 100644 (file)
@@ -1,5 +1,5 @@
 /* xlockmore.c --- xscreensaver compatibility layer for xlockmore modules.
- * xscreensaver, Copyright (c) 1997, 1998 Jamie Zawinski <jwz@jwz.org>
+ * xscreensaver, Copyright (c) 1997, 1998, 2001 Jamie Zawinski <jwz@jwz.org>
  *
  * Permission to use, copy, modify, distribute, and sell this software and its
  * documentation for any purpose is hereby granted without fee, provided that
 #include <stdio.h>
 #include <math.h>
 #include <string.h>
+#include <time.h>
+#include <sys/time.h>
 #include "screenhack.h"
 #include "xlockmoreI.h"
 
 #define countof(x) (sizeof((x))/sizeof(*(x)))
 
+#define MAX_COLORS (1L<<13)
+
 extern ModeSpecOpt xlockmore_opts[];
 extern const char *app_defaults;
 
@@ -61,7 +65,8 @@ pre_merge_options (void)
   /* Add extra args, if they're mentioned in the defaults... */
   {
     char *args[] = { "-count", "-cycles", "-delay", "-ncolors",
-                    "-size", "-wireframe", "-use3d", "-useSHM" };
+                    "-size", "-wireframe", "-use3d", "-useSHM",
+                     "-showFPS" };
     for (j = 0; j < countof(args); j++)
       if (strstr(app_defaults, args[j]+1))
        {
@@ -101,6 +106,17 @@ pre_merge_options (void)
              new->argKind = XrmoptionNoArg;
              new->value = "False";
            }
+         else if (!strcmp(new->option, "-showFPS"))
+           {
+             new->option = "-fps";
+             new->argKind = XrmoptionNoArg;
+             new->value = "True";
+             new = &options[i++];
+             new->option = "-no-fps";
+             new->specifier = options[i-2].specifier;
+             new->argKind = XrmoptionNoArg;
+             new->value = "False";
+           }
          else
            {
              new->argKind = XrmoptionSepArg;
@@ -195,6 +211,26 @@ xlockmore_read_resources (void)
 }
 
 
+static void
+xlockmore_handle_events (ModeInfo *mi, 
+                         void (*reshape) (ModeInfo *, int, int))
+{
+  while (XPending (mi->dpy))
+    {
+      XEvent event;
+      XNextEvent (mi->dpy, &event);
+      if (reshape && event.xany.type == ConfigureNotify)
+        {
+          XGetWindowAttributes (mi->dpy, mi->window, &mi->xgwa);
+          reshape (mi, mi->xgwa.width, mi->xgwa.height);
+        }
+      else
+        {
+          screenhack_handle_event (mi->dpy, &event);
+        }
+    }
+}
+
 
 void 
 xlockmore_screenhack (Display *dpy, Window window,
@@ -204,6 +240,7 @@ xlockmore_screenhack (Display *dpy, Window window,
                      Bool want_bright_colors,
                      void (*hack_init) (ModeInfo *),
                      void (*hack_draw) (ModeInfo *),
+                     void (*hack_reshape) (ModeInfo *, int, int),
                      void (*hack_free) (ModeInfo *))
 {
   ModeInfo mi;
@@ -249,8 +286,8 @@ xlockmore_screenhack (Display *dpy, Window window,
       mi.npixels = get_integer_resource ("ncolors", "Integer");
       if (mi.npixels <= 0)
        mi.npixels = 64;
-      else if (mi.npixels > 256)
-       mi.npixels = 256;
+      else if (mi.npixels > MAX_COLORS)
+       mi.npixels = MAX_COLORS;
 
       mi.colors = (XColor *) calloc (mi.npixels, sizeof (*mi.colors));
 
@@ -307,6 +344,7 @@ xlockmore_screenhack (Display *dpy, Window window,
 
   mi.wireframe_p = get_boolean_resource ("wireframe", "Boolean");
   mi.root_p = (window == RootWindowOfScreen (mi.xgwa.screen));
+  mi.fps_p = get_boolean_resource ("showFPS", "Boolean");
 #ifdef HAVE_XSHM_EXTENSION
   mi.use_shm = get_boolean_resource ("useSHM", "Boolean");
 #endif /* !HAVE_XSHM_EXTENSION */
@@ -328,6 +366,7 @@ xlockmore_screenhack (Display *dpy, Window window,
   do {
     hack_draw (&mi);
     XSync(dpy, False);
+    xlockmore_handle_events (&mi, hack_reshape);
     if (mi.pause)
       usleep(mi.pause);
     mi.pause = orig_pause;