X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fmemscroller.c;h=b1ca148644c290322b27c6b7fcdd18a5fd6aa508;hb=aa75c7476aeaa84cf3abc192b376a8b03c325213;hp=fca2459e8a0de7d4ff3f8ffa5a8a159f45ae718d;hpb=49f5b54f312fe4ac2e9bc47581a72451bd0e8439;p=xscreensaver diff --git a/hacks/memscroller.c b/hacks/memscroller.c index fca2459e..b1ca1486 100644 --- a/hacks/memscroller.c +++ b/hacks/memscroller.c @@ -1,4 +1,4 @@ -/* xscreensaver, Copyright (c) 2002, 2004, 2006 Jamie Zawinski +/* xscreensaver, Copyright (c) 2002-2015 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -21,6 +21,10 @@ #undef countof #define countof(x) (sizeof(x)/sizeof(*(x))) +#ifndef HAVE_MOBILE +# define READ_FILES +#endif + typedef struct { int which; XRectangle rect; @@ -38,7 +42,7 @@ typedef struct { Window window; XWindowAttributes xgwa; GC draw_gc, erase_gc, text_gc; - XFontStruct *fonts[4]; + XFontStruct *fonts[6]; int border; enum { SEED_RAM, SEED_RANDOM, SEED_FILE } seed_mode; @@ -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,19 @@ open_file (state *st) exit (1); } } +#endif + + +/* "The brk and sbrk functions are historical curiosities left over + from earlier days before the advent of virtual memory management." + -- sbrk(2) man page on BSD systems, as of 1995 or so. + */ +#ifdef HAVE_SBRK +# if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)) /* gcc >= 4.2 */ + /* Don't print "warning: 'sbrk' is deprecated". */ +# pragma GCC diagnostic ignored "-Wdeprecated-declarations" +# endif +#endif static unsigned int @@ -294,7 +335,7 @@ more_bits (state *st, scroller *sc) vv = sc->value; /* Pack RGB into a pixel according to the XImage component masks; - set the remaining bits to 1 for the benefit of HAVE_COCOA alpha. + set the remaining bits to 1 for the benefit of HAVE_JWXYZ alpha. */ # undef PACK # define PACK() ((((r << 24) | (r << 16) | (r << 8) | r) & rmsk) | \ @@ -316,10 +357,6 @@ more_bits (state *st, scroller *sc) sc->data = lomem; # ifdef HAVE_SBRK /* re-get it each time through */ - /* "The brk and sbrk functions are historical curiosities left over - from earlier days before the advent of virtual memory management." - -- sbrk(2) man page on MacOS - */ himem = ((unsigned char *) sbrk(0)) - (2 * sizeof(void *)); # endif @@ -331,13 +368,13 @@ more_bits (state *st, scroller *sc) } /* I don't understand what's going on there, but on MacOS X, we're - getting insane values for lomem and himem (both Xlib and HAVE_COCOA). + getting insane values for lomem and himem (both Xlib and HAVE_JWXYZ). Does malloc() draw from more than one heap? */ if ((unsigned long) himem - (unsigned long) lomem > 0x0FFFFFFF) { # if 0 fprintf (stderr, "%s: wonky: 0x%08x - 0x%08x = 0x%08x\n", progname, - (unsigned long) himem, (unsigned long) lomem, - (unsigned long) himem - (unsigned long) lomem); + (unsigned int) himem, (unsigned int) lomem, + (unsigned int) himem - (unsigned int) lomem); # endif himem = lomem + 0xFFFF; } @@ -399,6 +436,7 @@ more_bits (state *st, scroller *sc) pv = PACK(); break; +# ifdef READ_FILES case SEED_FILE: { int i; @@ -443,6 +481,7 @@ more_bits (state *st, scroller *sc) pv = PACK(); } break; +# endif /* READ_FILES */ default: abort(); @@ -483,7 +522,7 @@ draw_string (state *st) x = (st->xgwa.width - w) / 2; y = (bot - h) / 2; - if (y + h + 10 <= bot) + if (y + h + 10 <= bot && x > -10) { XSetFont (st->dpy, st->text_gc, st->fonts[i]->fid); XFillRectangle (st->dpy, st->window, st->erase_gc, @@ -580,14 +619,29 @@ memscroller_free (Display *dpy, Window window, void *closure) static const char *memscroller_defaults [] = { ".background: black", "*drawMode: color", + "*fpsSolid: true", + "*fpsTop: true", "*filename: (RAM)", ".textColor: #00FF00", ".foreground: #00FF00", "*borderSize: 2", - ".font1: -*-courier-medium-r-*-*-*-1400-*-*-m-*-*-*", - ".font2: -*-courier-medium-r-*-*-*-600-*-*-m-*-*-*", - ".font3: -*-courier-medium-r-*-*-*-180-*-*-m-*-*-*", - ".font4: fixed", + +#if defined(HAVE_COCOA) || defined(HAVE_ANDROID) + ".font1: OCR A Std 192, Lucida Console 192, Monaco 192", + ".font2: OCR A Std 144, Lucida Console 144, Monaco 144", + ".font3: OCR A Std 128, Lucida Console 128, Monaco 128", + ".font4: OCR A Std 96, Lucida Console 96, Monaco 96", + ".font5: OCR A Std 48, Lucida Console 48, Monaco 48", + ".font6: OCR A Std 24, Lucida Console 24, Monaco 24", +#else /* real X11 */ + ".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 /* real X11 */ + "*delay: 10000", "*offset: 0", 0