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