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.21 by root, Fri Feb 4 11:41:23 2005 UTC vs.
Revision 1.58 by sasha, Sat Aug 4 07:05:31 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.
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *---------------------------------------------------------------------*/ 24 *---------------------------------------------------------------------*/
24 25
25#include "../config.h" /* NECESSARY */ 26#include "../config.h" /* NECESSARY */
26#include "rxvt.h" /* NECESSARY */ 27#include "rxvt.h" /* NECESSARY */
27#include "xpm.intpro" /* PROTOS for internal routines */
28 28
29/*
30 * Pixmap geometry string interpretation :
31 * Each geometry string contains zero or one scale/position
32 * adjustment and may optionally be followed by a colon and one or more
33 * colon-delimited pixmap operations.
34 * The following table shows the valid geometry strings and their
35 * affects on the background image :
36 *
37 * WxH+X+Y Set scaling to W% by H%, and position to X% by Y%.
38 * W and H are percentages of the terminal window size.
39 * X and Y are also percentages; e.g., +50+50 centers
40 * the image in the window.
41 * WxH+X Assumes Y == X
42 * WxH Assumes Y == X == 50 (centers the image)
43 * W+X+Y Assumes H == W
44 * W+X Assumes H == W and Y == X
45 * W Assumes H == W and Y == X == 50
46 *
47 * Adjusting position only :
48 * =+X+Y Set position to X% by Y% (absolute).
49 * =+X Set position to X% by X%.
50 * +X+Y Adjust position horizontally X% and vertically Y%
51 * from current position (relative).
52 * +X Adjust position horizontally X% and vertically X%
53 * from current position.
54 *
55 * Adjusting scale only :
56 * Wx0 Multiply horizontal scaling factor by W%
57 * 0xH Multiply vertical scaling factor by H%
58 * 0x0 No scaling (show image at normal size).
59 *
60 * Pixmap Operations : (should be prepended by a colon)
61 * tile Tile image. Scaling/position modifiers above will affect
62 * the tile size and origin.
63 * propscale When scaling, scale proportionally. That is, maintain the
64 * proper aspect ratio for the image. Any portion of the
65 * background not covered by the image is filled with the
66 * current background color.
67 * hscale Scale horizontally, tile vertically ?
68 * vscale Tile horizontally, scale vertically ?
69 * scale Scale both up and down
70 * auto Same as 100x100+50+50
71 */
72
73#ifdef HAVE_BG_PIXMAP
74bool
75bgPixmap_t::window_size_sensitive ()
76{
29#ifdef XPM_BACKGROUND 77#ifdef XPM_BACKGROUND
78#ifdef HAVE_AFTERIMAGE
79 if (original_asim != NULL)
80#endif
81 {
82 if (h_scale != 0 || v_scale != 0)
83 return true;
84 }
85#endif
86#ifdef ENABLE_TRANSPARENCY
87 if (flags & bgPmap_Transparent)
88 return true;
89#endif
90 return false;
91}
30 92
31/* 93#ifdef XPM_BACKGROUND
32 * These GEOM strings indicate absolute size/position: 94static inline bool
33 * @ `WxH+X+Y' 95check_set_scale_value (int geom_flags, int flag, unsigned int &scale, unsigned int new_value)
34 * @ `WxH+X' -> Y = X
35 * @ `WxH' -> Y = X = 50
36 * @ `W+X+Y' -> H = W
37 * @ `W+X' -> H = W, Y = X
38 * @ `W' -> H = W, X = Y = 50
39 * @ `0xH' -> H *= H/100, X = Y = 50 (W unchanged)
40 * @ `Wx0' -> W *= W/100, X = Y = 50 (H unchanged)
41 * @ `=+X+Y' -> (H, W unchanged)
42 * @ `=+X' -> Y = X (H, W unchanged)
43 *
44 * These GEOM strings adjust position relative to current position:
45 * @ `+X+Y'
46 * @ `+X' -> Y = X
47 *
48 * And this GEOM string is for querying current scale/position:
49 * @ `?'
50 */
51int
52rxvt_term::scale_pixmap (const char *geom)
53{ 96{
54 int flags, changed = 0; 97 if (geom_flags & flag)
98 {
99 if (new_value > 1000)
100 new_value = 1000;
101 if (new_value != scale)
102 {
103 scale = new_value;
104 return true;
105 }
106 }
107 return false;
108}
109
110static inline bool
111check_set_align_value (int geom_flags, int flag, int &align, int new_value)
112{
113 if (geom_flags & flag)
114 {
115 if (new_value < -100)
116 new_value = -100;
117 else if (new_value > 200)
118 new_value = 200;
119 if (new_value != align)
120 {
121 align = new_value;
122 return true;
123 }
124 }
125 return false;
126}
127
128bool
129bgPixmap_t::handle_geometry (const char *geom)
130{
131 int geom_flags = 0, changed = 0;
55 int x = 0, y = 0; 132 int x = 0, y = 0;
56 unsigned int w = 0, h = 0; 133 unsigned int w = 0, h = 0;
57 unsigned int n; 134 unsigned int n;
58 char *p, *str; 135 unsigned long new_flags = (flags&(~bgPmap_geometryFlags));
59 bgPixmap_t *bgpixmap = & (bgPixmap); 136 char *p;
60 137#define MAXLEN_GEOM 256 /* could be longer then regular geometry string */
61#define MAXLEN_GEOM sizeof("[1000x1000+1000+1000]")
62 138
63 if (geom == NULL) 139 if (geom == NULL)
64 return 0; 140 return false;
65 str = (char *)rxvt_malloc (MAXLEN_GEOM + 1); 141
142 char str[MAXLEN_GEOM];
143
66 if (!strcmp (geom, "?")) 144 if (!strcmp (geom, "?"))
67 { 145 {
146#if 0 /* TODO: */
68 sprintf (str, "[%dx%d+%d+%d]", /* can't presume snprintf () ! */ 147 sprintf (str, "[%dx%d+%d+%d]", /* can't presume snprintf () ! */
69 min (bgpixmap->w, 9999), min (bgpixmap->h, 9999), 148 min (h_scale, 32767), min (v_scale, 32767),
70 min (bgpixmap->x, 9999), min (bgpixmap->y, 9999)); 149 min (h_align, 32767), min (v_align, 32767));
71 process_xterm_seq (XTerm_title, str, CHAR_ST); 150 process_xterm_seq (XTerm_title, str, CHAR_ST);
72 free (str); 151#endif
73 return 0; 152 return false;
74 } 153 }
75 154 while (isspace(*geom)) ++geom;
76 if ((p = strchr (geom, ';')) == NULL) 155 if ((p = strchr (geom, ';')) == NULL)
77 p = strchr (geom, '\0'); 156 p = strchr (geom, '\0');
157
78 n = (p - geom); 158 n = (p - geom);
79 if (n <= MAXLEN_GEOM) 159 if (n < MAXLEN_GEOM)
80 { 160 {
161 char *ops;
162 new_flags |= bgPmap_geometrySet;
163
81 strncpy (str, geom, n); 164 strncpy (str, geom, n);
82 str[n] = '\0'; 165 str[n] = '\0';
83 166 if (str[0] == ':')
84 flags = XParseGeometry (str, &x, &y, &w, &h); 167 ops = &str[0];
85 if (!flags) 168 else if (str[0] != 'x' && str[0] != 'X' && isalpha(str[0]))
169 ops = &str[0];
170 else
86 { 171 {
87 flags |= WidthValue; 172 char *tmp;
88 w = 0; 173 ops = strchr (str, ':');
89 } /* default is tile */ 174 if (ops != NULL)
90 if (flags & WidthValue)
91 {
92 if (! (flags & XValue))
93 x = 50;
94 if (! (flags & HeightValue))
95 h = w;
96 if (w && !h)
97 { 175 {
98 w = (bgpixmap->w * w) / 100; 176 for (tmp = ops-1; tmp >= str && isspace(*tmp); --tmp);
99 h = bgpixmap->h; 177 *(++tmp) = '\0';
178 if (ops == tmp) ++ops;
100 } 179 }
101 else if (h && !w) 180 }
181
182 if (ops > str || ops == NULL)
183 {
184 /* we have geometry string - let's handle it prior to applying ops */
185 geom_flags = XParseGeometry (str, &x, &y, &w, &h);
186
187 if ((geom_flags & XValue) && !(geom_flags & YValue))
102 { 188 {
103 w = bgpixmap->w; 189 y = x;
104 h = (bgpixmap->h * h) / 100; 190 geom_flags |= YValue;
105 } 191 }
106 if (w > 1000) 192
107 w = 1000; 193 if (flags & bgPmap_geometrySet)
108 if (h > 1000) 194 {/* new geometry is an adjustment to the old one ! */
109 h = 1000; 195 if ((geom_flags & WidthValue) && (geom_flags & HeightValue))
110 if (bgpixmap->w != (short)w) 196 {
197 if (w == 0 && h != 0)
198 {
199 w = h_scale;
200 h = (v_scale * h) / 100;
201 }
202 else if (h == 0 && w != 0)
203 {
204 w = (h_scale * w) / 100;
205 h = v_scale;
206 }
207 }
208 if (geom_flags & XValue)
209 {
210 if (str[0] != '=')
211 {
212 y += v_align;
213 x += h_align;
214 }
215 }
216 }
217 else /* setting up geometry from scratch */
111 { 218 {
112 bgpixmap->w = (short)w; 219 if (!(geom_flags & XValue))
113 changed++; 220 {/* use default geometry - centered */
221 x = y = bgPmap_defaultAlign;
222 }
223 else if (!(geom_flags & YValue))
224 y = x;
225
226 if ((geom_flags & (WidthValue|HeightValue)) == 0)
227 {/* use default geometry - scaled */
228 w = h = bgPmap_defaultScale;
229 }
230 else if (geom_flags & WidthValue)
231 {
232 if (!(geom_flags & HeightValue))
233 h = w;
234 }
235 else
236 w = h;
114 } 237 }
115 if (bgpixmap->h != (short)h) 238 } /* done parsing geometry string */
239 else if (!(flags & bgPmap_geometrySet))
240 { /* default geometry - scaled and centered */
241 x = y = bgPmap_defaultAlign;
242 w = h = bgPmap_defaultScale;
243 }
244
245 if (!(flags & bgPmap_geometrySet))
246 geom_flags |= WidthValue|HeightValue|XValue|YValue;
247
248 if (ops)
249 {
250 while (*ops)
116 { 251 {
117 bgpixmap->h = (short)h; 252 while (*ops == ':' || isspace(*ops)) ++ops;
118 changed++; 253#define CHECK_GEOM_OPS(op_str) (strncasecmp (ops, (op_str), sizeof(op_str)-1) == 0)
254 if (CHECK_GEOM_OPS("tile"))
255 {
256 w = h = 0;
257 geom_flags |= WidthValue|HeightValue;
119 } 258 }
120 } 259 else if (CHECK_GEOM_OPS("propscale"))
121 if (! (flags & YValue)) 260 {
261 if (w == 0 && h == 0)
262 {
263 w = 100;
264 geom_flags |= WidthValue;
265 }
266 new_flags |= bgPmap_propScale;
267 }
268 else if (CHECK_GEOM_OPS("hscale"))
269 {
270 if (w == 0)
271 w = 100;
272 h = 0;
273 geom_flags |= WidthValue|HeightValue;
274 }
275 else if (CHECK_GEOM_OPS("vscale"))
276 {
277 if (h == 0)
278 h = 100;
279 w = 0;
280 geom_flags |= WidthValue|HeightValue;
281 }
282 else if (CHECK_GEOM_OPS("scale"))
283 {
284 if (h == 0)
285 h = 100;
286 if (w == 0)
287 w = 100;
288 geom_flags |= WidthValue|HeightValue;
289 }
290 else if (CHECK_GEOM_OPS("auto"))
291 {
292 w = h = 100;
293 x = y = 50;
294 geom_flags |= WidthValue|HeightValue|XValue|YValue;
295 }
296#undef CHECK_GEOM_OPS
297 while (*ops != ':' && *ops != '\0') ++ops;
298 } /* done parsing ops */
122 { 299 }
123 if (flags & XNegative)
124 flags |= YNegative;
125 y = x;
126 }
127 300
128 if (! (flags & WidthValue) && geom[0] != '=') 301 if (check_set_scale_value (geom_flags, WidthValue, h_scale, w))
129 { 302 ++changed;
130 x += bgpixmap->x; 303 if (check_set_scale_value (geom_flags, HeightValue, v_scale, h))
131 y += bgpixmap->y; 304 ++changed;
132 } 305 if (check_set_align_value (geom_flags, XValue, h_align, x))
133 else 306 ++changed;
134 { 307 if (check_set_align_value (geom_flags, YValue, v_align, y))
135 if (flags & XNegative) 308 ++changed;
136 x += 100; 309 }
137 if (flags & YNegative) 310
138 y += 100; 311 if (new_flags != flags)
139 } 312 {
140 MIN_IT (x, 100); 313 flags = new_flags;
141 MIN_IT (y, 100);
142 MAX_IT (x, 0);
143 MAX_IT (y, 0);
144 if (bgpixmap->x != x)
145 {
146 bgpixmap->x = x;
147 changed++; 314 changed++;
148 }
149 if (bgpixmap->y != y)
150 {
151 bgpixmap->y = y;
152 changed++;
153 }
154 } 315 }
155 free (str); 316//fprintf( stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n",
317// flags, h_scale, v_scale, h_align, v_align);
156 return changed; 318 return (changed > 0);
157} 319}
158 320
159void 321void
160rxvt_term::resize_pixmap () 322rxvt_term::resize_pixmap ()
161{ 323{
162 XGCValues gcvalue; 324 XGCValues gcvalue;
163 GC gc; 325 GC gc;
164 unsigned int width = TermWin_TotalWidth (); 326 unsigned int w = bgPixmap.h_scale*szHint.width/100;
165 unsigned int height = TermWin_TotalHeight (); 327 unsigned int h = bgPixmap.v_scale*szHint.height/100;
166 dDisp; 328 int x = bgPixmap.h_align*szHint.width/100;
167 329 int y = bgPixmap.v_align*szHint.height/100;
168 if (TermWin.pixmap != None) 330#ifdef HAVE_AFTERIMAGE
169 XFreePixmap (disp, TermWin.pixmap); 331 ASImage *im = bgPixmap.original_asim;
170 332#else
333 void *im = NULL;
334#endif
335/* preliminary cleanup - this needs to be integrated with check_our_parents() code */
171 if (bgPixmap.pixmap == None) 336 if (bgPixmap.pixmap != None)
337 {
338 XFreePixmap (dpy, bgPixmap.pixmap);
339 bgPixmap.pixmap = None ;
340 }
341#ifdef ENABLE_TRANSPARENCY
342 if (option(Opt_transparent) && am_transparent)
343 {
344 /* we need to re-generate transparency pixmap in that case ! */
345 check_our_parents ();
346 return;
347 }
348#endif
349
350 if (im == NULL)
172 { /* So be it: I'm not using pixmaps */ 351 { /* So be it: I'm not using pixmaps */
173 TermWin.pixmap = None; 352 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]);
174
175 if (!(options & Opt_transparent) || !am_transparent)
176 XSetWindowBackground (disp, TermWin.vt,
177 pix_colors[Color_bg]);
178
179 return; 353 return;
180 } 354 }
181 355
182 gcvalue.foreground = pix_colors[Color_bg]; 356 gcvalue.foreground = pix_colors[Color_bg];
183 gc = XCreateGC (disp, TermWin.vt, GCForeground, &gcvalue); 357 gc = XCreateGC (dpy, vt, GCForeground, &gcvalue);
184 358
185 if (bgPixmap.pixmap != None)
186 { /* we have a specified pixmap */
187 unsigned int w = bgPixmap.w, h = bgPixmap.h,
188 x = bgPixmap.x, y = bgPixmap.y;
189 unsigned int xpmh = xpmAttr.height,
190 xpmw = xpmAttr.width;
191
192 /*
193 * don't zoom pixmap too much nor expand really small pixmaps 359 /* don't zoom pixmap too much nor expand really small pixmaps */
194 */ 360 if (w > 16000)
195 if (w > 1000 || h > 1000)
196 w = 1; 361 w = 1;
197 else if (width > (10 * xpmw) 362 if (h > 16000)
198 || height > (10 * xpmh)) 363 h = 1;
199 w = 0; /* tile */ 364
200 365#ifdef HAVE_AFTERIMAGE
201 if (w == 0) 366 if (w == 0)
202 { 367 w = im->width;
203 /* basic X tiling - let the X server do it */ 368 if (h == 0)
204 TermWin.pixmap = XCreatePixmap (disp, TermWin.vt, 369 h = im->height;
205 xpmw, xpmh, 370
206 (unsigned int)display->depth); 371 if (w != im->width || h != im->height)
207 XCopyArea (disp, bgPixmap.pixmap, TermWin.pixmap, gc, 372 {
208 0, 0, xpmw, xpmh, 0, 0); 373 ASImage *tmp = scale_asimage (asv, im, w, h, (x == 0 && y == 0)?ASA_XImage:ASA_ASImage, 0, ASIMAGE_QUALITY_DEFAULT);
374 if (tmp != NULL)
375 im = tmp;
376 }
377 bgPixmap.pmap_width = MIN(w,szHint.width);
378 bgPixmap.pmap_height = MIN(h,szHint.height);
379#if 0 /* TODO: fix that! */
380 if (x != 0 || y != 0)
381 {
382 ASImage *tmp = tile_asimage (asv, im, x, y, w, h, TINT_LEAVE_SAME, ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT);
383 if (tmp != NULL)
209 } 384 {
210 else 385 if (im != bgPixmap.original_asim)
386 destroy_asimage (&im);
387 im = tmp;
211 { 388 }
212 float incr, p;
213 Pixmap tmp;
214
215 TermWin.pixmap = XCreatePixmap (disp, TermWin.vt,
216 width, height,
217 (unsigned int)display->depth);
218 /*
219 * horizontal scaling
220 */
221 rxvt_pixmap_incr (&w, &x, &incr, &p, width, xpmw);
222
223 tmp = XCreatePixmap (disp, TermWin.vt,
224 width, xpmh, (unsigned int)display->depth);
225 XFillRectangle (disp, tmp, gc, 0, 0, width,
226 xpmh);
227
228 for ( /*nil */ ; x < w; x++, p += incr)
229 {
230 if (p >= xpmw)
231 p = 0;
232 /* copy one column from the original pixmap to the tmp pixmap */
233 XCopyArea (disp, bgPixmap.pixmap, tmp, gc,
234 (int)p, 0, 1, xpmh, (int)x, 0);
235 }
236
237 /*
238 * vertical scaling
239 */
240 rxvt_pixmap_incr (&h, &y, &incr, &p, height, xpmh);
241
242 if (y > 0)
243 XFillRectangle (disp, TermWin.pixmap, gc, 0, 0, width, y);
244
245 if (h < height)
246 XFillRectangle (disp, TermWin.pixmap, gc, 0, (int)h, width, height - h + 1);
247
248 for ( /*nil */ ; y < h; y++, p += incr)
249 {
250 if (p >= xpmh)
251 p = 0;
252
253 /* copy one row from the tmp pixmap to the main pixmap */
254 XCopyArea (disp, tmp, TermWin.pixmap, gc,
255 0, (int)p, width, 1, 0, (int)y);
256 }
257
258 XFreePixmap (disp, tmp);
259 }
260 } 389 }
390#endif
391 bgPixmap.pixmap = XCreatePixmap (dpy, vt, bgPixmap.pmap_width, bgPixmap.pmap_height, depth);
392 bgPixmap.pmap_depth = depth;
261 393
394 asimage2drawable (asv, bgPixmap.pixmap, im, gc, 0, 0, 0, 0, bgPixmap.pmap_width, bgPixmap.pmap_height, True);
395
396 if (im != bgPixmap.original_asim)
397 destroy_asimage (&im);
398#endif
399 if( bgPixmap.pixmap )
262 XSetWindowBackgroundPixmap (disp, TermWin.vt, TermWin.pixmap); 400 XSetWindowBackgroundPixmap (dpy, vt, bgPixmap.pixmap);
401
263 XFreeGC (disp, gc); 402 XFreeGC (dpy, gc);
264 am_transparent = 0;
265} 403}
266 404
267/* 405void
268 * Calculate tiling sizes and increments
269 * At start, p == 0, incr == xpmwidthheight
270 */
271/* INTPROTO */
272static void
273rxvt_pixmap_incr (unsigned int *wh, unsigned int *xy, float *incr, float *p, unsigned int widthheight, unsigned int xpmwidthheight)
274{
275 unsigned int cwh, cxy;
276 float cincr, cp;
277
278 cp = 0;
279 cincr = (float)xpmwidthheight;
280 cxy = *xy;
281 cwh = *wh;
282 if (cwh == 1)
283 { /* display one image, no horizontal/vertical scaling */
284 cincr = (float)widthheight;
285 if (xpmwidthheight <= widthheight)
286 {
287 cwh = xpmwidthheight;
288 cxy = (cxy * (widthheight - cwh)) / 100; /* beware! order */
289 cwh += cxy;
290 }
291 else
292 {
293 cxy = 0;
294 cwh = widthheight;
295 }
296 }
297 else if (cwh < 10)
298 { /* fit WH images across/down screen */
299 cincr *= cwh;
300 cxy = 0;
301 cwh = widthheight;
302 }
303 else
304 {
305 cincr *= 100.0 / cwh;
306 if (cwh < 100)
307 { /* contract */
308 float pos;
309
310 cwh = (cwh * widthheight) / 100;
311 pos = (float)cxy / 100 * widthheight - (cwh / 2);
312
313 cxy = (widthheight - cwh);
314 if (pos <= 0)
315 cxy = 0;
316 else if (pos < cxy)
317 cxy = (int) pos;
318 cwh += cxy;
319 }
320 else
321 { /* expand */
322 if (cxy > 0)
323 { /* position */
324 float pos;
325
326 pos = (float)cxy / 100 * xpmwidthheight - (cincr / 2);
327 cp = xpmwidthheight - cincr;
328 if (pos <= 0)
329 cp = 0;
330 else if (pos < cp)
331 cp = pos;
332 }
333 cxy = 0;
334 cwh = widthheight;
335 }
336 }
337 cincr /= widthheight;
338 *wh = cwh;
339 *xy = cxy;
340 *incr = cincr;
341 *p = cp;
342}
343
344Pixmap
345rxvt_term::set_bgPixmap (const char *file) 406rxvt_term::set_bgPixmap (const char *file)
346{ 407{
347 char *f; 408 char *f;
348 409
349 assert (file != NULL); 410 assert (file != NULL);
350 411
351 if (bgPixmap.pixmap != None) 412 if (bgPixmap.pixmap != None)
352 { 413 {
353 XFreePixmap (display->display, bgPixmap.pixmap); 414 XFreePixmap (dpy, bgPixmap.pixmap);
354 bgPixmap.pixmap = None; 415 bgPixmap.pixmap = None;
355 } 416 }
356 417
357 XSetWindowBackground (display->display, TermWin.vt, pix_colors[Color_bg]); 418 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]);
358
359 if (*file != '\0') 419 if (*file != '\0')
360 { 420 {
361 /* XWindowAttributes attr; */ 421#ifdef HAVE_AFTERIMAGE
422 if (asimman == NULL)
423 asimman = create_generic_imageman(rs[Rs_path]);
424 if ((f = strchr (file, ';')) == NULL)
425 bgPixmap.original_asim = get_asimage( asimman, file, 0xFFFFFFFF, 100 );
426 else
427 {
428 size_t len = f - file;
429 f = (char *)malloc (len + 1);
430 strncpy (f, file, len);
431 f[len] = '\0';
432 bgPixmap.original_asim = get_asimage( asimman, f, 0xFFFFFFFF, 100 );
433 free( f );
434 }
435#endif
436 }
362 437
438 resize_pixmap ();
439}
440
441#endif /* XPM_BACKGROUND */
442#endif /* HAVE_BG_PIXMAP */
443
444#ifdef ENABLE_TRANSPARENCY
445#ifndef HAVE_AFTERIMAGE
446/* taken from aterm-0.4.2 */
447
448typedef uint32_t RUINT32T;
449
450static void
451ShadeXImage(rxvt_term *term, XImage* srcImage, int shade, int rm, int gm, int bm)
452{
453 int sh_r, sh_g, sh_b;
454 RUINT32T mask_r, mask_g, mask_b;
455 RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b;
456 unsigned int lower_lim_r, lower_lim_g, lower_lim_b;
457 unsigned int upper_lim_r, upper_lim_g, upper_lim_b;
458 int i;
459
460 Visual *visual = term->visual;
461
462 if( visual->c_class != TrueColor || srcImage->format != ZPixmap ) return ;
463
464 /* for convenience */
465 mask_r = visual->red_mask;
466 mask_g = visual->green_mask;
467 mask_b = visual->blue_mask;
468
469 /* boring lookup table pre-initialization */
470 switch (srcImage->bits_per_pixel) {
471 case 15:
472 if ((mask_r != 0x7c00) ||
473 (mask_g != 0x03e0) ||
474 (mask_b != 0x001f))
475 return;
476 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+32+32));
477 lookup_r = lookup;
478 lookup_g = lookup+32;
479 lookup_b = lookup+32+32;
480 sh_r = 10;
481 sh_g = 5;
482 sh_b = 0;
483 break;
484 case 16:
485 if ((mask_r != 0xf800) ||
486 (mask_g != 0x07e0) ||
487 (mask_b != 0x001f))
488 return;
489 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+64+32));
490 lookup_r = lookup;
491 lookup_g = lookup+32;
492 lookup_b = lookup+32+64;
493 sh_r = 11;
494 sh_g = 5;
495 sh_b = 0;
496 break;
497 case 24:
498 if ((mask_r != 0xff0000) ||
499 (mask_g != 0x00ff00) ||
500 (mask_b != 0x0000ff))
501 return;
502 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256));
503 lookup_r = lookup;
504 lookup_g = lookup+256;
505 lookup_b = lookup+256+256;
506 sh_r = 16;
507 sh_g = 8;
508 sh_b = 0;
509 break;
510 case 32:
511 if ((mask_r != 0xff0000) ||
512 (mask_g != 0x00ff00) ||
513 (mask_b != 0x0000ff))
514 return;
515 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256));
516 lookup_r = lookup;
517 lookup_g = lookup+256;
518 lookup_b = lookup+256+256;
519 sh_r = 16;
520 sh_g = 8;
521 sh_b = 0;
522 break;
523 default:
524 return; /* we do not support this color depth */
525 }
526
527 /* prepare limits for color transformation (each channel is handled separately) */
528 if (shade < 0) {
529 shade = -shade;
530 if (shade < 0) shade = 0;
531 if (shade > 100) shade = 100;
532
533 lower_lim_r = 65535-rm;
534 lower_lim_g = 65535-gm;
535 lower_lim_b = 65535-bm;
536
537 lower_lim_r = 65535-(unsigned int)(((RUINT32T)lower_lim_r)*((RUINT32T)shade)/100);
538 lower_lim_g = 65535-(unsigned int)(((RUINT32T)lower_lim_g)*((RUINT32T)shade)/100);
539 lower_lim_b = 65535-(unsigned int)(((RUINT32T)lower_lim_b)*((RUINT32T)shade)/100);
540
541 upper_lim_r = upper_lim_g = upper_lim_b = 65535;
542 } else {
543 if (shade < 0) shade = 0;
544 if (shade > 100) shade = 100;
545
546 lower_lim_r = lower_lim_g = lower_lim_b = 0;
547
548 upper_lim_r = (unsigned int)((((RUINT32T)rm)*((RUINT32T)shade))/100);
549 upper_lim_g = (unsigned int)((((RUINT32T)gm)*((RUINT32T)shade))/100);
550 upper_lim_b = (unsigned int)((((RUINT32T)bm)*((RUINT32T)shade))/100);
551 }
552
553 /* switch red and blue bytes if necessary, we need it for some weird XServers like XFree86 3.3.3.1 */
554 if ((srcImage->bits_per_pixel == 24) && (mask_r >= 0xFF0000 ))
555 {
556 unsigned int tmp;
557
558 tmp = lower_lim_r;
559 lower_lim_r = lower_lim_b;
560 lower_lim_b = tmp;
561
562 tmp = upper_lim_r;
563 upper_lim_r = upper_lim_b;
564 upper_lim_b = tmp;
565 }
566
567 /* fill our lookup tables */
568 for (i = 0; i <= mask_r>>sh_r; i++)
569 {
570 RUINT32T tmp;
571 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_r-lower_lim_r));
572 tmp += ((RUINT32T)(mask_r>>sh_r))*((RUINT32T)lower_lim_r);
573 lookup_r[i] = (tmp/65535)<<sh_r;
574 }
575 for (i = 0; i <= mask_g>>sh_g; i++)
576 {
577 RUINT32T tmp;
578 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_g-lower_lim_g));
579 tmp += ((RUINT32T)(mask_g>>sh_g))*((RUINT32T)lower_lim_g);
580 lookup_g[i] = (tmp/65535)<<sh_g;
581 }
582 for (i = 0; i <= mask_b>>sh_b; i++)
583 {
584 RUINT32T tmp;
585 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_b-lower_lim_b));
586 tmp += ((RUINT32T)(mask_b>>sh_b))*((RUINT32T)lower_lim_b);
587 lookup_b[i] = (tmp/65535)<<sh_b;
588 }
589
590 /* apply table to input image (replacing colors by newly calculated ones) */
591 switch (srcImage->bits_per_pixel)
592 {
593 case 15:
594 {
595 unsigned short *p1, *pf, *p, *pl;
596 p1 = (unsigned short *) srcImage->data;
597 pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
598 while (p1 < pf)
599 {
600 p = p1;
601 pl = p1 + srcImage->width;
602 for (; p < pl; p++)
603 {
604 *p = lookup_r[(*p & 0x7c00)>>10] |
605 lookup_g[(*p & 0x03e0)>> 5] |
606 lookup_b[(*p & 0x001f)];
607 }
608 p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line);
609 }
610 break;
611 }
612 case 16:
613 {
614 unsigned short *p1, *pf, *p, *pl;
615 p1 = (unsigned short *) srcImage->data;
616 pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
617 while (p1 < pf)
618 {
619 p = p1;
620 pl = p1 + srcImage->width;
621 for (; p < pl; p++)
622 {
623 *p = lookup_r[(*p & 0xf800)>>11] |
624 lookup_g[(*p & 0x07e0)>> 5] |
625 lookup_b[(*p & 0x001f)];
626 }
627 p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line);
628 }
629 break;
630 }
631 case 24:
632 {
633 unsigned char *p1, *pf, *p, *pl;
634 p1 = (unsigned char *) srcImage->data;
635 pf = (unsigned char *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
636 while (p1 < pf)
637 {
638 p = p1;
639 pl = p1 + srcImage->width * 3;
640 for (; p < pl; p += 3)
641 {
642 p[0] = lookup_r[(p[0] & 0xff0000)>>16];
643 p[1] = lookup_r[(p[1] & 0x00ff00)>> 8];
644 p[2] = lookup_r[(p[2] & 0x0000ff)];
645 }
646 p1 = (unsigned char *) ((char *) p1 + srcImage->bytes_per_line);
647 }
648 break;
649 }
650 case 32:
651 {
652 RUINT32T *p1, *pf, *p, *pl;
653 p1 = (RUINT32T *) srcImage->data;
654 pf = (RUINT32T *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
655
656 while (p1 < pf)
657 {
658 p = p1;
659 pl = p1 + srcImage->width;
660 for (; p < pl; p++)
661 {
662 *p = lookup_r[(*p & 0xff0000)>>16] |
663 lookup_g[(*p & 0x00ff00)>> 8] |
664 lookup_b[(*p & 0x0000ff)] |
665 (*p & ~0xffffff);
666 }
667 p1 = (RUINT32T *) ((char *) p1 + srcImage->bytes_per_line);
668 }
669 break;
670 }
671 }
672
673 free (lookup);
674}
675#endif
676
677/*
678 * Check our parents are still who we think they are.
679 * Do transparency updates if required
680 */
681int
682rxvt_term::check_our_parents ()
683{
684 check_our_parents_ev.stop ();
685 check_our_parents_ev.start (NOW + .1);
686 return 0;
687}
688
689void
690rxvt_term::check_our_parents_cb (time_watcher &w)
691{
692 int i, pchanged, aformat, rootdepth;
693 unsigned long nitems, bytes_after;
694 Atom atype;
695 unsigned char *prop = NULL;
696 Window root, oldp, *list;
697 Pixmap rootpixmap = None;
698 XWindowAttributes wattr, wrootattr;
699 int sx, sy;
700 Window cr;
701 unsigned int rootpixmap_w = 0, rootpixmap_h = 0;
702
703 pchanged = 0;
704
705 if (!option (Opt_transparent))
706 return /*pchanged*/; /* Don't try any more */
707
708#if 0
709 struct timeval stv;
710 gettimeofday (&stv,NULL);
711#define PRINT_BACKGROUND_OP_TIME do{ struct timeval tv;gettimeofday (&tv,NULL); tv.tv_sec-= stv.tv_sec;\
712 fprintf (stderr,"%d: elapsed %ld usec\n",__LINE__,\
713 tv.tv_sec*1000000+tv.tv_usec-stv.tv_usec );}while(0)
714#else
715#define PRINT_BACKGROUND_OP_TIME do{}while(0)
716#endif
717
718
719 XGetWindowAttributes (dpy, display->root, &wrootattr);
720 rootdepth = wrootattr.depth;
721
722 XGetWindowAttributes (dpy, parent[0], &wattr);
723
724 if (rootdepth != wattr.depth)
725 {
726 if (am_transparent)
727 {
728 pchanged = 1;
729 XSetWindowBackground (dpy, vt, pix_colors_focused[Color_bg]);
730 am_transparent = am_pixmap_trans = 0;
731 }
732
733 return /*pchanged*/; /* Don't try any more */
734 }
735
736 /* Get all X ops out of the queue so that our information is up-to-date. */
737 XSync (dpy, False);
738
739 XTranslateCoordinates (dpy, parent[0], display->root,
740 0, 0, &sx, &sy, &cr);
741 /* check if we are outside of the visible part of the virtual screen : */
742 if( sx + (int)szHint.width <= 0 || sy + (int)szHint.height <= 0
743 || sx >= wrootattr.width || sy >= wrootattr.height )
744 return /* 0 */ ;
745 /*
746 * Make the frame window set by the window manager have
747 * the root background. Some window managers put multiple nested frame
748 * windows for each client, so we have to take care about that.
749 */
750 i = (xa[XA_XROOTPMAP_ID]
751 && XGetWindowProperty (dpy, display->root, xa[XA_XROOTPMAP_ID],
752 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
753 &nitems, &bytes_after, &prop) == Success);
754
755 if (!i || prop == NULL)
756 i = (xa[XA_ESETROOT_PMAP_ID]
757 && XGetWindowProperty (dpy, display->root, xa[XA_ESETROOT_PMAP_ID],
758 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
759 &nitems, &bytes_after, &prop) == Success);
760
761 /* TODO: the below logic needs to be cleaned up */
762 if (!i || prop == NULL
763 || (!ISSET_PIXCOLOR (Color_tint) && rs[Rs_shade] == NULL
764#ifdef HAVE_AFTERIMAGE
765 && bgPixmap.original_asim == NULL && rs[Rs_blurradius] == NULL
766#endif
767 )
768 )
769 rootpixmap = None;
770 else
771 {
772 int junk;
773 unsigned int ujunk;
774 /* root pixmap may be bad - allow a error */
775 allowedxerror = -1;
776 if ((rootpixmap = *(Pixmap *)prop) != None)
777 if (!XGetGeometry (dpy, rootpixmap, &root, &junk, &junk, &rootpixmap_w, &rootpixmap_h, &ujunk, &ujunk))
778 rootpixmap = None;
779 allowedxerror = 0;
780 }
781
782 if (prop != NULL)
783 XFree (prop);
784
785 if (rootpixmap != None)
786 {
787 Bool success = False;
788 GC gc = NULL;
789 XGCValues gcvalue;
790 int shade = 100;
791 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
792 Bool whole_tint = False, no_tint = True;
793
794 while (sx < 0) sx += (int)wrootattr.width;
795 while (sy < 0) sy += (int)wrootattr.height;
796
797 if (rs[Rs_shade])
798 shade = atoi (rs[Rs_shade]);
799 if (ISSET_PIXCOLOR (Color_tint))
800 pix_colors_focused [Color_tint].get (c);
801#define IS_COMPONENT_WHOLESOME(c) ((c) <=0x000700 || (c)>=0x00f700)
802 if (shade >= 100)
803 whole_tint = (IS_COMPONENT_WHOLESOME(c.r)
804 && IS_COMPONENT_WHOLESOME(c.g)
805 && IS_COMPONENT_WHOLESOME(c.b));
806 no_tint = (c.r >= 0x00f700 && c.g >= 0x00f700 && c.b >= 0x00f700);
807#undef IS_COMPONENT_WHOLESOME
808 /* theer are no performance advantages to reusing same pixmap */
809 if (bgPixmap.pixmap != None)
810 XFreePixmap (dpy, bgPixmap.pixmap);
811 bgPixmap.pixmap = XCreatePixmap (dpy, vt, szHint.width, szHint.height, rootdepth);
812 bgPixmap.pmap_width = szHint.width;
813 bgPixmap.pmap_height = szHint.height;
814 bgPixmap.pmap_depth = rootdepth;
815
816#if 0 /* TODO : identify cases where this will be detrimental to performance : */
817 /* we want to tile root pixmap into our own pixmap in this cases :
818 * 1) rootpixmap does not cover our window entirely
819 * 2) whole_tint - we can use server-side tinting or tinting disabled
820 */
821 if ( whole_tint || no_tint || pmap_w < sx + szHint.width || pmap_h < sy + szHint.height)
822 {
823 }
824#endif
825 gcvalue.tile = rootpixmap;
826 gcvalue.fill_style = FillTiled;
827 gcvalue.ts_x_origin = -sx;
828 gcvalue.ts_y_origin = -sy;
829 gc = XCreateGC (dpy, rootpixmap, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcvalue);
830 XFillRectangle (dpy, bgPixmap.pixmap, gc, 0, 0, szHint.width, szHint.height);
831
832 if (whole_tint && !no_tint)
833 {
834 /* In this case we can tint image server-side getting significant
835 * performance improvements, as we eliminate XImage transfer
836 */
837 gcvalue.foreground = Pixel (pix_colors_focused [Color_tint]);
838 gcvalue.function = GXand;
839 gcvalue.fill_style = FillSolid;
840 XChangeGC (dpy, gc, GCFillStyle | GCForeground | GCFunction, &gcvalue);
841 XFillRectangle (dpy, bgPixmap.pixmap, gc, 0, 0, szHint.width, szHint.height);
842 }
843 success = True;
844#ifdef HAVE_AFTERIMAGE
845 if (rs[Rs_blurradius] || bgPixmap.original_asim != NULL || (!whole_tint && (!no_tint || shade !=100)))
846 {
847 ARGB32 tint = TINT_LEAVE_SAME;
848 ASImage *back_im = NULL;
849
850 back_im = pixmap2ximage (asv, bgPixmap.pixmap, 0, 0, szHint.width, szHint.height, AllPlanes, 100);
851 if (back_im != NULL)
852 {
853 if (!whole_tint && (!no_tint || shade !=100))
854 {
855 ShadingInfo as_shade;
856 as_shade.shading = shade;
857 as_shade.tintColor.red = c.r;
858 as_shade.tintColor.green = c.g;
859 as_shade.tintColor.blue = c.b;
860 tint = shading2tint32 (&as_shade);
861 }
862
863 if (rs[Rs_blurradius] && back_im)
864 {
865 ASImage* tmp;
866 int junk;
867 unsigned int hr = 1, vr = 1;
868 int flags = XParseGeometry (rs[Rs_blurradius], &junk, &junk, &hr, &vr);
869 if (!(flags&WidthValue))
870 hr = 1;
871 if (!(flags&HeightValue))
872 vr = hr;
873 tmp = blur_asimage_gauss (asv, back_im, hr, vr, 0xFFFFFFFF,
874 (bgPixmap.original_asim == NULL || tint == TINT_LEAVE_SAME)?ASA_XImage:ASA_ASImage,
875 100, ASIMAGE_QUALITY_DEFAULT);
876 if (tmp)
877 {
878 destroy_asimage (&back_im);
879 back_im = tmp;
880 }
881 }
882
883 if (bgPixmap.original_asim != NULL)
884 {
885 ASImageLayer *layers = create_image_layers (2);
886 ASImage *merged_im = NULL;
887 int fore_w, fore_h;
888
889 layers[0].im = back_im;
890 layers[0].clip_width = szHint.width;
891 layers[0].clip_height = szHint.height;
892 layers[0].tint = tint;
893 layers[1].im = bgPixmap.original_asim;
894
895 fore_w = (bgPixmap.h_scale == 0) ? bgPixmap.original_asim->width : bgPixmap.h_scale*szHint.width/100;
896 fore_h = (bgPixmap.v_scale == 0) ? bgPixmap.original_asim->height : bgPixmap.v_scale*szHint.height/100;
897
898 if (fore_w != bgPixmap.original_asim->width
899 || fore_h != bgPixmap.original_asim->height)
900 {
901 layers[1].im = scale_asimage (asv,
902 bgPixmap.original_asim,
903 fore_w, fore_h,
904 ASA_ASImage, 100,
905 ASIMAGE_QUALITY_DEFAULT);
906 }
907 layers[1].clip_width = szHint.width;
908 layers[1].clip_height = szHint.height;
909
910 if (rs[Rs_blendtype])
911 {
912 layers[1].merge_scanlines = blend_scanlines_name2func (rs[Rs_blendtype]);
913 if (layers[1].merge_scanlines == NULL)
914 layers[1].merge_scanlines = alphablend_scanlines;
915 }
916 PRINT_BACKGROUND_OP_TIME;
917 merged_im = merge_layers (asv, layers, 2, szHint.width, szHint.height,
918 ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT);
919 if (layers[1].im != bgPixmap.original_asim)
920 destroy_asimage (&(layers[1].im));
921 free (layers);
922
923 if (merged_im != NULL)
924 {
925 destroy_asimage (&back_im);
926 back_im = merged_im;
927 }
928 PRINT_BACKGROUND_OP_TIME;
929 }
930 else if (tint != TINT_LEAVE_SAME)
931 {
932 ASImage* tmp = tile_asimage (asv, back_im, 0, 0, szHint.width, szHint.height, tint, ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT);
933 if (tmp)
934 {
935 destroy_asimage (&back_im);
936 back_im = tmp;
937 }
938 PRINT_BACKGROUND_OP_TIME;
939 }
940 asimage2drawable (asv, bgPixmap.pixmap, back_im, gc, 0, 0, 0, 0, szHint.width, szHint.height, True);
941 destroy_asimage (&back_im);
942 } /* back_im != NULL */
943 else
944 success = False;
945 }
946#else /* HAVE_AFTERIMAGE */
947 if (!whole_tint && (!no_tint || shade !=100))
948 {
949 XImage *image = XGetImage (dpy, bgPixmap.pixmap, 0, 0, szHint.width, szHint.height, AllPlanes, ZPixmap);
950 success = False;
951 if (image != NULL)
952 {
953 PRINT_BACKGROUND_OP_TIME;
954 if (gc == NULL)
955 gc = XCreateGC (dpy, vt, 0UL, &gcvalue);
956 if (ISSET_PIXCOLOR (Color_tint) || shade != 100)
957 ShadeXImage (this, image, shade, c.r, c.g, c.b);
958 XPutImage (dpy, bgPixmap.pixmap, gc, image, 0, 0, 0, 0, image->width, image->height);
959 XDestroyImage (image);
960 success = True;
961 }
962 }
963#endif /* HAVE_AFTERIMAGE */
964 PRINT_BACKGROUND_OP_TIME;
965
966 if (gc != NULL)
967 XFreeGC (dpy, gc);
968
969 if (!success)
970 {
971 if (am_transparent && am_pixmap_trans)
972 {
973 pchanged = 1;
974 if (bgPixmap.pixmap != None)
975 {
976 XFreePixmap (dpy, bgPixmap.pixmap);
977 bgPixmap.pixmap = None;
978 }
979 }
980
981 am_pixmap_trans = 0;
982 }
983 else
984 {
985 XSetWindowBackgroundPixmap (dpy, parent[0], bgPixmap.pixmap);
986 XClearWindow (dpy, parent[0]);
987
988 if (!am_transparent || !am_pixmap_trans)
989 pchanged = 1;
990
991 am_transparent = am_pixmap_trans = 1;
992 }
993 } /* rootpixmap != None */
994
995 if (am_pixmap_trans)
996 XSetWindowBackgroundPixmap (dpy, vt, ParentRelative);
997 else
998 {
999 unsigned int n;
363 /* 1000 /*
364 * we already have the required attributes 1001 * InheritPixmap transparency
365 */ 1002 */
366 /* XGetWindowAttributes (display->display, TermWin.vt, &attr); */ 1003 for (i = 1; i < (int) (sizeof (parent) / sizeof (Window)); i++)
1004 {
1005 oldp = parent[i];
1006 XQueryTree (dpy, parent[i - 1], &root, &parent[i], &list, &n);
1007 XFree (list);
367 1008
368 xpmAttr.closeness = 30000; 1009 if (parent[i] == display->root)
369 xpmAttr.colormap = display->cmap; 1010 {
370 xpmAttr.visual = display->visual; 1011 if (oldp != None)
371 xpmAttr.depth = display->depth; 1012 pchanged = 1;
372 xpmAttr.valuemask = (XpmCloseness | XpmColormap | XpmVisual |
373 XpmDepth | XpmSize | XpmReturnPixels);
374 1013
375 /* search environment variables here too */ 1014 break;
376 f = (char *)rxvt_File_find (file, ".xpm", rs[Rs_path]); 1015 }
377 if (f == NULL 1016
378 || XpmReadFileToPixmap (display->display, display->root, f, 1017 if (oldp != parent[i])
379 &bgPixmap.pixmap, NULL, 1018 pchanged = 1;
380 &xpmAttr)) 1019 }
1020
1021 n = 0;
1022
1023 if (pchanged)
1024 for (; n < (unsigned int)i; n++)
381 { 1025 {
382 char *p; 1026 XGetWindowAttributes (dpy, parent[n], &wattr);
383 1027
384 /* semi-colon delimited */ 1028 if (wattr.depth != rootdepth || wattr.c_class == InputOnly)
385 if ((p = strchr (file, ';')) == NULL) 1029 {
386 p = strchr (file, '\0'); 1030 n = (int) (sizeof (parent) / sizeof (Window)) + 1;
387 1031 break;
388 rxvt_warn ("couldn't load XPM file \"%.*s\", ignoring.\n", (p - file), file); 1032 }
389 } 1033 }
390 1034
391 free (f); 1035 if (n > (sizeof (parent) / sizeof (parent[0])))
1036 {
1037 XSetWindowBackground (dpy, parent[0], pix_colors_focused[Color_border]);
1038 XSetWindowBackground (dpy, vt, pix_colors_focused[Color_bg]);
1039 am_transparent = 0;
1040 /* XXX: also turn off Opt_transparent? */
1041 }
1042 else
1043 {
1044 for (n = 0; n < (unsigned int)i; n++)
1045 {
1046 XSetWindowBackgroundPixmap (dpy, parent[n], ParentRelative);
1047 XClearWindow (dpy, parent[n]);
1048 }
1049
1050 XSetWindowBackgroundPixmap (dpy, vt, ParentRelative);
1051 am_transparent = 1;
1052 }
1053
1054 for (; i < (int) (sizeof (parent) / sizeof (Window)); i++)
1055 parent[i] = None;
1056 }
1057
1058 if (scrollBar.win)
392 } 1059 {
1060 XSetWindowBackgroundPixmap (dpy, scrollBar.win, ParentRelative);
1061 scrollBar.setIdle ();
1062 scrollbar_show (0);
1063 }
393 1064
394 resize_pixmap (); 1065 if (am_transparent)
395 return bgPixmap.pixmap; 1066 {
1067 want_refresh = want_full_refresh = 1;
1068 if (am_pixmap_trans)
1069 flush ();
1070 }
1071
1072// return pchanged;
396} 1073}
397 1074#endif
398#endif /* XPM_BACKGROUND */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines