Imported Upstream version 2.5
[xfishtank.git] / xfish.c
diff --git a/xfish.c b/xfish.c
index 7f6dbf4a3b35ed245ec1bc0f7a59cc71a2047775..8c4c47a9279ace985c76a6a878df22089795e870 100644 (file)
--- a/xfish.c
+++ b/xfish.c
@@ -44,6 +44,7 @@
 #include <signal.h>
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
+#include <Imlib2.h>
 
 #include "vroot.h"
 #include "xfishy.h"
@@ -170,13 +171,15 @@ parse(argc, argv)
 int argc;
 char **argv;
 {
-    int c, i;
+    int c;
+    const char *display = getenv("DISPLAY");
     extern int optind;
     extern char *optarg;
     extern double atof();
 
     pname = argv[0];
-    strncpy(sname, getenv("DISPLAY"), sizeof(sname) - 1);
+    if (display != NULL)
+       strncpy(sname, display, sizeof(sname) - 1);
     strcpy(cname, "MediumAquamarine");
 
     while ((c = getopt(argc, argv, "dDob:C:c:p:m:f:i:r:s")) != EOF) {
@@ -651,6 +654,7 @@ int x, y, d;
 }
 
 
+void
 erasebubble(b, s)
 bubble *b;
 int s;
@@ -659,6 +663,7 @@ int s;
 }
 
 
+void
 putbubble(b, s, c)
 bubble *b;
 int s;
@@ -835,7 +840,6 @@ The fish colors are coded in xfishy.h as a trio of tables.
 void
 init_colormap()
 {
-    FILE *fp;
     int i, j, cnt;
     int NumCells;
     XColor hdef, edef;
@@ -856,12 +860,24 @@ init_colormap()
 
     Pcnt = 0;
     if (picname[0] != '\0') {
-       fp = fopen(picname, "r");
-       if (fp == NULL) {
-           fprintf(stderr, "Cannot open picture %s for reading\n", picname);
+       Imlib_Image image = imlib_load_image(picname);
+       if (image == NULL) {
+           fprintf(stderr, "Cannot load image %s\n", picname);
+           picname[0] = 0;
        } else {
-           Pdata = ReadBitmap(fp, &Pwidth, &Pheight, colrs);
-           fclose(fp);
+           imlib_context_set_image(image);
+           imlib_context_set_display(Dpy);
+           imlib_context_set_visual(DefaultVisual(Dpy, screen));
+           Pwidth = imlib_image_get_width();
+           Pheight = imlib_image_get_height();
+           DATA32 *image_data = imlib_image_get_data_for_reading_only();
+           Pdata = malloc(4 * Pwidth * Pheight);
+           for (i = 0; i < Pwidth * Pheight; i++) {
+               Pdata[4 * i] = image_data[i] & 0xFF;
+               Pdata[4 * i + 1] = image_data[i] & 0xFF00;
+               Pdata[4 * i + 2] = image_data[i] & 0xFF0000;
+               Pdata[4 * i + 3] = image_data[i] & 0xFF000000;
+           }
            Pcnt = ColorUsage(Pdata, Pwidth, Pheight, colrs);
        }
     }
@@ -1304,11 +1320,9 @@ Initialize signal so that SIGUSR1 causes secure mode to toggle.
 void
 init_signals()
 {
-    int ret;
-#ifdef linux
+#if defined(linux)
     signal(SIGUSR1, toggle_secure);
-#else
-#if defined(MOTOROLA) || defined(SCO)
+#elif defined(MOTOROLA) || defined(SCO)
     sigset(SIGUSR1, toggle_secure);
 #else
     struct sigvec vec;
@@ -1318,22 +1332,15 @@ init_signals()
     vec.sv_onstack = 0;
 
 #ifndef hpux
-    ret = sigvec(SIGUSR1, &vec, &vec);
-#if 0
-    if (ret != 0) {
-       fprintf(stderr, "sigvec call failed\n");
-    } else {
-       fprintf(stderr, "sigvec call OK\n");
-    }
-#endif
+    sigvec(SIGUSR1, &vec, &vec);
 #else
     sigvector(SIGUSR1, &vec, &vec);
 #endif
-#endif /* MOTOROLA */
-#endif /* LINUX */
+#endif
 }
 
 
+void
 set_window_type_desktop(Display *dpy, Window wid)
 {
     Atom _NET_WM_WINDOW_TYPE, _NET_WM_WINDOW_TYPE_DESKTOP;
@@ -1356,11 +1363,8 @@ initialize()
     XSetWindowAttributes attr;
     XGCValues vals;
     XSizeHints xsh;
-    XImage *pimage;
-    int i, size, cnt;
+    int i;
     char *p;
-    unsigned char *ndata;
-    unsigned char *ptr1, *ptr2;
 
     root_window = VirtualRootWindowOfScreen(DefaultScreenOfDisplay(Dpy));
 
@@ -1368,7 +1372,6 @@ initialize()
     width = winfo.width;
     height = winfo.height;
 
-    picname[0] = '\0';
     if ((p = XGetDefault(Dpy, pname, "BubbleLimit")) != NULL)
        blimit = atoi(p);
     if ((p = XGetDefault(Dpy, pname, "ColorLimit")) != NULL)
@@ -1407,20 +1410,11 @@ initialize()
     init_colormap();
 
     if (picname[0] != '\0') {
-       size = Pwidth * Pheight;
-       ndata = (unsigned char *) malloc(size);
-       ptr1 = Pdata;
-       ptr2 = ndata;
-       cnt = 1;
-       for (i = 0; i < size; i++) {
-           *ptr2 = cmap[cnt + (int) (*ptr1)];
-           ptr1++;
-           ptr2++;
-       }
-       pimage = MakeImage(ndata, Pwidth, Pheight);
-       free((char *) ndata);
-       i = DisplayPlanes(Dpy, screen);
-       PicMap = XCreatePixmap(Dpy, root_window, Pwidth, Pheight, i);
+       imlib_context_set_colormap(colormap);
+       PicMap = XCreatePixmap(Dpy, root_window, Pwidth, Pheight, DisplayPlanes(Dpy, screen));
+       imlib_context_set_drawable(PicMap);
+       imlib_render_image_on_drawable(0, 0);
+
     }
 
     if ((DoubleBuf) || (picname[0] != '\0')) {
@@ -1486,7 +1480,6 @@ initialize()
        XSetNormalHints(Dpy, wid, &xsh);
 
        if (picname[0] != '\0') {
-           XPutImage(Dpy, PicMap, gc, pimage, 0, 0, 0, 0, Pwidth, Pheight);
            XSetWindowBackgroundPixmap(Dpy, wid, PicMap);
        }
 
This page took 0.012758 seconds and 4 git commands to generate.