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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines