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. |
… | |
… | |
24 | |
25 | |
25 | #include "../config.h" /* NECESSARY */ |
26 | #include "../config.h" /* NECESSARY */ |
26 | #include "rxvt.h" /* NECESSARY */ |
27 | #include "rxvt.h" /* NECESSARY */ |
27 | |
28 | |
28 | #ifdef XPM_BACKGROUND |
29 | #ifdef XPM_BACKGROUND |
29 | |
|
|
30 | static void rxvt_pixmap_incr (unsigned int *wh, unsigned int *xy, float *incr, float *p, unsigned int widthheight, unsigned int xpmwidthheight); |
|
|
31 | |
30 | |
32 | /* |
31 | /* |
33 | * These GEOM strings indicate absolute size/position: |
32 | * These GEOM strings indicate absolute size/position: |
34 | * @ `WxH+X+Y' |
33 | * @ `WxH+X+Y' |
35 | * @ `WxH+X' -> Y = X |
34 | * @ `WxH+X' -> Y = X |
… | |
… | |
55 | int flags, changed = 0; |
54 | int flags, changed = 0; |
56 | int x = 0, y = 0; |
55 | int x = 0, y = 0; |
57 | unsigned int w = 0, h = 0; |
56 | unsigned int w = 0, h = 0; |
58 | unsigned int n; |
57 | unsigned int n; |
59 | char *p; |
58 | char *p; |
60 | bgPixmap_t *bgpixmap = & (bgPixmap); |
59 | bgPixmap_t *bgpixmap = &bgPixmap; |
61 | |
60 | |
62 | #define MAXLEN_GEOM sizeof("[10000x10000+10000+10000]") |
61 | #define MAXLEN_GEOM sizeof("[10000x10000+10000+10000]") |
63 | |
62 | |
64 | if (geom == NULL) |
63 | if (geom == NULL) |
65 | return 0; |
64 | return 0; |
… | |
… | |
77 | |
76 | |
78 | if ((p = strchr (geom, ';')) == NULL) |
77 | if ((p = strchr (geom, ';')) == NULL) |
79 | p = strchr (geom, '\0'); |
78 | p = strchr (geom, '\0'); |
80 | |
79 | |
81 | n = (p - geom); |
80 | n = (p - geom); |
82 | if (n <= MAXLEN_GEOM) |
81 | if (n < MAXLEN_GEOM) |
83 | { |
82 | { |
84 | strncpy (str, geom, n); |
83 | strncpy (str, geom, n); |
85 | str[n] = '\0'; |
84 | str[n] = '\0'; |
86 | |
85 | |
|
|
86 | if (strcmp(str, "auto") == 0) |
|
|
87 | { |
|
|
88 | if (!bgpixmap->auto_resize) |
|
|
89 | changed++; |
|
|
90 | bgpixmap->auto_resize = True ; |
|
|
91 | w = szHint.width ; |
|
|
92 | h = szHint.height ; |
|
|
93 | flags = WidthValue|HeightValue ; |
|
|
94 | } |
|
|
95 | else |
|
|
96 | { |
|
|
97 | bgpixmap->auto_resize = False ; |
87 | flags = XParseGeometry (str, &x, &y, &w, &h); |
98 | flags = XParseGeometry (str, &x, &y, &w, &h); |
88 | |
99 | } |
|
|
100 | /* code below is garbage and needs to be rewritten */ |
89 | if (!flags) |
101 | if (!flags) |
90 | { |
102 | { |
91 | flags |= WidthValue; |
103 | flags |= WidthValue; |
92 | w = 0; |
104 | w = 0; |
93 | } /* default is tile */ |
105 | } /* default is tile */ |
… | |
… | |
139 | { |
151 | { |
140 | x += bgpixmap->x; |
152 | x += bgpixmap->x; |
141 | y += bgpixmap->y; |
153 | y += bgpixmap->y; |
142 | } |
154 | } |
143 | |
155 | |
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) |
156 | if (bgpixmap->x != x) |
151 | { |
157 | { |
152 | bgpixmap->x = x; |
158 | bgpixmap->x = x; |
153 | changed++; |
159 | changed++; |
154 | } |
160 | } |
… | |
… | |
166 | void |
172 | void |
167 | rxvt_term::resize_pixmap () |
173 | rxvt_term::resize_pixmap () |
168 | { |
174 | { |
169 | XGCValues gcvalue; |
175 | XGCValues gcvalue; |
170 | GC gc; |
176 | GC gc; |
|
|
177 | unsigned int w = bgPixmap.w, h = bgPixmap.h; |
|
|
178 | unsigned int x = bgPixmap.x, y = bgPixmap.y; |
|
|
179 | ASImage *im = bgPixmap.original_asim; |
171 | |
180 | |
172 | if (pixmap != None) |
181 | /* preliminary cleanup - this needs to be integrated with check_our_parents() code */ |
173 | XFreePixmap (xdisp, pixmap); |
|
|
174 | |
|
|
175 | if (bgPixmap.pixmap == None) |
182 | if (bgPixmap.pixmap != None) |
|
|
183 | { |
|
|
184 | XFreePixmap (dpy, bgPixmap.pixmap); |
|
|
185 | bgPixmap.pixmap = None ; |
|
|
186 | } |
|
|
187 | #ifdef ENABLE_TRANSPARENCY |
|
|
188 | if (option(Opt_transparent) && am_transparent) |
|
|
189 | { |
|
|
190 | /* we need to re-generate transparency pixmap in that case ! */ |
|
|
191 | check_our_parents (); |
|
|
192 | return; |
|
|
193 | } |
|
|
194 | #endif |
|
|
195 | |
|
|
196 | if (bgPixmap.original_asim == NULL) |
176 | { /* So be it: I'm not using pixmaps */ |
197 | { /* 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]); |
198 | XSetWindowBackground (dpy, vt, pix_colors[Color_bg]); |
181 | |
|
|
182 | return; |
199 | return; |
183 | } |
200 | } |
184 | |
201 | |
185 | gcvalue.foreground = pix_colors[Color_bg]; |
202 | gcvalue.foreground = pix_colors[Color_bg]; |
186 | gc = XCreateGC (xdisp, vt, GCForeground, &gcvalue); |
203 | gc = XCreateGC (dpy, vt, GCForeground, &gcvalue); |
187 | |
204 | |
188 | if (bgPixmap.pixmap != None) |
205 | if (bgPixmap.auto_resize) |
189 | { /* we have a specified pixmap */ |
206 | { |
190 | unsigned int w = bgPixmap.w, h = bgPixmap.h, |
207 | w = szHint.width; |
191 | x = bgPixmap.x, y = bgPixmap.y; |
208 | h = szHint.height; |
192 | unsigned int xpmh = xpmAttr.height, |
209 | } |
193 | xpmw = xpmAttr.width; |
210 | else |
194 | |
|
|
195 | /* |
|
|
196 | * don't zoom pixmap too much nor expand really small pixmaps |
211 | { /* don't zoom pixmap too much nor expand really small pixmaps */ |
197 | */ |
212 | if (w > 16000) |
198 | if (w > 32767 || h > 32767) |
|
|
199 | w = 1; |
213 | w = 1; |
200 | else if (width > (10 * xpmw) |
214 | if (h > 16000) |
201 | || height > (10 * xpmh)) |
215 | h = 1; |
202 | w = 0; /* tile */ |
216 | } |
|
|
217 | if (w == 0) w = im->width; |
|
|
218 | else if (w < 10) w *= im->width; |
|
|
219 | if (h == 0) h = im->height; |
|
|
220 | else if (w < 10) h *= im->height; |
203 | |
221 | |
204 | if (!w) |
222 | if (w != im->width || h != im->height) |
205 | { |
223 | { |
206 | /* basic X tiling - let the X server do it */ |
224 | 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); |
225 | if (tmp != NULL) |
208 | |
226 | im = tmp; |
209 | XCopyArea (xdisp, bgPixmap.pixmap, pixmap, gc, x, y, xpmw - x, xpmh - y, 0, 0); |
227 | } |
210 | XCopyArea (xdisp, bgPixmap.pixmap, pixmap, gc, x, 0, xpmw - x, y, 0, xpmh - y); |
228 | if (x != 0 || y != 0) |
211 | XCopyArea (xdisp, bgPixmap.pixmap, pixmap, gc, 0, y, x, xpmh - y, xpmw - x, 0); |
229 | { |
212 | XCopyArea (xdisp, bgPixmap.pixmap, pixmap, gc, 0, 0, x, y, xpmw - x, xpmh - y); |
230 | ASImage *tmp = tile_asimage (asv, im, x, y, w, h, TINT_LEAVE_SAME, ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT); |
|
|
231 | if (tmp != NULL) |
213 | } |
232 | { |
214 | else |
233 | if (im != bgPixmap.original_asim) |
|
|
234 | destroy_asimage (&im); |
|
|
235 | im = tmp; |
215 | { |
236 | } |
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 | } |
237 | } |
|
|
238 | bgPixmap.pixmap = XCreatePixmap (dpy, vt, w, h, depth); |
|
|
239 | bgPixmap.pmap_width = w; |
|
|
240 | bgPixmap.pmap_height = h; |
|
|
241 | bgPixmap.pmap_depth = depth; |
260 | |
242 | |
|
|
243 | asimage2drawable (asv, bgPixmap.pixmap, im, gc, 0, 0, 0, 0, w, h, True); |
|
|
244 | |
|
|
245 | if (im != bgPixmap.original_asim) |
|
|
246 | destroy_asimage (&im); |
|
|
247 | |
261 | XSetWindowBackgroundPixmap (xdisp, vt, pixmap); |
248 | XSetWindowBackgroundPixmap (dpy, vt, bgPixmap.pixmap); |
262 | |
249 | |
263 | if (pixmap != None) |
|
|
264 | { |
|
|
265 | XFreePixmap (xdisp, pixmap); |
|
|
266 | pixmap = None; |
|
|
267 | } |
|
|
268 | |
|
|
269 | XFreeGC (xdisp, gc); |
250 | XFreeGC (dpy, gc); |
270 | am_transparent = 0; |
|
|
271 | } |
251 | } |
272 | |
252 | |
273 | /* |
253 | void |
274 | * Calculate tiling sizes and increments |
|
|
275 | * At start, p == 0, incr == xpmwidthheight |
|
|
276 | */ |
|
|
277 | static void |
|
|
278 | rxvt_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 | |
|
|
349 | Pixmap |
|
|
350 | rxvt_term::set_bgPixmap (const char *file) |
254 | rxvt_term::set_bgPixmap (const char *file) |
351 | { |
255 | { |
352 | char *f; |
256 | char *f; |
353 | |
257 | |
354 | assert (file != NULL); |
258 | assert (file != NULL); |
355 | |
259 | |
356 | if (bgPixmap.pixmap != None) |
260 | if (bgPixmap.pixmap != None) |
357 | { |
261 | { |
358 | XFreePixmap (display->display, bgPixmap.pixmap); |
262 | XFreePixmap (dpy, bgPixmap.pixmap); |
359 | bgPixmap.pixmap = None; |
263 | bgPixmap.pixmap = None; |
360 | } |
264 | } |
361 | |
265 | |
362 | XSetWindowBackground (display->display, vt, pix_colors[Color_bg]); |
266 | XSetWindowBackground (dpy, vt, pix_colors[Color_bg]); |
363 | |
267 | |
364 | if (*file != '\0') |
268 | if (*file != '\0') |
365 | { |
269 | { |
366 | /* XWindowAttributes attr; */ |
270 | if (asimman == NULL) |
|
|
271 | asimman = create_generic_imageman(rs[Rs_path]); |
|
|
272 | if ((f = strchr (file, ';')) == NULL) |
|
|
273 | bgPixmap.original_asim = get_asimage( asimman, file, 0xFFFFFFFF, 100 ); |
|
|
274 | else |
|
|
275 | { |
|
|
276 | size_t len = f - file; |
|
|
277 | f = (char *)malloc (len + 1); |
|
|
278 | strncpy (f, file, len); |
|
|
279 | f[len] = '\0'; |
|
|
280 | bgPixmap.original_asim = get_asimage( asimman, f, 0xFFFFFFFF, 100 ); |
|
|
281 | free( f ); |
|
|
282 | } |
|
|
283 | } |
367 | |
284 | |
|
|
285 | resize_pixmap (); |
|
|
286 | } |
|
|
287 | |
|
|
288 | #endif /* XPM_BACKGROUND */ |
|
|
289 | |
|
|
290 | #ifdef ENABLE_TRANSPARENCY |
|
|
291 | #if TINTING && !defined(HAVE_AFTERIMAGE) |
|
|
292 | /* taken from aterm-0.4.2 */ |
|
|
293 | |
|
|
294 | typedef uint32_t RUINT32T; |
|
|
295 | |
|
|
296 | static void |
|
|
297 | ShadeXImage(rxvt_term *term, XImage* srcImage, int shade, int rm, int gm, int bm) |
|
|
298 | { |
|
|
299 | int sh_r, sh_g, sh_b; |
|
|
300 | RUINT32T mask_r, mask_g, mask_b; |
|
|
301 | RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b; |
|
|
302 | unsigned int lower_lim_r, lower_lim_g, lower_lim_b; |
|
|
303 | unsigned int upper_lim_r, upper_lim_g, upper_lim_b; |
|
|
304 | int i; |
|
|
305 | |
|
|
306 | Visual *visual = term->visual; |
|
|
307 | |
|
|
308 | if( visual->c_class != TrueColor || srcImage->format != ZPixmap ) return ; |
|
|
309 | |
|
|
310 | /* for convenience */ |
|
|
311 | mask_r = visual->red_mask; |
|
|
312 | mask_g = visual->green_mask; |
|
|
313 | mask_b = visual->blue_mask; |
|
|
314 | |
|
|
315 | /* boring lookup table pre-initialization */ |
|
|
316 | switch (srcImage->bits_per_pixel) { |
|
|
317 | case 15: |
|
|
318 | if ((mask_r != 0x7c00) || |
|
|
319 | (mask_g != 0x03e0) || |
|
|
320 | (mask_b != 0x001f)) |
|
|
321 | return; |
|
|
322 | lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+32+32)); |
|
|
323 | lookup_r = lookup; |
|
|
324 | lookup_g = lookup+32; |
|
|
325 | lookup_b = lookup+32+32; |
|
|
326 | sh_r = 10; |
|
|
327 | sh_g = 5; |
|
|
328 | sh_b = 0; |
|
|
329 | break; |
|
|
330 | case 16: |
|
|
331 | if ((mask_r != 0xf800) || |
|
|
332 | (mask_g != 0x07e0) || |
|
|
333 | (mask_b != 0x001f)) |
|
|
334 | return; |
|
|
335 | lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+64+32)); |
|
|
336 | lookup_r = lookup; |
|
|
337 | lookup_g = lookup+32; |
|
|
338 | lookup_b = lookup+32+64; |
|
|
339 | sh_r = 11; |
|
|
340 | sh_g = 5; |
|
|
341 | sh_b = 0; |
|
|
342 | break; |
|
|
343 | case 24: |
|
|
344 | if ((mask_r != 0xff0000) || |
|
|
345 | (mask_g != 0x00ff00) || |
|
|
346 | (mask_b != 0x0000ff)) |
|
|
347 | return; |
|
|
348 | lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256)); |
|
|
349 | lookup_r = lookup; |
|
|
350 | lookup_g = lookup+256; |
|
|
351 | lookup_b = lookup+256+256; |
|
|
352 | sh_r = 16; |
|
|
353 | sh_g = 8; |
|
|
354 | sh_b = 0; |
|
|
355 | break; |
|
|
356 | case 32: |
|
|
357 | if ((mask_r != 0xff0000) || |
|
|
358 | (mask_g != 0x00ff00) || |
|
|
359 | (mask_b != 0x0000ff)) |
|
|
360 | return; |
|
|
361 | lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256)); |
|
|
362 | lookup_r = lookup; |
|
|
363 | lookup_g = lookup+256; |
|
|
364 | lookup_b = lookup+256+256; |
|
|
365 | sh_r = 16; |
|
|
366 | sh_g = 8; |
|
|
367 | sh_b = 0; |
|
|
368 | break; |
|
|
369 | default: |
|
|
370 | return; /* we do not support this color depth */ |
|
|
371 | } |
|
|
372 | |
|
|
373 | /* prepare limits for color transformation (each channel is handled separately) */ |
|
|
374 | if (shade < 0) { |
|
|
375 | shade = -shade; |
|
|
376 | if (shade < 0) shade = 0; |
|
|
377 | if (shade > 100) shade = 100; |
|
|
378 | |
|
|
379 | lower_lim_r = 65535-rm; |
|
|
380 | lower_lim_g = 65535-gm; |
|
|
381 | lower_lim_b = 65535-bm; |
|
|
382 | |
|
|
383 | lower_lim_r = 65535-(unsigned int)(((RUINT32T)lower_lim_r)*((RUINT32T)shade)/100); |
|
|
384 | lower_lim_g = 65535-(unsigned int)(((RUINT32T)lower_lim_g)*((RUINT32T)shade)/100); |
|
|
385 | lower_lim_b = 65535-(unsigned int)(((RUINT32T)lower_lim_b)*((RUINT32T)shade)/100); |
|
|
386 | |
|
|
387 | upper_lim_r = upper_lim_g = upper_lim_b = 65535; |
|
|
388 | } else { |
|
|
389 | if (shade < 0) shade = 0; |
|
|
390 | if (shade > 100) shade = 100; |
|
|
391 | |
|
|
392 | lower_lim_r = lower_lim_g = lower_lim_b = 0; |
|
|
393 | |
|
|
394 | upper_lim_r = (unsigned int)((((RUINT32T)rm)*((RUINT32T)shade))/100); |
|
|
395 | upper_lim_g = (unsigned int)((((RUINT32T)gm)*((RUINT32T)shade))/100); |
|
|
396 | upper_lim_b = (unsigned int)((((RUINT32T)bm)*((RUINT32T)shade))/100); |
|
|
397 | } |
|
|
398 | |
|
|
399 | /* switch red and blue bytes if necessary, we need it for some weird XServers like XFree86 3.3.3.1 */ |
|
|
400 | if ((srcImage->bits_per_pixel == 24) && (mask_r >= 0xFF0000 )) |
|
|
401 | { |
|
|
402 | unsigned int tmp; |
|
|
403 | |
|
|
404 | tmp = lower_lim_r; |
|
|
405 | lower_lim_r = lower_lim_b; |
|
|
406 | lower_lim_b = tmp; |
|
|
407 | |
|
|
408 | tmp = upper_lim_r; |
|
|
409 | upper_lim_r = upper_lim_b; |
|
|
410 | upper_lim_b = tmp; |
|
|
411 | } |
|
|
412 | |
|
|
413 | /* fill our lookup tables */ |
|
|
414 | for (i = 0; i <= mask_r>>sh_r; i++) |
|
|
415 | { |
|
|
416 | RUINT32T tmp; |
|
|
417 | tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_r-lower_lim_r)); |
|
|
418 | tmp += ((RUINT32T)(mask_r>>sh_r))*((RUINT32T)lower_lim_r); |
|
|
419 | lookup_r[i] = (tmp/65535)<<sh_r; |
|
|
420 | } |
|
|
421 | for (i = 0; i <= mask_g>>sh_g; i++) |
|
|
422 | { |
|
|
423 | RUINT32T tmp; |
|
|
424 | tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_g-lower_lim_g)); |
|
|
425 | tmp += ((RUINT32T)(mask_g>>sh_g))*((RUINT32T)lower_lim_g); |
|
|
426 | lookup_g[i] = (tmp/65535)<<sh_g; |
|
|
427 | } |
|
|
428 | for (i = 0; i <= mask_b>>sh_b; i++) |
|
|
429 | { |
|
|
430 | RUINT32T tmp; |
|
|
431 | tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_b-lower_lim_b)); |
|
|
432 | tmp += ((RUINT32T)(mask_b>>sh_b))*((RUINT32T)lower_lim_b); |
|
|
433 | lookup_b[i] = (tmp/65535)<<sh_b; |
|
|
434 | } |
|
|
435 | |
|
|
436 | /* apply table to input image (replacing colors by newly calculated ones) */ |
|
|
437 | switch (srcImage->bits_per_pixel) |
|
|
438 | { |
|
|
439 | case 15: |
|
|
440 | { |
|
|
441 | unsigned short *p1, *pf, *p, *pl; |
|
|
442 | p1 = (unsigned short *) srcImage->data; |
|
|
443 | pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line); |
|
|
444 | while (p1 < pf) |
|
|
445 | { |
|
|
446 | p = p1; |
|
|
447 | pl = p1 + srcImage->width; |
|
|
448 | for (; p < pl; p++) |
|
|
449 | { |
|
|
450 | *p = lookup_r[(*p & 0x7c00)>>10] | |
|
|
451 | lookup_g[(*p & 0x03e0)>> 5] | |
|
|
452 | lookup_b[(*p & 0x001f)]; |
|
|
453 | } |
|
|
454 | p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line); |
|
|
455 | } |
|
|
456 | break; |
|
|
457 | } |
|
|
458 | case 16: |
|
|
459 | { |
|
|
460 | unsigned short *p1, *pf, *p, *pl; |
|
|
461 | p1 = (unsigned short *) srcImage->data; |
|
|
462 | pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line); |
|
|
463 | while (p1 < pf) |
|
|
464 | { |
|
|
465 | p = p1; |
|
|
466 | pl = p1 + srcImage->width; |
|
|
467 | for (; p < pl; p++) |
|
|
468 | { |
|
|
469 | *p = lookup_r[(*p & 0xf800)>>11] | |
|
|
470 | lookup_g[(*p & 0x07e0)>> 5] | |
|
|
471 | lookup_b[(*p & 0x001f)]; |
|
|
472 | } |
|
|
473 | p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line); |
|
|
474 | } |
|
|
475 | break; |
|
|
476 | } |
|
|
477 | case 24: |
|
|
478 | { |
|
|
479 | unsigned char *p1, *pf, *p, *pl; |
|
|
480 | p1 = (unsigned char *) srcImage->data; |
|
|
481 | pf = (unsigned char *) (srcImage->data + srcImage->height * srcImage->bytes_per_line); |
|
|
482 | while (p1 < pf) |
|
|
483 | { |
|
|
484 | p = p1; |
|
|
485 | pl = p1 + srcImage->width * 3; |
|
|
486 | for (; p < pl; p += 3) |
|
|
487 | { |
|
|
488 | p[0] = lookup_r[(p[0] & 0xff0000)>>16]; |
|
|
489 | p[1] = lookup_r[(p[1] & 0x00ff00)>> 8]; |
|
|
490 | p[2] = lookup_r[(p[2] & 0x0000ff)]; |
|
|
491 | } |
|
|
492 | p1 = (unsigned char *) ((char *) p1 + srcImage->bytes_per_line); |
|
|
493 | } |
|
|
494 | break; |
|
|
495 | } |
|
|
496 | case 32: |
|
|
497 | { |
|
|
498 | RUINT32T *p1, *pf, *p, *pl; |
|
|
499 | p1 = (RUINT32T *) srcImage->data; |
|
|
500 | pf = (RUINT32T *) (srcImage->data + srcImage->height * srcImage->bytes_per_line); |
|
|
501 | |
|
|
502 | while (p1 < pf) |
|
|
503 | { |
|
|
504 | p = p1; |
|
|
505 | pl = p1 + srcImage->width; |
|
|
506 | for (; p < pl; p++) |
|
|
507 | { |
|
|
508 | *p = lookup_r[(*p & 0xff0000)>>16] | |
|
|
509 | lookup_g[(*p & 0x00ff00)>> 8] | |
|
|
510 | lookup_b[(*p & 0x0000ff)] | |
|
|
511 | (*p & ~0xffffff); |
|
|
512 | } |
|
|
513 | p1 = (RUINT32T *) ((char *) p1 + srcImage->bytes_per_line); |
|
|
514 | } |
|
|
515 | break; |
|
|
516 | } |
|
|
517 | } |
|
|
518 | |
|
|
519 | free (lookup); |
|
|
520 | } |
|
|
521 | #endif |
|
|
522 | |
|
|
523 | /* |
|
|
524 | * Check our parents are still who we think they are. |
|
|
525 | * Do transparency updates if required |
|
|
526 | */ |
|
|
527 | int |
|
|
528 | rxvt_term::check_our_parents () |
|
|
529 | { |
|
|
530 | check_our_parents_ev.stop (); |
|
|
531 | check_our_parents_ev.start (NOW + .1); |
|
|
532 | return 0; |
|
|
533 | } |
|
|
534 | |
|
|
535 | void |
|
|
536 | rxvt_term::check_our_parents_cb (time_watcher &w) |
|
|
537 | { |
|
|
538 | int i, pchanged, aformat, rootdepth; |
|
|
539 | unsigned long nitems, bytes_after; |
|
|
540 | Atom atype; |
|
|
541 | unsigned char *prop = NULL; |
|
|
542 | Window root, oldp, *list; |
|
|
543 | Pixmap rootpixmap = None; |
|
|
544 | XWindowAttributes wattr, wrootattr; |
|
|
545 | int sx, sy; |
|
|
546 | Window cr; |
|
|
547 | unsigned int rootpixmap_w = 0, rootpixmap_h = 0; |
|
|
548 | |
|
|
549 | pchanged = 0; |
|
|
550 | |
|
|
551 | if (!option (Opt_transparent)) |
|
|
552 | return /*pchanged*/; /* Don't try any more */ |
|
|
553 | |
|
|
554 | #if 0 |
|
|
555 | struct timeval stv; |
|
|
556 | gettimeofday (&stv,NULL); |
|
|
557 | #define PRINT_BACKGROUND_OP_TIME do{ struct timeval tv;gettimeofday (&tv,NULL); tv.tv_sec-= stv.tv_sec;\ |
|
|
558 | fprintf (stderr,"%d: elapsed %ld usec\n",__LINE__,\ |
|
|
559 | tv.tv_sec*1000000+tv.tv_usec-stv.tv_usec );}while(0) |
|
|
560 | #else |
|
|
561 | #define PRINT_BACKGROUND_OP_TIME do{}while(0) |
|
|
562 | #endif |
|
|
563 | |
|
|
564 | |
|
|
565 | XGetWindowAttributes (dpy, display->root, &wrootattr); |
|
|
566 | rootdepth = wrootattr.depth; |
|
|
567 | |
|
|
568 | XGetWindowAttributes (dpy, parent[0], &wattr); |
|
|
569 | |
|
|
570 | if (rootdepth != wattr.depth) |
|
|
571 | { |
|
|
572 | if (am_transparent) |
|
|
573 | { |
|
|
574 | pchanged = 1; |
|
|
575 | XSetWindowBackground (dpy, vt, pix_colors_focused[Color_bg]); |
|
|
576 | am_transparent = am_pixmap_trans = 0; |
|
|
577 | } |
|
|
578 | |
|
|
579 | return /*pchanged*/; /* Don't try any more */ |
|
|
580 | } |
|
|
581 | |
|
|
582 | /* Get all X ops out of the queue so that our information is up-to-date. */ |
|
|
583 | XSync (dpy, False); |
|
|
584 | |
|
|
585 | XTranslateCoordinates (dpy, parent[0], display->root, |
|
|
586 | 0, 0, &sx, &sy, &cr); |
|
|
587 | /* check if we are outside of the visible part of the virtual screen : */ |
|
|
588 | if( sx + (int)szHint.width <= 0 || sy + (int)szHint.height <= 0 |
|
|
589 | || sx >= wrootattr.width || sy >= wrootattr.height ) |
|
|
590 | return /* 0 */ ; |
|
|
591 | /* |
|
|
592 | * Make the frame window set by the window manager have |
|
|
593 | * the root background. Some window managers put multiple nested frame |
|
|
594 | * windows for each client, so we have to take care about that. |
|
|
595 | */ |
|
|
596 | i = (xa[XA_XROOTPMAP_ID] |
|
|
597 | && XGetWindowProperty (dpy, display->root, xa[XA_XROOTPMAP_ID], |
|
|
598 | 0L, 1L, False, XA_PIXMAP, &atype, &aformat, |
|
|
599 | &nitems, &bytes_after, &prop) == Success); |
|
|
600 | |
|
|
601 | if (!i || prop == NULL) |
|
|
602 | i = (xa[XA_ESETROOT_PMAP_ID] |
|
|
603 | && XGetWindowProperty (dpy, display->root, xa[XA_ESETROOT_PMAP_ID], |
|
|
604 | 0L, 1L, False, XA_PIXMAP, &atype, &aformat, |
|
|
605 | &nitems, &bytes_after, &prop) == Success); |
|
|
606 | |
|
|
607 | /* TODO: the below logic needs to be cleaned up */ |
|
|
608 | if (!i || prop == NULL |
|
|
609 | #if TINTING |
|
|
610 | || (!ISSET_PIXCOLOR (Color_tint) && rs[Rs_shade] == NULL |
|
|
611 | #ifdef HAVE_AFTERIMAGE |
|
|
612 | && bgPixmap.original_asim == NULL && rs[Rs_blurradius] == NULL |
|
|
613 | #endif |
|
|
614 | ) |
|
|
615 | #endif |
|
|
616 | ) |
|
|
617 | rootpixmap = None; |
|
|
618 | else |
|
|
619 | { |
|
|
620 | int junk; |
|
|
621 | unsigned int ujunk; |
|
|
622 | /* root pixmap may be bad - allow a error */ |
|
|
623 | allowedxerror = -1; |
|
|
624 | if ((rootpixmap = *(Pixmap *)prop) != None) |
|
|
625 | if (!XGetGeometry (dpy, rootpixmap, &root, &junk, &junk, &rootpixmap_w, &rootpixmap_h, &ujunk, &ujunk)) |
|
|
626 | rootpixmap = None; |
|
|
627 | allowedxerror = 0; |
|
|
628 | } |
|
|
629 | |
|
|
630 | if (prop != NULL) |
|
|
631 | XFree (prop); |
|
|
632 | |
|
|
633 | if (rootpixmap != None) |
|
|
634 | { |
|
|
635 | Bool success = False; |
|
|
636 | GC gc = NULL; |
|
|
637 | XGCValues gcvalue; |
|
|
638 | int shade = 100; |
|
|
639 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
|
|
640 | Bool whole_tint = False, no_tint = True; |
|
|
641 | |
|
|
642 | while (sx < 0) sx += (int)wrootattr.width; |
|
|
643 | while (sy < 0) sy += (int)wrootattr.height; |
|
|
644 | |
|
|
645 | #if TINTING |
|
|
646 | if (rs[Rs_shade]) |
|
|
647 | shade = atoi (rs[Rs_shade]); |
|
|
648 | if (ISSET_PIXCOLOR (Color_tint)) |
|
|
649 | pix_colors_focused [Color_tint].get (c); |
|
|
650 | #define IS_COMPONENT_WHOLESOME(c) ((c) <=0x000700 || (c)>=0x00f700) |
|
|
651 | if (shade >= 100) |
|
|
652 | whole_tint = (IS_COMPONENT_WHOLESOME(c.r) |
|
|
653 | && IS_COMPONENT_WHOLESOME(c.g) |
|
|
654 | && IS_COMPONENT_WHOLESOME(c.b)); |
|
|
655 | no_tint = (c.r >= 0x00f700 && c.g >= 0x00f700 && c.b >= 0x00f700); |
|
|
656 | #undef IS_COMPONENT_WHOLESOME |
|
|
657 | #endif /* TINTING */ |
|
|
658 | /* theer are no performance advantages to reusing same pixmap */ |
|
|
659 | if (bgPixmap.pixmap != None) |
|
|
660 | XFreePixmap (dpy, bgPixmap.pixmap); |
|
|
661 | bgPixmap.pixmap = XCreatePixmap (dpy, vt, szHint.width, szHint.height, rootdepth); |
|
|
662 | bgPixmap.pmap_width = szHint.width; |
|
|
663 | bgPixmap.pmap_height = szHint.height; |
|
|
664 | bgPixmap.pmap_depth = rootdepth; |
|
|
665 | |
|
|
666 | #if 0 /* TODO : identify cases where this will be detrimental to performance : */ |
|
|
667 | /* we want to tile root pixmap into our own pixmap in this cases : |
|
|
668 | * 1) rootpixmap does not cover our window entirely |
|
|
669 | * 2) whole_tint - we can use server-side tinting or tinting disabled |
|
|
670 | */ |
|
|
671 | if ( whole_tint || no_tint || pmap_w < sx + szHint.width || pmap_h < sy + szHint.height) |
|
|
672 | { |
|
|
673 | } |
|
|
674 | #endif |
|
|
675 | gcvalue.tile = rootpixmap; |
|
|
676 | gcvalue.fill_style = FillTiled; |
|
|
677 | gcvalue.ts_x_origin = -sx; |
|
|
678 | gcvalue.ts_y_origin = -sy; |
|
|
679 | gc = XCreateGC (dpy, rootpixmap, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcvalue); |
|
|
680 | XFillRectangle (dpy, bgPixmap.pixmap, gc, 0, 0, szHint.width, szHint.height); |
|
|
681 | |
|
|
682 | #if TINTING |
|
|
683 | if (whole_tint && !no_tint) |
|
|
684 | { |
|
|
685 | /* In this case we can tint image server-side getting significant |
|
|
686 | * performance improvements, as we eliminate XImage transfer |
|
|
687 | */ |
|
|
688 | gcvalue.foreground = Pixel (pix_colors_focused [Color_tint]); |
|
|
689 | gcvalue.function = GXand; |
|
|
690 | gcvalue.fill_style = FillSolid; |
|
|
691 | XChangeGC (dpy, gc, GCFillStyle | GCForeground | GCFunction, &gcvalue); |
|
|
692 | XFillRectangle (dpy, bgPixmap.pixmap, gc, 0, 0, szHint.width, szHint.height); |
|
|
693 | } |
|
|
694 | #endif |
|
|
695 | success = True; |
|
|
696 | #ifdef HAVE_AFTERIMAGE |
|
|
697 | if (rs[Rs_blurradius] || bgPixmap.original_asim != NULL || (!whole_tint && (!no_tint || shade !=100))) |
|
|
698 | { |
|
|
699 | ARGB32 tint = TINT_LEAVE_SAME; |
|
|
700 | ASImage *back_im = NULL; |
|
|
701 | |
|
|
702 | back_im = pixmap2ximage (asv, bgPixmap.pixmap, 0, 0, szHint.width, szHint.height, AllPlanes, 100); |
|
|
703 | if (back_im != NULL) |
|
|
704 | { |
|
|
705 | if (!whole_tint && (!no_tint || shade !=100)) |
|
|
706 | { |
|
|
707 | ShadingInfo as_shade; |
|
|
708 | as_shade.shading = shade; |
|
|
709 | as_shade.tintColor.red = c.r; |
|
|
710 | as_shade.tintColor.green = c.g; |
|
|
711 | as_shade.tintColor.blue = c.b; |
|
|
712 | tint = shading2tint32 (&as_shade); |
|
|
713 | } |
|
|
714 | |
|
|
715 | if (rs[Rs_blurradius] && back_im) |
|
|
716 | { |
|
|
717 | ASImage* tmp; |
|
|
718 | int junk; |
|
|
719 | unsigned int hr = 1, vr = 1; |
|
|
720 | int flags = XParseGeometry (rs[Rs_blurradius], &junk, &junk, &hr, &vr); |
|
|
721 | if (!(flags&WidthValue)) |
|
|
722 | hr = 1; |
|
|
723 | if (!(flags&HeightValue)) |
|
|
724 | vr = hr; |
|
|
725 | tmp = blur_asimage_gauss (asv, back_im, hr, vr, 0xFFFFFFFF, |
|
|
726 | (bgPixmap.original_asim == NULL || tint == TINT_LEAVE_SAME)?ASA_XImage:ASA_ASImage, |
|
|
727 | 100, ASIMAGE_QUALITY_DEFAULT); |
|
|
728 | if (tmp) |
|
|
729 | { |
|
|
730 | destroy_asimage (&back_im); |
|
|
731 | back_im = tmp; |
|
|
732 | } |
|
|
733 | } |
|
|
734 | |
|
|
735 | if (bgPixmap.original_asim != NULL) |
|
|
736 | { |
|
|
737 | ASImageLayer *layers = create_image_layers (2); |
|
|
738 | ASImage *merged_im = NULL; |
|
|
739 | int fore_w, fore_h; |
|
|
740 | |
|
|
741 | layers[0].im = back_im; |
|
|
742 | layers[0].clip_width = szHint.width; |
|
|
743 | layers[0].clip_height = szHint.height; |
|
|
744 | layers[0].tint = tint; |
|
|
745 | layers[1].im = bgPixmap.original_asim; |
|
|
746 | if (bgPixmap.auto_resize) |
|
|
747 | { |
|
|
748 | fore_w = szHint.width; |
|
|
749 | fore_h = szHint.height; |
|
|
750 | } |
|
|
751 | else |
|
|
752 | { |
|
|
753 | fore_w = (bgPixmap.w == 0) ? bgPixmap.original_asim->width : bgPixmap.w; |
|
|
754 | fore_h = (bgPixmap.h == 0) ? bgPixmap.original_asim->height : bgPixmap.h; |
|
|
755 | } |
|
|
756 | if (fore_w != bgPixmap.original_asim->width |
|
|
757 | || fore_h != bgPixmap.original_asim->height) |
|
|
758 | { |
|
|
759 | layers[1].im = scale_asimage (asv, |
|
|
760 | bgPixmap.original_asim, |
|
|
761 | fore_w, fore_h, |
|
|
762 | ASA_ASImage, 100, |
|
|
763 | ASIMAGE_QUALITY_DEFAULT); |
|
|
764 | } |
|
|
765 | layers[1].clip_width = szHint.width; |
|
|
766 | layers[1].clip_height = szHint.height; |
|
|
767 | |
|
|
768 | if (rs[Rs_blendtype]) |
|
|
769 | { |
|
|
770 | layers[1].merge_scanlines = blend_scanlines_name2func (rs[Rs_blendtype]); |
|
|
771 | if (layers[1].merge_scanlines == NULL) |
|
|
772 | layers[1].merge_scanlines = alphablend_scanlines; |
|
|
773 | } |
|
|
774 | PRINT_BACKGROUND_OP_TIME; |
|
|
775 | merged_im = merge_layers (asv, layers, 2, szHint.width, szHint.height, |
|
|
776 | ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT); |
|
|
777 | if (layers[1].im != bgPixmap.original_asim) |
|
|
778 | destroy_asimage (&(layers[1].im)); |
|
|
779 | free (layers); |
|
|
780 | |
|
|
781 | if (merged_im != NULL) |
|
|
782 | { |
|
|
783 | destroy_asimage (&back_im); |
|
|
784 | back_im = merged_im; |
|
|
785 | } |
|
|
786 | PRINT_BACKGROUND_OP_TIME; |
|
|
787 | } |
|
|
788 | else if (tint != TINT_LEAVE_SAME) |
|
|
789 | { |
|
|
790 | ASImage* tmp = tile_asimage (asv, back_im, 0, 0, szHint.width, szHint.height, tint, ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT); |
|
|
791 | if (tmp) |
|
|
792 | { |
|
|
793 | destroy_asimage (&back_im); |
|
|
794 | back_im = tmp; |
|
|
795 | } |
|
|
796 | PRINT_BACKGROUND_OP_TIME; |
|
|
797 | } |
|
|
798 | asimage2drawable (asv, bgPixmap.pixmap, back_im, gc, 0, 0, 0, 0, szHint.width, szHint.height, True); |
|
|
799 | destroy_asimage (&back_im); |
|
|
800 | } /* back_im != NULL */ |
|
|
801 | else |
|
|
802 | success = False; |
|
|
803 | } |
|
|
804 | #else /* HAVE_AFTERIMAGE */ |
|
|
805 | #if TINTING |
|
|
806 | if (!whole_tint && (!no_tint || shade !=100)) |
|
|
807 | { |
|
|
808 | XImage *image = XGetImage (dpy, bgPixmap.pixmap, 0, 0, szHint.width, szHint.height, AllPlanes, ZPixmap); |
|
|
809 | success = False; |
|
|
810 | if (image != NULL) |
|
|
811 | { |
|
|
812 | PRINT_BACKGROUND_OP_TIME; |
|
|
813 | if (gc == NULL) |
|
|
814 | gc = XCreateGC (dpy, vt, 0UL, &gcvalue); |
|
|
815 | if (ISSET_PIXCOLOR (Color_tint) || shade != 100) |
|
|
816 | ShadeXImage (this, image, shade, c.r, c.g, c.b); |
|
|
817 | XPutImage (dpy, bgPixmap.pixmap, gc, image, 0, 0, 0, 0, image->width, image->height); |
|
|
818 | XDestroyImage (image); |
|
|
819 | success = True; |
|
|
820 | } |
|
|
821 | } |
|
|
822 | #endif |
|
|
823 | #endif /* HAVE_AFTERIMAGE */ |
|
|
824 | PRINT_BACKGROUND_OP_TIME; |
|
|
825 | |
|
|
826 | if (gc != NULL) |
|
|
827 | XFreeGC (dpy, gc); |
|
|
828 | |
|
|
829 | if (!success) |
|
|
830 | { |
|
|
831 | if (am_transparent && am_pixmap_trans) |
|
|
832 | { |
|
|
833 | pchanged = 1; |
|
|
834 | if (bgPixmap.pixmap != None) |
|
|
835 | { |
|
|
836 | XFreePixmap (dpy, bgPixmap.pixmap); |
|
|
837 | bgPixmap.pixmap = None; |
|
|
838 | } |
|
|
839 | } |
|
|
840 | |
|
|
841 | am_pixmap_trans = 0; |
|
|
842 | } |
|
|
843 | else |
|
|
844 | { |
|
|
845 | XSetWindowBackgroundPixmap (dpy, parent[0], bgPixmap.pixmap); |
|
|
846 | XClearWindow (dpy, parent[0]); |
|
|
847 | |
|
|
848 | if (!am_transparent || !am_pixmap_trans) |
|
|
849 | pchanged = 1; |
|
|
850 | |
|
|
851 | am_transparent = am_pixmap_trans = 1; |
|
|
852 | } |
|
|
853 | } /* rootpixmap != None */ |
|
|
854 | |
|
|
855 | if (am_pixmap_trans) |
|
|
856 | XSetWindowBackgroundPixmap (dpy, vt, ParentRelative); |
|
|
857 | else |
|
|
858 | { |
|
|
859 | unsigned int n; |
368 | /* |
860 | /* |
369 | * we already have the required attributes |
861 | * InheritPixmap transparency |
370 | */ |
862 | */ |
371 | /* XGetWindowAttributes (display->display, vt, &attr); */ |
863 | for (i = 1; i < (int) (sizeof (parent) / sizeof (Window)); i++) |
|
|
864 | { |
|
|
865 | oldp = parent[i]; |
|
|
866 | XQueryTree (dpy, parent[i - 1], &root, &parent[i], &list, &n); |
|
|
867 | XFree (list); |
372 | |
868 | |
373 | xpmAttr.closeness = 30000; |
869 | if (parent[i] == display->root) |
374 | xpmAttr.colormap = cmap; |
870 | { |
375 | xpmAttr.visual = visual; |
871 | if (oldp != None) |
376 | xpmAttr.depth = depth; |
872 | pchanged = 1; |
377 | xpmAttr.valuemask = (XpmCloseness | XpmColormap | XpmVisual |
|
|
378 | | XpmDepth | XpmSize | XpmReturnPixels); |
|
|
379 | |
873 | |
380 | /* search environment variables here too */ |
874 | break; |
381 | f = (char *)rxvt_File_find (file, ".xpm", rs[Rs_path]); |
875 | } |
382 | if (f == NULL |
876 | |
383 | || XpmReadFileToPixmap (display->display, display->root, f, |
877 | if (oldp != parent[i]) |
384 | &bgPixmap.pixmap, NULL, |
878 | pchanged = 1; |
385 | &xpmAttr)) |
879 | } |
|
|
880 | |
|
|
881 | n = 0; |
|
|
882 | |
|
|
883 | if (pchanged) |
|
|
884 | for (; n < (unsigned int)i; n++) |
386 | { |
885 | { |
387 | char *p; |
886 | XGetWindowAttributes (dpy, parent[n], &wattr); |
388 | |
887 | |
389 | /* semi-colon delimited */ |
888 | if (wattr.depth != rootdepth || wattr.c_class == InputOnly) |
390 | if ((p = strchr (file, ';')) == NULL) |
889 | { |
391 | p = strchr (file, '\0'); |
890 | n = (int) (sizeof (parent) / sizeof (Window)) + 1; |
392 | |
891 | break; |
393 | rxvt_warn ("couldn't load XPM file \"%.*s\", ignoring.\n", (p - file), file); |
892 | } |
394 | } |
893 | } |
395 | |
894 | |
396 | free (f); |
895 | if (n > (sizeof (parent) / sizeof (parent[0]))) |
|
|
896 | { |
|
|
897 | XSetWindowBackground (dpy, parent[0], pix_colors_focused[Color_border]); |
|
|
898 | XSetWindowBackground (dpy, vt, pix_colors_focused[Color_bg]); |
|
|
899 | am_transparent = 0; |
|
|
900 | /* XXX: also turn off Opt_transparent? */ |
|
|
901 | } |
|
|
902 | else |
|
|
903 | { |
|
|
904 | for (n = 0; n < (unsigned int)i; n++) |
|
|
905 | { |
|
|
906 | XSetWindowBackgroundPixmap (dpy, parent[n], ParentRelative); |
|
|
907 | XClearWindow (dpy, parent[n]); |
|
|
908 | } |
|
|
909 | |
|
|
910 | XSetWindowBackgroundPixmap (dpy, vt, ParentRelative); |
|
|
911 | am_transparent = 1; |
|
|
912 | } |
|
|
913 | |
|
|
914 | for (; i < (int) (sizeof (parent) / sizeof (Window)); i++) |
|
|
915 | parent[i] = None; |
|
|
916 | } |
|
|
917 | |
|
|
918 | if (scrollBar.win) |
397 | } |
919 | { |
|
|
920 | XSetWindowBackgroundPixmap (dpy, scrollBar.win, ParentRelative); |
|
|
921 | scrollBar.setIdle (); |
|
|
922 | scrollbar_show (0); |
|
|
923 | } |
398 | |
924 | |
399 | resize_pixmap (); |
925 | if (am_transparent) |
400 | return bgPixmap.pixmap; |
926 | { |
|
|
927 | want_refresh = want_full_refresh = 1; |
|
|
928 | if (am_pixmap_trans) |
|
|
929 | flush (); |
|
|
930 | } |
|
|
931 | |
|
|
932 | // return pchanged; |
401 | } |
933 | } |
402 | |
934 | #endif |
403 | #endif /* XPM_BACKGROUND */ |
|
|