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