--- rxvt-unicode/src/xpm.C 2004/02/01 01:34:41 1.7 +++ rxvt-unicode/src/xpm.C 2006/01/25 21:09:22 1.30 @@ -1,7 +1,6 @@ /*--------------------------------*-C-*---------------------------------* - * File: xpm.c + * File: xpm.C *----------------------------------------------------------------------* - * $Id: xpm.C,v 1.7 2004/02/01 01:34:41 pcg Exp $ * * All portions of code are copyright by their respective author/s. * Copyright (c) 1997 Carsten Haitzler @@ -25,10 +24,11 @@ #include "../config.h" /* NECESSARY */ #include "rxvt.h" /* NECESSARY */ -#include "xpm.intpro" /* PROTOS for internal routines */ #ifdef XPM_BACKGROUND +static void rxvt_pixmap_incr (unsigned int *wh, unsigned int *xy, float *incr, float *p, unsigned int widthheight, unsigned int xpmwidthheight); + /* * These GEOM strings indicate absolute size/position: * @ `WxH+X+Y' @@ -52,48 +52,54 @@ int rxvt_term::scale_pixmap (const char *geom) { - int flags, changed = 0; - int x = 0, y = 0; - unsigned int w = 0, h = 0; - unsigned int n; - char *p, *str; - bgPixmap_t *bgpixmap = &(bgPixmap); + int flags, changed = 0; + int x = 0, y = 0; + unsigned int w = 0, h = 0; + unsigned int n; + char *p; + bgPixmap_t *bgpixmap = & (bgPixmap); -#define MAXLEN_GEOM sizeof("[1000x1000+1000+1000]") +#define MAXLEN_GEOM sizeof("[10000x10000+10000+10000]") if (geom == NULL) return 0; - str = (char *)rxvt_malloc (MAXLEN_GEOM + 1); - if (!STRCMP(geom, "?")) + + char str[MAXLEN_GEOM]; + + if (!strcmp (geom, "?")) { - sprintf(str, "[%dx%d+%d+%d]", /* can't presume snprintf() ! */ - min(bgpixmap->w, 9999), min(bgpixmap->h, 9999), - min(bgpixmap->x, 9999), min(bgpixmap->y, 9999)); - xterm_seq (XTerm_title, str, CHAR_ST); - free(str); + sprintf (str, "[%dx%d+%d+%d]", /* can't presume snprintf () ! */ + min (bgpixmap->w, 32767), min (bgpixmap->h, 32767), + min (bgpixmap->x, 32767), min (bgpixmap->y, 32767)); + process_xterm_seq (XTerm_title, str, CHAR_ST); return 0; } - if ((p = STRCHR(geom, ';')) == NULL) - p = STRCHR(geom, '\0'); + if ((p = strchr (geom, ';')) == NULL) + p = strchr (geom, '\0'); + n = (p - geom); if (n <= MAXLEN_GEOM) { - STRNCPY(str, geom, n); + strncpy (str, geom, n); str[n] = '\0'; - flags = XParseGeometry(str, &x, &y, &w, &h); + flags = XParseGeometry (str, &x, &y, &w, &h); + if (!flags) { flags |= WidthValue; w = 0; } /* default is tile */ + if (flags & WidthValue) { if (!(flags & XValue)) x = 50; + if (!(flags & HeightValue)) h = w; + if (w && !h) { w = (bgpixmap->w * w) / 100; @@ -104,25 +110,28 @@ w = bgpixmap->w; h = (bgpixmap->h * h) / 100; } - if (w > 1000) - w = 1000; - if (h > 1000) - h = 1000; + + min_it (w, 32767); + min_it (h, 32767); + if (bgpixmap->w != (short)w) { bgpixmap->w = (short)w; changed++; } + if (bgpixmap->h != (short)h) { bgpixmap->h = (short)h; changed++; } } + if (!(flags & YValue)) { if (flags & XNegative) flags |= YNegative; + y = x; } @@ -131,145 +140,142 @@ x += bgpixmap->x; y += bgpixmap->y; } - else + + if (xpmAttr.width && xpmAttr.height) { - if (flags & XNegative) - x += 100; - if (flags & YNegative) - y += 100; - } - MIN_IT(x, 100); - MIN_IT(y, 100); - MAX_IT(x, 0); - MAX_IT(y, 0); + x = MOD(x, xpmAttr.width); + y = MOD(y, xpmAttr.height); + } + if (bgpixmap->x != x) { bgpixmap->x = x; changed++; } + if (bgpixmap->y != y) { bgpixmap->y = y; changed++; } } - free(str); + return changed; } void rxvt_term::resize_pixmap () { - XGCValues gcvalue; - GC gc; - unsigned int width = TermWin_TotalWidth(); - unsigned int height = TermWin_TotalHeight(); + XGCValues gcvalue; + GC gc; - if (TermWin.pixmap != None) - XFreePixmap(Xdisplay, TermWin.pixmap); + if (pixmap != None) + XFreePixmap (xdisp, pixmap); if (bgPixmap.pixmap == None) { /* So be it: I'm not using pixmaps */ - TermWin.pixmap = None; - if (!(Options & Opt_transparent) || am_transparent == 0) - XSetWindowBackground(Xdisplay, TermWin.vt, - PixColors[Color_bg]); + pixmap = None; + + if (!OPTION (Opt_transparent) || !am_transparent) + XSetWindowBackground (xdisp, vt, pix_colors[Color_bg]); + return; } - gcvalue.foreground = PixColors[Color_bg]; - gc = XCreateGC(Xdisplay, TermWin.vt, GCForeground, &gcvalue); + gcvalue.foreground = pix_colors[Color_bg]; + gc = XCreateGC (xdisp, vt, GCForeground, &gcvalue); if (bgPixmap.pixmap != None) { /* we have a specified pixmap */ - unsigned int w = bgPixmap.w, h = bgPixmap.h, - x = bgPixmap.x, y = bgPixmap.y; - unsigned int xpmh = xpmAttr.height, - xpmw = xpmAttr.width; + unsigned int w = bgPixmap.w, h = bgPixmap.h, + x = bgPixmap.x, y = bgPixmap.y; + unsigned int xpmh = xpmAttr.height, + xpmw = xpmAttr.width; /* * don't zoom pixmap too much nor expand really small pixmaps */ - if (w > 1000 || h > 1000) + if (w > 32767 || h > 32767) w = 1; else if (width > (10 * xpmw) || height > (10 * xpmh)) w = 0; /* tile */ - if (w == 0) + if (!w) { /* basic X tiling - let the X server do it */ - TermWin.pixmap = XCreatePixmap(Xdisplay, TermWin.vt, - xpmw, xpmh, - (unsigned int)XDEPTH); - XCopyArea(Xdisplay, bgPixmap.pixmap, TermWin.pixmap, gc, - 0, 0, xpmw, xpmh, 0, 0); + pixmap = XCreatePixmap (xdisp, vt, xpmw, xpmh, depth); + + XCopyArea (xdisp, bgPixmap.pixmap, pixmap, gc, x, y, xpmw - x, xpmh - y, 0, 0); + XCopyArea (xdisp, bgPixmap.pixmap, pixmap, gc, x, 0, xpmw - x, y, 0, xpmh - y); + XCopyArea (xdisp, bgPixmap.pixmap, pixmap, gc, 0, y, x, xpmh - y, xpmw - x, 0); + XCopyArea (xdisp, bgPixmap.pixmap, pixmap, gc, 0, 0, x, y, xpmw - x, xpmh - y); } else { - float incr, p; - Pixmap tmp; + float incr, p; + Pixmap tmp; - TermWin.pixmap = XCreatePixmap(Xdisplay, TermWin.vt, - width, height, - (unsigned int)XDEPTH); + pixmap = XCreatePixmap (xdisp, vt, width, height, depth); /* * horizontal scaling */ - rxvt_pixmap_incr(&w, &x, &incr, &p, width, xpmw); + rxvt_pixmap_incr (&w, &x, &incr, &p, width, xpmw); - tmp = XCreatePixmap(Xdisplay, TermWin.vt, - width, xpmh, (unsigned int)XDEPTH); - XFillRectangle(Xdisplay, tmp, gc, 0, 0, width, - xpmh); + tmp = XCreatePixmap (xdisp, vt, width, xpmh, depth); + XFillRectangle (xdisp, tmp, gc, 0, 0, width, xpmh); for ( /*nil */ ; x < w; x++, p += incr) { if (p >= xpmw) p = 0; + /* copy one column from the original pixmap to the tmp pixmap */ - XCopyArea(Xdisplay, bgPixmap.pixmap, tmp, gc, - (int)p, 0, 1, xpmh, (int)x, 0); + XCopyArea (xdisp, bgPixmap.pixmap, tmp, gc, (int)p, 0, 1, xpmh, (int)x, 0); } /* * vertical scaling */ - rxvt_pixmap_incr(&h, &y, &incr, &p, height, xpmh); + rxvt_pixmap_incr (&h, &y, &incr, &p, height, xpmh); if (y > 0) - XFillRectangle(Xdisplay, TermWin.pixmap, gc, 0, 0, width, - y); + XFillRectangle (xdisp, pixmap, gc, 0, 0, width, y); + if (h < height) - XFillRectangle(Xdisplay, TermWin.pixmap, gc, 0, (int)h, - width, height - h + 1); + XFillRectangle (xdisp, pixmap, gc, 0, (int)h, width, height - h + 1); + for ( /*nil */ ; y < h; y++, p += incr) { if (p >= xpmh) p = 0; + /* copy one row from the tmp pixmap to the main pixmap */ - XCopyArea(Xdisplay, tmp, TermWin.pixmap, gc, - 0, (int)p, width, 1, 0, (int)y); + XCopyArea (xdisp, tmp, pixmap, gc, 0, (int)p, width, 1, 0, (int)y); } - XFreePixmap(Xdisplay, tmp); + + XFreePixmap (xdisp, tmp); } } - XSetWindowBackgroundPixmap(Xdisplay, TermWin.vt, TermWin.pixmap); - XFreeGC(Xdisplay, gc); - am_transparent = 0; - XClearWindow(Xdisplay, TermWin.vt); + XSetWindowBackgroundPixmap (xdisp, vt, pixmap); + + if (pixmap != None) + { + XFreePixmap (xdisp, pixmap); + pixmap = None; + } - XSync(Xdisplay, False); + XFreeGC (xdisp, gc); + am_transparent = 0; } /* * Calculate tiling sizes and increments * At start, p == 0, incr == xpmwidthheight */ -/* INTPROTO */ static void -rxvt_pixmap_incr(unsigned int *wh, unsigned int *xy, float *incr, float *p, unsigned int widthheight, unsigned int xpmwidthheight) +rxvt_pixmap_incr (unsigned int *wh, unsigned int *xy, float *incr, float *p, unsigned int widthheight, unsigned int xpmwidthheight) { unsigned int cwh, cxy; float cincr, cp; @@ -343,16 +349,17 @@ Pixmap rxvt_term::set_bgPixmap (const char *file) { - char *f; + char *f; - assert(file != NULL); + assert (file != NULL); if (bgPixmap.pixmap != None) { - XFreePixmap(Xdisplay, bgPixmap.pixmap); + XFreePixmap (xdisp, bgPixmap.pixmap); bgPixmap.pixmap = None; } - XSetWindowBackground(Xdisplay, TermWin.vt, PixColors[Color_bg]); + + XSetWindowBackground (xdisp, vt, pix_colors[Color_bg]); if (*file != '\0') { @@ -361,33 +368,34 @@ /* * we already have the required attributes */ - /* XGetWindowAttributes(Xdisplay, TermWin.vt, &attr); */ + /* XGetWindowAttributes (xdisp, vt, &attr); */ xpmAttr.closeness = 30000; - xpmAttr.colormap = XCMAP; - xpmAttr.visual = XVISUAL; - xpmAttr.depth = XDEPTH; - xpmAttr.valuemask = (XpmCloseness | XpmColormap | XpmVisual | - XpmDepth | XpmSize | XpmReturnPixels); + xpmAttr.colormap = cmap; + xpmAttr.visual = visual; + xpmAttr.depth = depth; + xpmAttr.valuemask = (XpmCloseness | XpmColormap | XpmVisual + | XpmDepth | XpmSize | XpmReturnPixels); /* search environment variables here too */ - f = (char *)rxvt_File_find(file, ".xpm", rs[Rs_path]); + f = (char *)rxvt_File_find (file, ".xpm", rs[Rs_path]); if (f == NULL - || XpmReadFileToPixmap(Xdisplay, Xroot, f, - &bgPixmap.pixmap, NULL, - &xpmAttr)) + || XpmReadFileToPixmap (xdisp, display->root, f, + &bgPixmap.pixmap, NULL, + &xpmAttr)) { - char *p; + char *p; /* semi-colon delimited */ - if ((p = STRCHR(file, ';')) == NULL) - p = STRCHR(file, '\0'); + if ((p = strchr (file, ';')) == NULL) + p = strchr (file, '\0'); - rxvt_print_error("couldn't load XPM file \"%.*s\"", (p - file), - file); + rxvt_warn ("couldn't load XPM file \"%.*s\", ignoring.\n", (p - file), file); } - free(f); + + free (f); } + resize_pixmap (); return bgPixmap.pixmap; }