From http://www.jwz.org/xscreensaver/xscreensaver-5.37.tar.gz
[xscreensaver] / hacks / xflame.c
index 04b82c1a96d689061722c8b59bab9932dcbe0ca7..7e35081e7a62633ad8b8943d87f63cbfa4daa210 100644 (file)
@@ -41,6 +41,7 @@
 
    * 4-Oct-99, jwz: added support for packed-24bpp (versus 32bpp.)
    * 16-Jan-2002, jwz: added gdk_pixbuf support.
+   * 9-Oct-2016, Dave Odell <dmo2118@gmail.com>: Updated for new xshm.c.
 
  */
 
@@ -54,9 +55,7 @@
 #undef countof
 #define countof(x) (sizeof((x))/sizeof((*x)))
 
-#ifdef HAVE_XSHM_EXTENSION
-# include "xshm.h"
-#endif /* HAVE_XSHM_EXTENSION */
+#include "xshm.h"
 
 #include "images/bob.xbm"
 
@@ -71,12 +70,9 @@ struct state {
   Colormap        colormap;
   Visual          *visual;
   Screen          *screen;
-  Bool            shared;
   Bool            bloom;
   XImage          *xim;
-#ifdef HAVE_XSHM_EXTENSION
   XShmSegmentInfo shminfo;
-#endif /* HAVE_XSHM_EXTENSION */
   GC              gc;
   int             ctab[256];
 
@@ -125,30 +121,19 @@ MakeImage(struct state *st)
 {
   XGCValues gcv;
 
-#ifdef HAVE_XSHM_EXTENSION
-  st->shared = True;
-  st->xim = create_xshm_image (st->dpy, st->visual, st->depth, ZPixmap, NULL,
-                           &st->shminfo, st->width, st->height);
-#else  /* !HAVE_XSHM_EXTENSION */
-  st->xim = 0;
-#endif /* !HAVE_XSHM_EXTENSION */
+  if (st->xim)
+    destroy_xshm_image (st->dpy, st->xim, &st->shminfo);
 
+  st->xim = create_xshm_image (st->dpy, st->visual, st->depth, ZPixmap,
+                               &st->shminfo, st->width, st->height);
   if (!st->xim)
     {
-      st->shared = False;
-      st->xim = XCreateImage (st->dpy, st->visual, st->depth, ZPixmap, 0, NULL,
-                          st->width, st->height, 32, 0);
-      if (st->xim)
-        st->xim->data = (char *) calloc(st->xim->height, st->xim->bytes_per_line);
-      if (!st->xim || !st->xim->data)
-        {
-          fprintf(stderr,"%s: out of memory.\n", progname);
-          exit(1);
-        }
+      fprintf(stderr,"%s: out of memory.\n", progname);
+      exit(1);
     }
 
-  st->gc = XCreateGC(st->dpy,st->window,0,&gcv);
-  if (!st->gc) exit (1);
+  if (! st->gc)
+    st->gc = XCreateGC(st->dpy,st->window,0,&gcv);
 }
 
 
@@ -199,14 +184,9 @@ InitColors(struct state *st)
 static void
 DisplayImage(struct state *st)
 {
-#ifdef HAVE_XSHM_EXTENSION
-  if (st->shared)
-    XShmPutImage(st->dpy, st->window, st->gc, st->xim, 0,(st->top - 1) << 1, 0,
-                 (st->top - 1) << 1, st->width, st->height - ((st->top - 1) << 1), False);
-  else
-#endif /* HAVE_XSHM_EXTENSION */
-    XPutImage(st->dpy, st->window, st->gc, st->xim, 0, (st->top - 1) << 1, 0,
-              (st->top - 1) << 1, st->width, st->height - ((st->top - 1) << 1));
+  put_xshm_image(st->dpy, st->window, st->gc, st->xim, 0,(st->top - 1) << 1, 0,
+                 (st->top - 1) << 1, st->width, st->height - ((st->top - 1) << 1),
+                 &st->shminfo);
 }
 
 
@@ -215,6 +195,8 @@ InitFlame(struct state *st)
 {
   st->fwidth  = st->width / 2;
   st->fheight = st->height / 2;
+
+  if (st->flame) free (st->flame);
   st->flame   = (unsigned char *) malloc((st->fwidth + 2) * (st->fheight + 2)
                                      * sizeof(unsigned char));
 
@@ -605,11 +587,11 @@ FlamePasteData(struct state *st,
 static unsigned char *
 loadBitmap(struct state *st, int *w, int *h)
 {
+# ifdef HAVE_JWXYZ
+  const char *bitmap_name = "(default)"; /* #### always use builtin */
+# else
   char *bitmap_name = get_string_resource (st->dpy, "bitmap", "Bitmap");
-
-#ifdef HAVE_COCOA
-  bitmap_name = "(default)"; /* #### always use builtin */
-#endif /* HAVE_COCOA */
+# endif
   
   if (!bitmap_name ||
       !*bitmap_name ||
@@ -619,13 +601,13 @@ loadBitmap(struct state *st, int *w, int *h)
     {
       XImage *ximage;
       unsigned char *result, *o;
-      char *bits = (char *) malloc (sizeof(bob_bits));
+      unsigned char *bits = (unsigned char *) malloc (sizeof(bob_bits));
       int x, y;
-      int scale = ((st->width > bob_width * 11) ? 2 : 1);
+      int scale = ((st->width > bob_width * 10) ? 2 : 1);
  
       memcpy (bits, bob_bits, sizeof(bob_bits));
-      ximage = XCreateImage (st->dpy, st->visual, 1, XYBitmap, 0, bits,
-                             bob_width, bob_height, 8, 0);
+      ximage = XCreateImage (st->dpy, st->visual, 1, XYBitmap, 0, 
+                             (char *) bits, bob_width, bob_height, 8, 0);
       ximage->byte_order = LSBFirst;
       ximage->bitmap_bit_order = LSBFirst;
       *w = ximage->width * scale;
@@ -638,7 +620,7 @@ loadBitmap(struct state *st, int *w, int *h)
       return result;
     }
   else  /* load a bitmap file */
-#ifdef HAVE_COCOA
+#ifdef HAVE_JWXYZ
     abort(); /* #### fix me */
 #else
    {
@@ -697,7 +679,7 @@ loadBitmap(struct state *st, int *w, int *h)
       *h = st->height;
       return result;
     }
-#endif /* !HAVE_COCOA */
+#endif /* !HAVE_JWXYZ */
 
   *w = 0;
   *h = 0;
@@ -721,12 +703,6 @@ xflame_init (Display *dpy, Window win)
   InitColors(st);
   st->theim = loadBitmap(st, &st->theimx, &st->theimy);
 
-  /* utils/xshm.c doesn't provide a way to free the shared-memory image, which
-     makes it hard for us to react to window resizing.  So, punt for now.  The
-     size of the window at startup is the size it will stay.
-  */
-  GetXInfo(st);
-
   MakeImage(st);
   InitFlame(st);
   FlameFill(st,0);
@@ -755,6 +731,12 @@ static void
 xflame_reshape (Display *dpy, Window window, void *closure, 
                  unsigned int w, unsigned int h)
 {
+  struct state *st = (struct state *) closure;
+  GetXInfo(st);
+  MakeImage(st);
+  InitFlame(st);
+  FlameFill(st,0);
+  XClearWindow (dpy, window);
 }
 
 static Bool
@@ -774,6 +756,8 @@ xflame_free (Display *dpy, Window window, void *closure)
 static const char *xflame_defaults [] = {
   ".background:     black",
   ".foreground:     #FFAF5F",
+  "*fpsTop:        true",
+  "*fpsSolid:       true",
   "*bitmap:         (default)",
   "*bitmapBaseline: 20",
   "*delay:          10000",