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