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.32 by root, Sat Feb 18 15:24:39 2006 UTC vs.
Revision 1.38 by sasha, Fri Jun 8 20:04:12 2007 UTC

1/*--------------------------------*-C-*---------------------------------* 1/*----------------------------------------------------------------------*
2 * File: xpm.C 2 * File: xpm.C
3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
4 * 4 *
5 * All portions of code are copyright by their respective author/s. 5 * All portions of code are copyright by their respective author/s.
6 * Copyright (c) 1997 Carsten Haitzler <raster@zip.com.au> 6 * Copyright (c) 1997 Carsten Haitzler <raster@zip.com.au>
7 * Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de> 7 * Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de>
8 * Copyright (c) 1998-2001 Geoff Wing <gcw@pobox.com> 8 * Copyright (c) 1998-2001 Geoff Wing <gcw@pobox.com>
9 * Copyright (c) 2005-2006 Marc Lehmann <pcg@goof.com>
9 * 10 *
10 * This program is free software; you can redistribute it and/or modify 11 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by 12 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or 13 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version. 14 * (at your option) any later version.
55 int flags, changed = 0; 56 int flags, changed = 0;
56 int x = 0, y = 0; 57 int x = 0, y = 0;
57 unsigned int w = 0, h = 0; 58 unsigned int w = 0, h = 0;
58 unsigned int n; 59 unsigned int n;
59 char *p; 60 char *p;
60 bgPixmap_t *bgpixmap = & (bgPixmap); 61 bgPixmap_t *bgpixmap = &bgPixmap;
61 62
62#define MAXLEN_GEOM sizeof("[10000x10000+10000+10000]") 63#define MAXLEN_GEOM sizeof("[10000x10000+10000+10000]")
63 64
64 if (geom == NULL) 65 if (geom == NULL)
65 return 0; 66 return 0;
77 78
78 if ((p = strchr (geom, ';')) == NULL) 79 if ((p = strchr (geom, ';')) == NULL)
79 p = strchr (geom, '\0'); 80 p = strchr (geom, '\0');
80 81
81 n = (p - geom); 82 n = (p - geom);
82 if (n <= MAXLEN_GEOM) 83 if (n < MAXLEN_GEOM)
83 { 84 {
84 strncpy (str, geom, n); 85 strncpy (str, geom, n);
85 str[n] = '\0'; 86 str[n] = '\0';
86 87
88 if (strcmp(str, "auto") == 0)
89 {
90 if (!bgpixmap->auto_resize)
91 changed++;
92 bgpixmap->auto_resize = True ;
93 w = szHint.width ;
94 h = szHint.height ;
95 flags = WidthValue|HeightValue ;
96 }
97 else
98 {
99 bgpixmap->auto_resize = False ;
87 flags = XParseGeometry (str, &x, &y, &w, &h); 100 flags = XParseGeometry (str, &x, &y, &w, &h);
101 }
88 102
89 if (!flags) 103 if (!flags)
90 { 104 {
91 flags |= WidthValue; 105 flags |= WidthValue;
92 w = 0; 106 w = 0;
168{ 182{
169 XGCValues gcvalue; 183 XGCValues gcvalue;
170 GC gc; 184 GC gc;
171 185
172 if (pixmap != None) 186 if (pixmap != None)
187 {
173 XFreePixmap (dpy, pixmap); 188 XFreePixmap (dpy, pixmap);
189 pixmap = None ;
190 }
174 191
175 if (bgPixmap.pixmap == None) 192 if (bgPixmap.pixmap == None)
176 { /* So be it: I'm not using pixmaps */ 193 { /* So be it: I'm not using pixmaps */
177 pixmap = None; 194 pixmap = None;
178 195
196#ifdef TRANSPARENT
179 if (!OPTION (Opt_transparent) || !am_transparent) 197 if (!option (Opt_transparent) || !am_transparent)
198#endif
180 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]); 199 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]);
181 200
182 return; 201 return;
183 } 202 }
184 203
190 unsigned int w = bgPixmap.w, h = bgPixmap.h, 209 unsigned int w = bgPixmap.w, h = bgPixmap.h,
191 x = bgPixmap.x, y = bgPixmap.y; 210 x = bgPixmap.x, y = bgPixmap.y;
192 unsigned int xpmh = xpmAttr.height, 211 unsigned int xpmh = xpmAttr.height,
193 xpmw = xpmAttr.width; 212 xpmw = xpmAttr.width;
194 213
214 if (bgPixmap.auto_resize)
215 {
216 w = szHint.width ;
217 h = szHint.height ;
218 }
195 /* 219 /*
196 * don't zoom pixmap too much nor expand really small pixmaps 220 * don't zoom pixmap too much nor expand really small pixmaps
197 */ 221 */
198 if (w > 32767 || h > 32767) 222 if (w > 32767 || h > 32767)
199 w = 1; 223 w = 1;
210 XCopyArea (dpy, bgPixmap.pixmap, pixmap, gc, x, 0, xpmw - x, y, 0, xpmh - y); 234 XCopyArea (dpy, bgPixmap.pixmap, pixmap, gc, x, 0, xpmw - x, y, 0, xpmh - y);
211 XCopyArea (dpy, bgPixmap.pixmap, pixmap, gc, 0, y, x, xpmh - y, xpmw - x, 0); 235 XCopyArea (dpy, bgPixmap.pixmap, pixmap, gc, 0, y, x, xpmh - y, xpmw - x, 0);
212 XCopyArea (dpy, bgPixmap.pixmap, pixmap, gc, 0, 0, x, y, xpmw - x, xpmh - y); 236 XCopyArea (dpy, bgPixmap.pixmap, pixmap, gc, 0, 0, x, y, xpmw - x, xpmh - y);
213 } 237 }
214 else 238 else
239#ifdef HAVE_AFTERIMAGE
240#ifdef TRANSPARENT
241 if (!option(Opt_transparent) || !am_transparent)
242 /* will do that in check_our_parents otherwise */
243#endif
244 {
245 ASImage *scaled_im = scale_asimage( display->asv, original_asim, w, h, ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT );
246 if (scaled_im)
247 {
248 pixmap = asimage2pixmap( display->asv, display->root, scaled_im, gc, True );
249 destroy_asimage( &scaled_im );
250 }
251 }
252#else /* HAVE_AFTERIMAGE */
215 { 253 {
216 float incr, p; 254 float incr, p;
217 Pixmap tmp; 255 Pixmap tmp;
218 256
219 pixmap = XCreatePixmap (dpy, vt, width, height, depth); 257 pixmap = XCreatePixmap (dpy, vt, width, height, depth);
254 XCopyArea (dpy, tmp, pixmap, gc, 0, (int)p, width, 1, 0, (int)y); 292 XCopyArea (dpy, tmp, pixmap, gc, 0, (int)p, width, 1, 0, (int)y);
255 } 293 }
256 294
257 XFreePixmap (dpy, tmp); 295 XFreePixmap (dpy, tmp);
258 } 296 }
297#endif /* HAVE_AFTERIMAGE */
259 } 298 }
260 299
261 XSetWindowBackgroundPixmap (dpy, vt, pixmap); 300 XSetWindowBackgroundPixmap (dpy, vt, pixmap);
262 301
263 XFreeGC (dpy, gc); 302 XFreeGC (dpy, gc);
303#ifdef TRANSPARENT
264 am_transparent = 0; 304 am_transparent = 0;
305#endif
265} 306}
266 307
267/* 308/*
268 * Calculate tiling sizes and increments 309 * Calculate tiling sizes and increments
269 * At start, p == 0, incr == xpmwidthheight 310 * At start, p == 0, incr == xpmwidthheight
362 /* 403 /*
363 * we already have the required attributes 404 * we already have the required attributes
364 */ 405 */
365 /* XGetWindowAttributes (dpy, vt, &attr); */ 406 /* XGetWindowAttributes (dpy, vt, &attr); */
366 407
408#ifdef HAVE_AFTERIMAGE
409 if (asimman == NULL)
410 asimman = create_generic_imageman(rs[Rs_path]);
411 if ((f = strchr (file, ';')) == NULL)
412 original_asim = get_asimage( asimman, file, 0xFFFFFFFF, 100 );
413 else
414 {
415 f = strndup( file, f - file );
416 original_asim = get_asimage( asimman, f, 0xFFFFFFFF, 100 );
417 free( f );
418 }
419 if (original_asim)
420 {
421 bgPixmap.pixmap = asimage2pixmap( display->asv, display->root, original_asim, NULL, True );
422 xpmAttr.width = original_asim->width ;
423 xpmAttr.height = original_asim->height ;
424 }
425#else /* HAVE_AFTERIMAGE */
367 xpmAttr.closeness = 30000; 426 xpmAttr.closeness = 30000;
368 xpmAttr.colormap = cmap; 427 xpmAttr.colormap = cmap;
369 xpmAttr.visual = visual; 428 xpmAttr.visual = visual;
370 xpmAttr.depth = depth; 429 xpmAttr.depth = depth;
371 xpmAttr.valuemask = (XpmCloseness | XpmColormap | XpmVisual 430 xpmAttr.valuemask = (XpmCloseness | XpmColormap | XpmVisual
384 if ((p = strchr (file, ';')) == NULL) 443 if ((p = strchr (file, ';')) == NULL)
385 p = strchr (file, '\0'); 444 p = strchr (file, '\0');
386 445
387 rxvt_warn ("couldn't load XPM file \"%.*s\", ignoring.\n", (p - file), file); 446 rxvt_warn ("couldn't load XPM file \"%.*s\", ignoring.\n", (p - file), file);
388 } 447 }
389
390 free (f); 448 free (f);
449#endif /* HAVE_AFTERIMAGE */
391 } 450 }
392 451
393 resize_pixmap (); 452 resize_pixmap ();
394 return bgPixmap.pixmap; 453 return bgPixmap.pixmap;
395} 454}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines