1 |
/*----------------------------------------------------------------------* |
2 |
* File: xpm.C |
3 |
*----------------------------------------------------------------------* |
4 |
* |
5 |
* All portions of code are copyright by their respective author/s. |
6 |
* Copyright (c) 1997 Carsten Haitzler <raster@zip.com.au> |
7 |
* Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de> |
8 |
* Copyright (c) 1998-2001 Geoff Wing <gcw@pobox.com> |
9 |
* Copyright (c) 2005-2006 Marc Lehmann <pcg@goof.com> |
10 |
* |
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 |
13 |
* the Free Software Foundation; either version 2 of the License, or |
14 |
* (at your option) any later version. |
15 |
* |
16 |
* This program is distributed in the hope that it will be useful, |
17 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19 |
* GNU General Public License for more details. |
20 |
* |
21 |
* You should have received a copy of the GNU General Public License |
22 |
* along with this program; if not, write to the Free Software |
23 |
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
24 |
*---------------------------------------------------------------------*/ |
25 |
|
26 |
#include "../config.h" /* NECESSARY */ |
27 |
#include "rxvt.h" /* NECESSARY */ |
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 |
{ |
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 |
} |
92 |
|
93 |
#ifdef XPM_BACKGROUND |
94 |
static inline bool |
95 |
check_set_scale_value (int geom_flags, int flag, unsigned int &scale, unsigned int new_value) |
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 |
{ |
131 |
int geom_flags = 0, changed = 0; |
132 |
int x = 0, y = 0; |
133 |
unsigned int w = 0, h = 0; |
134 |
unsigned int n; |
135 |
unsigned long new_flags = (flags&(~bgPmap_geometryFlags)); |
136 |
char *p; |
137 |
#define MAXLEN_GEOM 256 /* could be longer then regular geometry string */ |
138 |
|
139 |
if (geom == NULL) |
140 |
return false; |
141 |
|
142 |
char str[MAXLEN_GEOM]; |
143 |
|
144 |
if (!strcmp (geom, "?")) |
145 |
{ |
146 |
#if 0 /* TODO: */ |
147 |
sprintf (str, "[%dx%d+%d+%d]", /* can't presume snprintf () ! */ |
148 |
min (h_scale, 32767), min (v_scale, 32767), |
149 |
min (h_align, 32767), min (v_align, 32767)); |
150 |
process_xterm_seq (XTerm_title, str, CHAR_ST); |
151 |
#endif |
152 |
return false; |
153 |
} |
154 |
while (isspace(*geom)) ++geom; |
155 |
if ((p = strchr (geom, ';')) == NULL) |
156 |
p = strchr (geom, '\0'); |
157 |
|
158 |
n = (p - geom); |
159 |
if (n < MAXLEN_GEOM) |
160 |
{ |
161 |
char *ops; |
162 |
new_flags |= bgPmap_geometrySet; |
163 |
|
164 |
strncpy (str, geom, n); |
165 |
str[n] = '\0'; |
166 |
if (str[0] == ':') |
167 |
ops = &str[0]; |
168 |
else if (str[0] != 'x' && str[0] != 'X' && isalpha(str[0])) |
169 |
ops = &str[0]; |
170 |
else |
171 |
{ |
172 |
char *tmp; |
173 |
ops = strchr (str, ':'); |
174 |
if (ops != NULL) |
175 |
{ |
176 |
for (tmp = ops-1; tmp >= str && isspace(*tmp); --tmp); |
177 |
*(++tmp) = '\0'; |
178 |
if (ops == tmp) ++ops; |
179 |
} |
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)) |
188 |
{ |
189 |
y = x; |
190 |
geom_flags |= YValue; |
191 |
} |
192 |
|
193 |
if (flags & bgPmap_geometrySet) |
194 |
{/* new geometry is an adjustment to the old one ! */ |
195 |
if ((geom_flags & WidthValue) && (geom_flags & HeightValue)) |
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 */ |
218 |
{ |
219 |
if (!(geom_flags & XValue)) |
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; |
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; |
247 |
|
248 |
if (ops) |
249 |
{ |
250 |
while (*ops) |
251 |
{ |
252 |
while (*ops == ':' || isspace(*ops)) ++ops; |
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; |
258 |
} |
259 |
else if (CHECK_GEOM_OPS("propscale")) |
260 |
{ |
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 */ |
299 |
} |
300 |
|
301 |
if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) |
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 |
} |
310 |
|
311 |
if (new_flags != flags) |
312 |
{ |
313 |
flags = new_flags; |
314 |
changed++; |
315 |
} |
316 |
//fprintf( stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n", |
317 |
// flags, h_scale, v_scale, h_align, v_align); |
318 |
return (changed > 0); |
319 |
} |
320 |
|
321 |
void |
322 |
rxvt_term::resize_pixmap () |
323 |
{ |
324 |
XGCValues gcvalue; |
325 |
GC gc; |
326 |
unsigned int w = bgPixmap.h_scale*szHint.width/100; |
327 |
unsigned int h = bgPixmap.v_scale*szHint.height/100; |
328 |
int x = bgPixmap.h_align*szHint.width/100; |
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 */ |
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) |
351 |
{ /* So be it: I'm not using pixmaps */ |
352 |
XSetWindowBackground (dpy, vt, pix_colors[Color_bg]); |
353 |
return; |
354 |
} |
355 |
|
356 |
gcvalue.foreground = pix_colors[Color_bg]; |
357 |
gc = XCreateGC (dpy, vt, GCForeground, &gcvalue); |
358 |
|
359 |
/* don't zoom pixmap too much nor expand really small pixmaps */ |
360 |
if (w > 16000) |
361 |
w = 1; |
362 |
if (h > 16000) |
363 |
h = 1; |
364 |
|
365 |
#ifdef HAVE_AFTERIMAGE |
366 |
if (w == 0) |
367 |
w = im->width; |
368 |
if (h == 0) |
369 |
h = im->height; |
370 |
|
371 |
if (w != im->width || h != im->height) |
372 |
{ |
373 |
ASImage *tmp = scale_asimage (asv, im, w, h, (x == 0 && y == 0)?ASA_XImage:ASA_ASImage, 0, ASIMAGE_QUALITY_DEFAULT); |
374 |
if (tmp != NULL) |
375 |
im = tmp; |
376 |
} |
377 |
bgPixmap.pmap_width = MIN(w,szHint.width); |
378 |
bgPixmap.pmap_height = MIN(h,szHint.height); |
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) |
384 |
{ |
385 |
if (im != bgPixmap.original_asim) |
386 |
destroy_asimage (&im); |
387 |
im = tmp; |
388 |
} |
389 |
} |
390 |
#endif |
391 |
bgPixmap.pixmap = XCreatePixmap (dpy, vt, bgPixmap.pmap_width, bgPixmap.pmap_height, depth); |
392 |
bgPixmap.pmap_depth = depth; |
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 ) |
400 |
XSetWindowBackgroundPixmap (dpy, vt, bgPixmap.pixmap); |
401 |
|
402 |
XFreeGC (dpy, gc); |
403 |
} |
404 |
|
405 |
void |
406 |
rxvt_term::set_bgPixmap (const char *file) |
407 |
{ |
408 |
char *f; |
409 |
|
410 |
assert (file != NULL); |
411 |
|
412 |
if (bgPixmap.pixmap != None) |
413 |
{ |
414 |
XFreePixmap (dpy, bgPixmap.pixmap); |
415 |
bgPixmap.pixmap = None; |
416 |
} |
417 |
|
418 |
XSetWindowBackground (dpy, vt, pix_colors[Color_bg]); |
419 |
if (*file != '\0') |
420 |
{ |
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 |
} |
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; |
1000 |
/* |
1001 |
* InheritPixmap transparency |
1002 |
*/ |
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); |
1008 |
|
1009 |
if (parent[i] == display->root) |
1010 |
{ |
1011 |
if (oldp != None) |
1012 |
pchanged = 1; |
1013 |
|
1014 |
break; |
1015 |
} |
1016 |
|
1017 |
if (oldp != parent[i]) |
1018 |
pchanged = 1; |
1019 |
} |
1020 |
|
1021 |
n = 0; |
1022 |
|
1023 |
if (pchanged) |
1024 |
for (; n < (unsigned int)i; n++) |
1025 |
{ |
1026 |
XGetWindowAttributes (dpy, parent[n], &wattr); |
1027 |
|
1028 |
if (wattr.depth != rootdepth || wattr.c_class == InputOnly) |
1029 |
{ |
1030 |
n = (int) (sizeof (parent) / sizeof (Window)) + 1; |
1031 |
break; |
1032 |
} |
1033 |
} |
1034 |
|
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) |
1059 |
{ |
1060 |
XSetWindowBackgroundPixmap (dpy, scrollBar.win, ParentRelative); |
1061 |
scrollBar.setIdle (); |
1062 |
scrollbar_show (0); |
1063 |
} |
1064 |
|
1065 |
if (am_transparent) |
1066 |
{ |
1067 |
want_refresh = want_full_refresh = 1; |
1068 |
if (am_pixmap_trans) |
1069 |
flush (); |
1070 |
} |
1071 |
|
1072 |
// return pchanged; |
1073 |
} |
1074 |
#endif |