From http://www.jwz.org/xscreensaver/xscreensaver-5.22.tar.gz
[xscreensaver] / hacks / memscroller.c
index ee1e1b54cbe03b6b2246628c235a3e57fd4f13e7..ddd07eed83c49609766691369d80a5d225eb108e 100644 (file)
@@ -1,4 +1,4 @@
-/* xscreensaver, Copyright (c) 2002, 2004, 2006 Jamie Zawinski <jwz@jwz.org>
+/* xscreensaver, Copyright (c) 2002-2012 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
 #undef countof
 #define countof(x) (sizeof(x)/sizeof(*(x)))
 
+#ifndef USE_IPHONE
+# define READ_FILES
+#endif
+
 typedef struct {
   int which;
   XRectangle rect;
@@ -82,7 +86,7 @@ memscroller_init (Display *dpy, Window window)
   {
     int ncolors = 255;
     XColor colors[256];
-    make_random_colormap (st->dpy, st->xgwa.visual, st->xgwa.colormap,
+    make_random_colormap (st->xgwa.screen, st->xgwa.visual, st->xgwa.colormap,
                           colors, &ncolors, True, True, 0, False);
   }
 
@@ -97,14 +101,31 @@ memscroller_init (Display *dpy, Window window)
         char res[20];
         sprintf (res, "font%d", i+1);
         fontname = get_string_resource (dpy, res, "Font");
-        st->fonts[i] = XLoadQueryFont (dpy, fontname);
-        if (!st->fonts[i] && i < nfonts-1)
+        /* Each resource can be a comma-separated list of font names.
+           We use the first one that exists. */
+        if (fontname && *fontname) 
           {
-            fprintf (stderr, "%s: unable to load font: \"%s\"\n",
-                     progname, fontname);
-            st->fonts[i] = st->fonts[i+1];
+            char *f2 = strdup(fontname);
+            char *f, *token = f2;
+            while ((f = strtok(token, ",")) && !st->fonts[i])
+              {
+                token = 0;
+                while (*f == ' ' || *f == '\t') f++;
+                st->fonts[i] = XLoadQueryFont (dpy, f);
+              }
+            free (f2);
+            if (!st->fonts[i] && i < nfonts-1)
+              {
+                fprintf (stderr, "%s: unable to load font: \"%s\"\n",
+                         progname, fontname);
+                st->fonts[i] = st->fonts[i+1];
+              }
           }
       }
+
+    if (!st->fonts[0])
+      st->fonts[0] = XLoadQueryFont (dpy, "fixed");
+
     if (!st->fonts[0])
       {
         fprintf (stderr, "%s: unable to load any fonts!", progname);
@@ -146,7 +167,9 @@ memscroller_init (Display *dpy, Window window)
   s = 0;
 
 
+# ifdef READ_FILES
   st->filename = get_string_resource (dpy, "filename", "Filename");
+# endif
 
   if (!st->filename ||
       !*st->filename ||
@@ -154,12 +177,16 @@ memscroller_init (Display *dpy, Window window)
       !strcasecmp (st->filename, "(mem)") ||
       !strcasecmp (st->filename, "(memory)"))
     st->seed_mode = SEED_RAM;
+# ifdef READ_FILES
   else if (st->filename &&
            (!strcasecmp (st->filename, "(rand)") ||
             !strcasecmp (st->filename, "(random)")))
     st->seed_mode = SEED_RANDOM;
   else
     st->seed_mode = SEED_FILE;
+# else
+  st->seed_mode = SEED_RANDOM;
+# endif
 
   st->nscrollers = 3;
   st->scrollers = (scroller *) calloc (st->nscrollers, sizeof(scroller));
@@ -253,6 +280,7 @@ reshape_memscroller (state *st)
 
 
 
+# ifdef READ_FILES
 static void
 open_file (state *st)
 {
@@ -271,6 +299,7 @@ open_file (state *st)
       exit (1);
     }
 }
+#endif
 
 
 static unsigned int
@@ -399,6 +428,7 @@ more_bits (state *st, scroller *sc)
       pv = PACK();
       break;
 
+# ifdef READ_FILES
     case SEED_FILE:
       {
         int i;
@@ -443,6 +473,7 @@ more_bits (state *st, scroller *sc)
         pv = PACK();
       }
       break;
+# endif /* READ_FILES */
 
     default:
       abort();
@@ -586,21 +617,23 @@ static const char *memscroller_defaults [] = {
   ".textColor:            #00FF00",
   ".foreground:                   #00FF00",
   "*borderSize:                   2",
-#ifdef HAVE_COCOA
-  ".font1:                OCR A Std 192",
-  ".font2:                OCR A Std 144",
-  ".font3:                OCR A Std 128",
-  ".font4:                OCR A Std 96",
-  ".font5:                OCR A Std 48",
-  ".font6:                OCR A Std 24",
-#else
+
+#if defined(HAVE_COCOA) && !defined(USE_IPHONE)
+  ".font1:                OCR A Std 192, Lucida Console 192",
+  ".font2:                OCR A Std 144, Lucida Console 144",
+  ".font3:                OCR A Std 128, Lucida Console 128",
+  ".font4:                OCR A Std 96,  Lucida Console 96",
+  ".font5:                OCR A Std 48,  Lucida Console 48",
+  ".font6:                OCR A Std 24,  Lucida Console 24",
+#else  /* !HAVE_COCOA */
   ".font1:                -*-courier-bold-r-*-*-*-1440-*-*-m-*-*-*",
   ".font2:                -*-courier-bold-r-*-*-*-960-*-*-m-*-*-*",
   ".font3:                -*-courier-bold-r-*-*-*-480-*-*-m-*-*-*",
   ".font4:                -*-courier-bold-r-*-*-*-320-*-*-m-*-*-*",
   ".font5:                -*-courier-bold-r-*-*-*-180-*-*-m-*-*-*",
   ".font6:                fixed",
-#endif
+#endif /* !HAVE_COCOA */
+
   "*delay:                10000",
   "*offset:               0",
   0