X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?p=xscreensaver;a=blobdiff_plain;f=hacks%2Fmemscroller.c;h=f18e5a0e3a91d0c74414c7bbed5c62924ecedcc1;hp=e3940f8e54158d6932281d41e3ed72d76c8aa4f7;hb=4361b69d3178d7fc98d0388f9a223af6c2651aba;hpb=5f9c47ca98dd43d8f59b7c27d3fde6edfde4fe21 diff --git a/hacks/memscroller.c b/hacks/memscroller.c index e3940f8e..f18e5a0e 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 @@ -12,15 +12,16 @@ */ #include "screenhack.h" -#include - -#ifdef HAVE_XSHM_EXTENSION #include "xshm.h" -#endif +#include #undef countof #define countof(x) (sizeof(x)/sizeof(*(x))) +#ifndef HAVE_MOBILE +# define READ_FILES +#endif + typedef struct { int which; XRectangle rect; @@ -50,10 +51,7 @@ typedef struct { int nscrollers; scroller *scrollers; -# ifdef HAVE_XSHM_EXTENSION - Bool shm_p; XShmSegmentInfo shm_info; -# endif int delay; @@ -82,7 +80,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); } @@ -163,7 +161,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 || @@ -171,12 +171,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)); @@ -189,29 +193,12 @@ memscroller_init (Display *dpy, Window window) sc->which = i; sc->speed = i+1; - sc->image = 0; -# ifdef HAVE_XSHM_EXTENSION - st->shm_p = get_boolean_resource (dpy, "useSHM", "Boolean"); - if (st->shm_p) - { - sc->image = create_xshm_image (st->dpy, st->xgwa.visual, - st->xgwa.depth, - ZPixmap, 0, &st->shm_info, - 1, max_height); - if (! sc->image) - st->shm_p = False; - } -# endif /* HAVE_XSHM_EXTENSION */ + sc->image = create_xshm_image (st->dpy, st->xgwa.visual, + st->xgwa.depth, + ZPixmap, &st->shm_info, + 1, max_height); if (!sc->image) - sc->image = XCreateImage (st->dpy, st->xgwa.visual, st->xgwa.depth, - ZPixmap, 0, 0, 1, max_height, 8, 0); - - if (sc->image && !sc->image->data) - sc->image->data = (char *) - malloc (sc->image->bytes_per_line * sc->image->height + 1); - - if (!sc->image || !sc->image->data) { fprintf (stderr, "%s: out of memory (allocating 1x%d image)\n", progname, sc->image->height); @@ -270,6 +257,7 @@ reshape_memscroller (state *st) +# ifdef READ_FILES static void open_file (state *st) { @@ -288,6 +276,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 @@ -311,7 +312,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) | \ @@ -333,10 +334,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 @@ -348,7 +345,7 @@ 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 @@ -416,6 +413,7 @@ more_bits (state *st, scroller *sc) pv = PACK(); break; +# ifdef READ_FILES case SEED_FILE: { int i; @@ -460,6 +458,7 @@ more_bits (state *st, scroller *sc) pv = PACK(); } break; +# endif /* READ_FILES */ default: abort(); @@ -550,21 +549,12 @@ memscroller_draw (Display *dpy, Window window, void *closure) for (j = 0; j < sc->speed; j++) { -# ifdef HAVE_XSHM_EXTENSION - if (st->shm_p) - XShmPutImage (st->dpy, st->window, st->draw_gc, sc->image, + put_xshm_image (st->dpy, st->window, st->draw_gc, sc->image, 0, 0, sc->rect.x + sc->rect.width - sc->image->width - j, sc->rect.y, sc->rect.width, sc->rect.height, - False); - else -# endif /* HAVE_XSHM_EXTENSION */ - XPutImage (st->dpy, st->window, st->draw_gc, sc->image, - 0, 0, - sc->rect.x + sc->rect.width - sc->image->width - j, - sc->rect.y, - sc->rect.width, sc->rect.height); + &st->shm_info); } } @@ -604,21 +594,21 @@ static const char *memscroller_defaults [] = { ".foreground: #00FF00", "*borderSize: 2", -#ifdef HAVE_COCOA - ".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 */ +#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 /* !HAVE_COCOA */ +#endif /* real X11 */ "*delay: 10000", "*offset: 0",