ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/xpm.C
(Generate patch)

Comparing rxvt-unicode/src/xpm.C (file contents):
Revision 1.53 by sasha, Tue Jul 31 22:24:36 2007 UTC vs.
Revision 1.54 by ayin, Thu Aug 2 00:09:54 2007 UTC

25 25
26#include "../config.h" /* NECESSARY */ 26#include "../config.h" /* NECESSARY */
27#include "rxvt.h" /* NECESSARY */ 27#include "rxvt.h" /* NECESSARY */
28 28
29#ifdef XPM_BACKGROUND 29#ifdef XPM_BACKGROUND
30
31#ifndef HAVE_AFTERIMAGE
32/*
33 * search for FILE in the current working directory, and within the
34 * colon-delimited PATHLIST, adding the file extension EXT if required.
35 *
36 * FILE is either semi-colon or zero terminated
37 */
38static char *
39rxvt_File_search_path (const char *pathlist, const char *file, const char *ext)
40{
41 int maxpath, len;
42 const char *p, *path;
43 char name[256];
44
45 if (!access (file, R_OK)) /* found (plain name) in current directory */
46 return strdup (file);
47
48 /* semi-colon delimited */
49 if ((p = strchr (file, ';')))
50 len = (p - file);
51 else
52 len = strlen (file);
53
54 /* leave room for an extra '/' and trailing '\0' */
55 maxpath = sizeof (name) - (len + (ext ? strlen (ext) : 0) + 2);
56 if (maxpath <= 0)
57 return NULL;
58
59 /* check if we can find it now */
60 strncpy (name, file, len);
61 name[len] = '\0';
62
63 if (!access (name, R_OK))
64 return strdup (name);
65 if (ext)
66 {
67 strcat (name, ext);
68 if (!access (name, R_OK))
69 return strdup (name);
70 }
71 for (path = pathlist; path != NULL && *path != '\0'; path = p)
72 {
73 int n;
74
75 /* colon delimited */
76 if ((p = strchr (path, ':')) == NULL)
77 p = strchr (path, '\0');
78
79 n = (p - path);
80 if (*p != '\0')
81 p++;
82
83 if (n > 0 && n <= maxpath)
84 {
85 strncpy (name, path, n);
86 if (name[n - 1] != '/')
87 name[n++] = '/';
88 name[n] = '\0';
89 strncat (name, file, len);
90
91 if (!access (name, R_OK))
92 return strdup (name);
93 if (ext)
94 {
95 strcat (name, ext);
96 if (!access (name, R_OK))
97 return strdup (name);
98 }
99 }
100 }
101 return NULL;
102}
103
104/*
105 * Calculate tiling sizes and increments
106 * At start, p == 0, incr == xpmwidthheight
107 */
108static void
109rxvt_pixmap_incr (unsigned int *wh, unsigned int *xy, float *incr, float *p, unsigned int widthheight, unsigned int xpmwidthheight)
110{
111 unsigned int cwh, cxy;
112 float cincr, cp;
113
114 cp = 0;
115 cincr = (float)xpmwidthheight;
116 cxy = *xy;
117 cwh = *wh;
118 if (cwh == 1)
119 { /* display one image, no horizontal/vertical scaling */
120 cincr = (float)widthheight;
121 if (xpmwidthheight <= widthheight)
122 {
123 cwh = xpmwidthheight;
124 cxy = (cxy * (widthheight - cwh)) / 100; /* beware! order */
125 cwh += cxy;
126 }
127 else
128 {
129 cxy = 0;
130 cwh = widthheight;
131 }
132 }
133 else if (cwh < 10)
134 { /* fit WH images across/down screen */
135 cincr *= cwh;
136 cxy = 0;
137 cwh = widthheight;
138 }
139 else
140 {
141 cincr *= 100.0 / cwh;
142 if (cwh < 100)
143 { /* contract */
144 float pos;
145
146 cwh = (cwh * widthheight) / 100;
147 pos = (float)cxy / 100 * widthheight - (cwh / 2);
148
149 cxy = (widthheight - cwh);
150 if (pos <= 0)
151 cxy = 0;
152 else if (pos < cxy)
153 cxy = (int) pos;
154 cwh += cxy;
155 }
156 else
157 { /* expand */
158 if (cxy > 0)
159 { /* position */
160 float pos;
161
162 pos = (float)cxy / 100 * xpmwidthheight - (cincr / 2);
163 cp = xpmwidthheight - cincr;
164 if (pos <= 0)
165 cp = 0;
166 else if (pos < cp)
167 cp = pos;
168 }
169 cxy = 0;
170 cwh = widthheight;
171 }
172 }
173 cincr /= widthheight;
174 *wh = cwh;
175 *xy = cxy;
176 *incr = cincr;
177 *p = cp;
178}
179#endif
180 30
181/* 31/*
182 * These GEOM strings indicate absolute size/position: 32 * These GEOM strings indicate absolute size/position:
183 * @ `WxH+X+Y' 33 * @ `WxH+X+Y'
184 * @ `WxH+X' -> Y = X 34 * @ `WxH+X' -> Y = X
382 XCopyArea (dpy, bgPixmap.pixmap, pixmap, gc, x, 0, xpmw - x, y, 0, xpmh - y); 232 XCopyArea (dpy, bgPixmap.pixmap, pixmap, gc, x, 0, xpmw - x, y, 0, xpmh - y);
383 XCopyArea (dpy, bgPixmap.pixmap, pixmap, gc, 0, y, x, xpmh - y, xpmw - x, 0); 233 XCopyArea (dpy, bgPixmap.pixmap, pixmap, gc, 0, y, x, xpmh - y, xpmw - x, 0);
384 XCopyArea (dpy, bgPixmap.pixmap, pixmap, gc, 0, 0, x, y, xpmw - x, xpmh - y); 234 XCopyArea (dpy, bgPixmap.pixmap, pixmap, gc, 0, 0, x, y, xpmw - x, xpmh - y);
385 } 235 }
386 else 236 else
387#ifdef HAVE_AFTERIMAGE
388#ifdef ENABLE_TRANSPARENCY 237#ifdef ENABLE_TRANSPARENCY
389 if (!option(Opt_transparent) || !am_transparent) 238 if (!option(Opt_transparent) || !am_transparent)
390 /* will do that in check_our_parents otherwise */ 239 /* will do that in check_our_parents otherwise */
391#endif 240#endif
392 { 241 {
395 { 244 {
396 pixmap = asimage2pixmap(asv, display->root, scaled_im, gc, True); 245 pixmap = asimage2pixmap(asv, display->root, scaled_im, gc, True);
397 destroy_asimage (&scaled_im); 246 destroy_asimage (&scaled_im);
398 } 247 }
399 } 248 }
400#else /* HAVE_AFTERIMAGE */
401 {
402 float incr, p;
403 Pixmap tmp;
404
405 pixmap = XCreatePixmap (dpy, vt, width, height, depth);
406 /*
407 * horizontal scaling
408 */
409 rxvt_pixmap_incr (&w, &x, &incr, &p, width, xpmw);
410
411 tmp = XCreatePixmap (dpy, vt, width, xpmh, depth);
412 XFillRectangle (dpy, tmp, gc, 0, 0, width, xpmh);
413
414 for ( /*nil */ ; x < w; x++, p += incr)
415 {
416 if (p >= xpmw)
417 p = 0;
418
419 /* copy one column from the original pixmap to the tmp pixmap */
420 XCopyArea (dpy, bgPixmap.pixmap, tmp, gc, (int)p, 0, 1, xpmh, (int)x, 0);
421 }
422
423 /*
424 * vertical scaling
425 */
426 rxvt_pixmap_incr (&h, &y, &incr, &p, height, xpmh);
427
428 if (y > 0)
429 XFillRectangle (dpy, pixmap, gc, 0, 0, width, y);
430
431 if (h < height)
432 XFillRectangle (dpy, pixmap, gc, 0, (int)h, width, height - h + 1);
433
434 for ( /*nil */ ; y < h; y++, p += incr)
435 {
436 if (p >= xpmh)
437 p = 0;
438
439 /* copy one row from the tmp pixmap to the main pixmap */
440 XCopyArea (dpy, tmp, pixmap, gc, 0, (int)p, width, 1, 0, (int)y);
441 }
442
443 XFreePixmap (dpy, tmp);
444 }
445#endif /* HAVE_AFTERIMAGE */
446 } 249 }
447 250
448 XSetWindowBackgroundPixmap (dpy, vt, pixmap); 251 XSetWindowBackgroundPixmap (dpy, vt, pixmap);
449 252
450 XFreeGC (dpy, gc); 253 XFreeGC (dpy, gc);
475 /* 278 /*
476 * we already have the required attributes 279 * we already have the required attributes
477 */ 280 */
478 /* XGetWindowAttributes (dpy, vt, &attr); */ 281 /* XGetWindowAttributes (dpy, vt, &attr); */
479 282
480#ifdef HAVE_AFTERIMAGE
481 if (asimman == NULL) 283 if (asimman == NULL)
482 asimman = create_generic_imageman(rs[Rs_path]); 284 asimman = create_generic_imageman(rs[Rs_path]);
483 if ((f = strchr (file, ';')) == NULL) 285 if ((f = strchr (file, ';')) == NULL)
484 original_asim = get_asimage( asimman, file, 0xFFFFFFFF, 100 ); 286 original_asim = get_asimage( asimman, file, 0xFFFFFFFF, 100 );
485 else 287 else
495 { 297 {
496 bgPixmap.pixmap = asimage2pixmap (asv, display->root, original_asim, NULL, True); 298 bgPixmap.pixmap = asimage2pixmap (asv, display->root, original_asim, NULL, True);
497 xpmAttr.width = original_asim->width ; 299 xpmAttr.width = original_asim->width ;
498 xpmAttr.height = original_asim->height ; 300 xpmAttr.height = original_asim->height ;
499 } 301 }
500#else /* HAVE_AFTERIMAGE */
501 xpmAttr.closeness = 30000;
502 xpmAttr.colormap = cmap;
503 xpmAttr.visual = visual;
504 xpmAttr.depth = depth;
505 xpmAttr.valuemask = (XpmCloseness | XpmColormap | XpmVisual
506 | XpmDepth | XpmSize | XpmReturnPixels);
507
508 /* search environment variables here too */
509 f = rxvt_File_search_path (rs[Rs_path], file, ".xpm");
510 if (f == NULL
511 || XpmReadFileToPixmap (dpy, display->root, f,
512 &bgPixmap.pixmap, NULL,
513 &xpmAttr))
514 {
515 char *p;
516
517 /* semi-colon delimited */
518 if ((p = strchr (file, ';')) == NULL)
519 p = strchr (file, '\0');
520
521 rxvt_warn ("couldn't load XPM file \"%.*s\", ignoring.\n", (p - file), file);
522 }
523 free (f);
524#endif /* HAVE_AFTERIMAGE */
525 } 302 }
526 303
527 resize_pixmap (); 304 resize_pixmap ();
528 return bgPixmap.pixmap; 305 return bgPixmap.pixmap;
529} 306}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines