ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/background.C
(Generate patch)

Comparing rxvt-unicode/src/background.C (file contents):
Revision 1.15 by sasha, Mon Nov 19 15:50:46 2007 UTC vs.
Revision 1.60 by sf-exg, Sun Oct 3 20:41:32 2010 UTC

1/*----------------------------------------------------------------------* 1/*----------------------------------------------------------------------*
2 * File: background.C - former xpm.C 2 * File: background.C - former 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) 2005-2006 Marc Lehmann <pcg@goof.com> 6 * Copyright (c) 2005-2008 Marc Lehmann <pcg@goof.com>
7 * Copyright (c) 2007 Sasha Vasko <sasha@aftercode.net> 7 * Copyright (c) 2007 Sasha Vasko <sasha@aftercode.net>
8 * 8 *
9 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by 10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or 11 * the Free Software Foundation; either version 2 of the License, or
25#include "rxvt.h" /* NECESSARY */ 25#include "rxvt.h" /* NECESSARY */
26 26
27#define DO_TIMING_TEST 0 27#define DO_TIMING_TEST 0
28 28
29#if DO_TIMING_TEST 29#if DO_TIMING_TEST
30# include <sys/time.h>
30#define TIMING_TEST_START(id) \ 31#define TIMING_TEST_START(id) \
31 struct timeval timing_test_##id##_stv;\ 32 struct timeval timing_test_##id##_stv; \
32 gettimeofday (&timing_test_##id##_stv, NULL); 33 gettimeofday (&timing_test_##id##_stv, NULL);
33 34
34#define TIMING_TEST_PRINT_RESULT(id) \ 35#define TIMING_TEST_PRINT_RESULT(id) \
35 do{ struct timeval tv;gettimeofday (&tv, NULL); tv.tv_sec -= (timing_test_##id##_stv).tv_sec;\ 36 do { \
37 struct timeval tv; \
38 gettimeofday (&tv, NULL); \
39 tv.tv_sec -= (timing_test_##id##_stv).tv_sec; \
36 fprintf (stderr, "%s: %s: %d: elapsed %ld usec\n", #id, __FILE__, __LINE__,\ 40 fprintf (stderr, "%s: %s: %d: elapsed %ld usec\n", #id, __FILE__, __LINE__, \
37 tv.tv_sec * 1000000 + tv.tv_usec - (timing_test_##id##_stv).tv_usec);}while (0) 41 tv.tv_sec * 1000000 + tv.tv_usec - (timing_test_##id##_stv).tv_usec); \
42 } while (0)
38 43
39#else 44#else
40#define TIMING_TEST_START(id) do{}while (0) 45#define TIMING_TEST_START(id) do {} while (0)
41#define TIMING_TEST_PRINT_RESULT(id) do{}while (0) 46#define TIMING_TEST_PRINT_RESULT(id) do {} while (0)
42#endif 47#endif
43 48
44/* 49/*
45 * Pixmap geometry string interpretation : 50 * Pixmap geometry string interpretation :
46 * Each geometry string contains zero or one scale/position 51 * Each geometry string contains zero or one scale/position
47 * adjustment and may optionally be followed by a colon and one or more 52 * adjustment and may optionally be followed by a colon and one or more
48 * colon-delimited pixmap operations. 53 * colon-delimited pixmap operations.
49 * The following table shows the valid geometry strings and their 54 * The following table shows the valid geometry strings and their
50 * affects on the background image : 55 * effects on the background image :
51 * 56 *
52 * WxH+X+Y Set scaling to W% by H%, and position to X% by Y%. 57 * WxH+X+Y Set scaling to W% by H%, and position to X% by Y%.
53 * W and H are percentages of the terminal window size. 58 * W and H are percentages of the terminal window size.
54 * X and Y are also percentages; e.g., +50+50 centers 59 * X and Y are also percentages; e.g., +50+50 centers
55 * the image in the window. 60 * the image in the window.
56 * WxH+X Assumes Y == X 61 * WxH+X Assumes Y == X
57 * WxH Assumes Y == X == 50 (centers the image) 62 * WxH Assumes Y == X == 50 (centers the image)
58 * W+X+Y Assumes H == W 63 * W+X+Y Assumes H == W
59 * W+X Assumes H == W and Y == X 64 * W+X Assumes H == W and Y == X
60 * W Assumes H == W and Y == X == 50 65 * W Assumes H == W and Y == X == 50
61 * 66 *
62 * Adjusting position only : 67 * Adjusting position only :
63 * =+X+Y Set position to X% by Y% (absolute). 68 * =+X+Y Set position to X% by Y% (absolute).
64 * =+X Set position to X% by X%. 69 * =+X Set position to X% by X%.
65 * +X+Y Adjust position horizontally X% and vertically Y% 70 * +X+Y Adjust position horizontally X% and vertically Y%
66 * from current position (relative). 71 * from current position (relative).
67 * +X Adjust position horizontally X% and vertically X% 72 * +X Adjust position horizontally X% and vertically X%
68 * from current position. 73 * from current position.
69 * 74 *
70 * Adjusting scale only : 75 * Adjusting scale only :
71 * Wx0 Multiply horizontal scaling factor by W% 76 * Wx0 Multiply horizontal scaling factor by W%
72 * 0xH Multiply vertical scaling factor by H% 77 * 0xH Multiply vertical scaling factor by H%
73 * 0x0 No scaling (show image at normal size). 78 * 0x0 No scaling (show image at normal size).
74 * 79 *
75 * Pixmap Operations : (should be prepended by a colon) 80 * Pixmap Operations : (should be prepended by a colon)
76 * tile Tile image. Scaling/position modifiers above will affect 81 * tile Tile image. Scaling/position modifiers above will affect
77 * the tile size and origin. 82 * the tile size and origin.
78 * propscale When scaling, scale proportionally. That is, maintain the 83 * propscale When scaling, scale proportionally. That is, maintain the
79 * proper aspect ratio for the image. Any portion of the 84 * proper aspect ratio for the image. Any portion of the
80 * background not covered by the image is filled with the 85 * background not covered by the image is filled with the
81 * current background color. 86 * current background color.
82 * hscale Scale horizontally, tile vertically ? 87 * hscale Scale horizontally, tile vertically ?
83 * vscale Tile horizontally, scale vertically ? 88 * vscale Tile horizontally, scale vertically ?
86 */ 91 */
87 92
88#ifdef HAVE_BG_PIXMAP 93#ifdef HAVE_BG_PIXMAP
89bgPixmap_t::bgPixmap_t () 94bgPixmap_t::bgPixmap_t ()
90{ 95{
96 // this is basically redundant as bgPixmap_t is only used in
97 // zero_initialised-derived structs
91#ifdef HAVE_AFTERIMAGE 98#ifdef HAVE_AFTERIMAGE
92 original_asim = NULL; 99 original_asim = NULL;
93#endif 100#endif
101#ifdef HAVE_PIXBUF
102 pixbuf = NULL;
103#endif
94#ifdef BG_IMAGE_FROM_FILE 104#ifdef BG_IMAGE_FROM_FILE
105 have_image = false;
95 h_scale = v_scale = 0; 106 h_scale = v_scale = 0;
96 h_align = v_align = 0; 107 h_align = v_align = 0;
97#endif 108#endif
98 flags = 0; 109 flags = 0;
99 pixmap = None; 110 pixmap = None;
111 valid_since = invalid_since = 0;
112 target = 0;
100} 113}
101 114
102void 115void
103bgPixmap_t::destroy () 116bgPixmap_t::destroy ()
104{ 117{
105#ifdef HAVE_AFTERIMAGE 118#ifdef HAVE_AFTERIMAGE
106 if (original_asim) 119 if (original_asim)
107 safe_asimage_destroy (original_asim); 120 safe_asimage_destroy (original_asim);
108#endif 121#endif
109 122
123#ifdef HAVE_PIXBUF
124 if (pixbuf)
125 g_object_unref (pixbuf);
126#endif
127
110 if (pixmap && target) 128 if (pixmap && target)
111 XFreePixmap (target->dpy, pixmap); 129 XFreePixmap (target->dpy, pixmap);
112} 130}
113 131
114bool 132bool
118 if (flags & isTransparent) 136 if (flags & isTransparent)
119 return true; 137 return true;
120# endif 138# endif
121 139
122# ifdef BG_IMAGE_FROM_FILE 140# ifdef BG_IMAGE_FROM_FILE
123# ifdef HAVE_AFTERIMAGE 141 if (have_image)
124 if (original_asim != NULL)
125# endif
126 { 142 {
127 if (h_scale != 0 || v_scale != 0 143 if (h_scale != 0 || v_scale != 0
128 || h_align != 0 || v_align != 0) 144 || h_align != 0 || v_align != 0)
129 return true; 145 return true;
130 } 146 }
131# endif 147# endif
132 148
133 return false; 149 return false;
134} 150}
135 151
136bool 152bool
137bgPixmap_t::window_position_sensitive () 153bgPixmap_t::window_position_sensitive ()
138{ 154{
139# ifdef ENABLE_TRANSPARENCY 155# ifdef ENABLE_TRANSPARENCY
140 if (flags & isTransparent) 156 if (flags & isTransparent)
141 return true; 157 return true;
142# endif 158# endif
143 159
144# ifdef BG_IMAGE_FROM_FILE 160# ifdef BG_IMAGE_FROM_FILE
145# ifdef HAVE_AFTERIMAGE 161 if (have_image)
146 if (original_asim != NULL)
147# endif
148 { 162 {
149 if (h_align == rootAlign || v_align == rootAlign) 163 if (h_align == rootAlign || v_align == rootAlign)
150 return true; 164 return true;
151 } 165 }
152# endif 166# endif
155}; 169};
156 170
157bool bgPixmap_t::need_client_side_rendering () 171bool bgPixmap_t::need_client_side_rendering ()
158{ 172{
159# ifdef HAVE_AFTERIMAGE 173# ifdef HAVE_AFTERIMAGE
160 if (original_asim != NULL) 174 if (original_asim)
161 return true; 175 return true;
162# endif 176# endif
163# ifdef ENABLE_TRANSPARENCY 177# ifdef ENABLE_TRANSPARENCY
164 if (flags & isTransparent) 178 if (flags & isTransparent)
165 { 179 {
214 228
215static inline int 229static inline int
216make_align_position (int align, int window_size, int image_size) 230make_align_position (int align, int window_size, int image_size)
217{ 231{
218 int diff = window_size - image_size; 232 int diff = window_size - image_size;
219 int smaller = MIN (image_size,window_size); 233 int smaller = min (image_size, window_size);
220 234
221 if (align >= 0 && align <= 50) 235 if (align >= 0 && align <= 50)
222 return diff * align / 100; 236 return diff * align / 100;
223 else if (align > 50 && align <= 100) 237 else if (align > 50 && align <= 100)
224 return window_size - image_size - diff * (100 - align) / 100; 238 return window_size - image_size - diff * (100 - align) / 100;
233make_clip_rectangle (int pos, int size, int target_size, int &dst_pos, int &dst_size) 247make_clip_rectangle (int pos, int size, int target_size, int &dst_pos, int &dst_size)
234{ 248{
235 int src_pos = 0; 249 int src_pos = 0;
236 dst_pos = 0; 250 dst_pos = 0;
237 dst_size = size; 251 dst_size = size;
238 if (pos < 0 && size > target_size) 252 if (pos < 0)
239 { 253 {
240 src_pos = -pos; 254 src_pos = -pos;
241 dst_size += pos; 255 dst_size += pos;
242 } 256 }
243 else if (pos > 0) 257 else if (pos > 0)
254 int geom_flags = 0, changed = 0; 268 int geom_flags = 0, changed = 0;
255 int x = 0, y = 0; 269 int x = 0, y = 0;
256 unsigned int w = 0, h = 0; 270 unsigned int w = 0, h = 0;
257 unsigned int n; 271 unsigned int n;
258 unsigned long new_flags = (flags & (~geometryFlags)); 272 unsigned long new_flags = (flags & (~geometryFlags));
259 char *p; 273 const char *p;
260# define MAXLEN_GEOM 256 /* could be longer then regular geometry string */ 274# define MAXLEN_GEOM 256 /* could be longer than regular geometry string */
261 275
262 if (geom == NULL) 276 if (geom == NULL)
263 return false; 277 return false;
264 278
265 char str[MAXLEN_GEOM]; 279 char str[MAXLEN_GEOM];
272 if (n < MAXLEN_GEOM) 286 if (n < MAXLEN_GEOM)
273 { 287 {
274 char *ops; 288 char *ops;
275 new_flags |= geometrySet; 289 new_flags |= geometrySet;
276 290
277 strncpy (str, geom, n); 291 memcpy (str, geom, n);
278 str[n] = '\0'; 292 str[n] = '\0';
279 if (str[0] == ':') 293 if (str[0] == ':')
280 ops = &str[0]; 294 ops = &str[0];
281 else if (str[0] != 'x' && str[0] != 'X' && isalpha(str[0])) 295 else if (str[0] != 'x' && str[0] != 'X' && isalpha(str[0]))
282 ops = &str[0]; 296 ops = &str[0];
302 y = x; 316 y = x;
303 geom_flags |= YValue; 317 geom_flags |= YValue;
304 } 318 }
305 319
306 if (flags & geometrySet) 320 if (flags & geometrySet)
321 {
307 {/* new geometry is an adjustment to the old one ! */ 322 /* new geometry is an adjustment to the old one ! */
308 if ((geom_flags & WidthValue) && (geom_flags & HeightValue)) 323 if ((geom_flags & WidthValue) && (geom_flags & HeightValue))
309 { 324 {
310 if (w == 0 && h != 0) 325 if (w == 0 && h != 0)
311 { 326 {
312 w = h_scale; 327 w = h_scale;
328 } 343 }
329 } 344 }
330 else /* setting up geometry from scratch */ 345 else /* setting up geometry from scratch */
331 { 346 {
332 if (!(geom_flags & XValue)) 347 if (!(geom_flags & XValue))
348 {
333 {/* use default geometry - centered */ 349 /* use default geometry - centered */
334 x = y = defaultAlign; 350 x = y = defaultAlign;
335 } 351 }
336 else if (!(geom_flags & YValue)) 352 else if (!(geom_flags & YValue))
337 y = x; 353 y = x;
338 354
339 if ((geom_flags & (WidthValue|HeightValue)) == 0) 355 if ((geom_flags & (WidthValue|HeightValue)) == 0)
356 {
340 {/* use default geometry - scaled */ 357 /* use default geometry - scaled */
341 w = h = defaultScale; 358 w = h = defaultScale;
342 } 359 }
343 else if (geom_flags & WidthValue) 360 else if (geom_flags & WidthValue)
344 { 361 {
345 if (!(geom_flags & HeightValue)) 362 if (!(geom_flags & HeightValue))
348 else 365 else
349 w = h; 366 w = h;
350 } 367 }
351 } /* done parsing geometry string */ 368 } /* done parsing geometry string */
352 else if (!(flags & geometrySet)) 369 else if (!(flags & geometrySet))
370 {
353 { /* default geometry - scaled and centered */ 371 /* default geometry - scaled and centered */
354 x = y = defaultAlign; 372 x = y = defaultAlign;
355 w = h = defaultScale; 373 w = h = defaultScale;
356 } 374 }
357 375
358 if (!(flags & geometrySet)) 376 if (!(flags & geometrySet))
361 if (ops) 379 if (ops)
362 { 380 {
363 while (*ops) 381 while (*ops)
364 { 382 {
365 while (*ops == ':' || isspace(*ops)) ++ops; 383 while (*ops == ':' || isspace(*ops)) ++ops;
384
366# define CHECK_GEOM_OPS(op_str) (strncasecmp (ops, (op_str), sizeof(op_str)-1) == 0) 385# define CHECK_GEOM_OPS(op_str) (strncasecmp (ops, (op_str), sizeof (op_str) - 1) == 0)
367 if (CHECK_GEOM_OPS("tile")) 386 if (CHECK_GEOM_OPS ("tile"))
368 { 387 {
369 w = h = noScale; 388 w = h = noScale;
370 geom_flags |= WidthValue|HeightValue; 389 geom_flags |= WidthValue|HeightValue;
371 } 390 }
372 else if (CHECK_GEOM_OPS("propscale")) 391 else if (CHECK_GEOM_OPS ("propscale"))
373 { 392 {
374 if (w == 0 && h == 0) 393 if (w == 0 && h == 0)
375 { 394 {
376 w = windowScale; 395 w = windowScale;
377 geom_flags |= WidthValue; 396 geom_flags |= WidthValue;
378 } 397 }
379 new_flags |= propScale; 398 new_flags |= propScale;
380 } 399 }
381 else if (CHECK_GEOM_OPS("hscale")) 400 else if (CHECK_GEOM_OPS ("hscale"))
382 { 401 {
383 if (w == 0)
384 w = windowScale; 402 if (w == 0) w = windowScale;
403
385 h = noScale; 404 h = noScale;
386 geom_flags |= WidthValue|HeightValue; 405 geom_flags |= WidthValue|HeightValue;
387 } 406 }
388 else if (CHECK_GEOM_OPS("vscale")) 407 else if (CHECK_GEOM_OPS ("vscale"))
389 { 408 {
390 if (h == 0)
391 h = windowScale; 409 if (h == 0) h = windowScale;
410
392 w = noScale; 411 w = noScale;
393 geom_flags |= WidthValue|HeightValue; 412 geom_flags |= WidthValue|HeightValue;
394 } 413 }
395 else if (CHECK_GEOM_OPS("scale")) 414 else if (CHECK_GEOM_OPS ("scale"))
396 { 415 {
397 if (h == 0)
398 h = windowScale; 416 if (h == 0) h = windowScale;
399 if (w == 0)
400 w = windowScale; 417 if (w == 0) w = windowScale;
418
401 geom_flags |= WidthValue|HeightValue; 419 geom_flags |= WidthValue|HeightValue;
402 } 420 }
403 else if (CHECK_GEOM_OPS("auto")) 421 else if (CHECK_GEOM_OPS ("auto"))
404 { 422 {
405 w = h = windowScale; 423 w = h = windowScale;
406 x = y = centerAlign; 424 x = y = centerAlign;
407 geom_flags |= WidthValue|HeightValue|XValue|YValue; 425 geom_flags |= WidthValue|HeightValue|XValue|YValue;
408 } 426 }
409 else if (CHECK_GEOM_OPS("root")) 427 else if (CHECK_GEOM_OPS ("root"))
410 { 428 {
411 w = h = noScale; 429 w = h = noScale;
412 x = y = rootAlign; 430 x = y = rootAlign;
413 geom_flags |= WidthValue|HeightValue|XValue|YValue; 431 geom_flags |= WidthValue|HeightValue|XValue|YValue;
414 } 432 }
415# undef CHECK_GEOM_OPS 433# undef CHECK_GEOM_OPS
434
416 while (*ops != ':' && *ops != '\0') ++ops; 435 while (*ops != ':' && *ops != '\0') ++ops;
417 } /* done parsing ops */ 436 } /* done parsing ops */
418 } 437 }
419 438
420 if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) 439 if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) ++changed;
421 ++changed;
422 if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) 440 if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) ++changed;
423 ++changed;
424 if (check_set_align_value (geom_flags, XValue, h_align, x)) 441 if (check_set_align_value (geom_flags, XValue, h_align, x)) ++changed;
425 ++changed;
426 if (check_set_align_value (geom_flags, YValue, v_align, y)) 442 if (check_set_align_value (geom_flags, YValue, v_align, y)) ++changed;
427 ++changed;
428 } 443 }
429 444
430 if (new_flags != flags) 445 if (new_flags != flags)
431 { 446 {
432 flags = new_flags; 447 flags = new_flags;
433 changed++; 448 changed++;
434 } 449 }
450
435//fprintf( stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n", 451 //fprintf (stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n",
436// flags, h_scale, v_scale, h_align, v_align); 452 // flags, h_scale, v_scale, h_align, v_align);
437 return (changed > 0); 453 return (changed > 0);
454}
455
456void
457bgPixmap_t::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y)
458{
459 int target_width = target->szHint.width;
460 int target_height = target->szHint.height;
461
462 w = h_scale * target_width / 100;
463 h = v_scale * target_height / 100;
464
465 if (h_align == rootAlign || v_align == rootAlign)
466 {
467 target->get_window_origin (x, y);
468 x = -x;
469 y = -y;
470 }
471
472 if (h_align != rootAlign)
473 x = make_align_position (h_align, target_width, w > 0 ? w : image_width);
474
475 if (v_align != rootAlign)
476 y = make_align_position (v_align, target_height, h > 0 ? h : image_height);
438} 477}
439 478
440# ifdef HAVE_AFTERIMAGE 479# ifdef HAVE_AFTERIMAGE
441bool 480bool
442bgPixmap_t::render_asim (ASImage *background, ARGB32 background_tint) 481bgPixmap_t::render_image (unsigned long background_flags)
443{ 482{
444 if (target == NULL) 483 if (target == NULL)
445 return false; 484 return false;
446 485
486 target->init_asv ();
487
488 ASImage *background = NULL;
489 ARGB32 background_tint = TINT_LEAVE_SAME;
490
491# ifdef ENABLE_TRANSPARENCY
492 if (background_flags)
493 background = pixmap2ximage (target->asv, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, 100);
494
495 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded))
496 {
497 ShadingInfo as_shade;
498 as_shade.shading = (shade == 0) ? 100 : shade;
499
500 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
501 if (flags & tintSet)
502 tint.get (c);
503 as_shade.tintColor.red = c.r;
504 as_shade.tintColor.green = c.g;
505 as_shade.tintColor.blue = c.b;
506
507 background_tint = shading2tint32 (&as_shade);
508 }
509
510 if (!(background_flags & transpPmapBlured) && (flags & blurNeeded) && background != NULL)
511 {
512 ASImage *tmp = blur_asimage_gauss (target->asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF,
513 (original_asim == NULL || tint == TINT_LEAVE_SAME) ? ASA_XImage : ASA_ASImage,
514 100, ASIMAGE_QUALITY_DEFAULT);
515 if (tmp)
516 {
517 destroy_asimage (&background);
518 background = tmp;
519 }
520 }
521# endif
522
523 ASImage *result = 0;
524
447 int target_width = (int)target->szHint.width; 525 int target_width = target->szHint.width;
448 int target_height = (int)target->szHint.height; 526 int target_height = target->szHint.height;
449 int new_pmap_width = target_width, new_pmap_height = target_height; 527 int new_pmap_width = target_width;
450 ASImage *result = NULL; 528 int new_pmap_height = target_height;
451 529
452 int x = 0; 530 int x = 0;
453 int y = 0; 531 int y = 0;
454 int w = h_scale * target_width / 100; 532 int w = 0;
455 int h = v_scale * target_height / 100; 533 int h = 0;
456 534
457 TIMING_TEST_START (asim); 535 TIMING_TEST_START (asim);
458 536
459 if (original_asim) 537 if (original_asim)
460 { 538 get_image_geometry (original_asim->width, original_asim->height, w, h, x, y);
461 if (h_align == rootAlign || v_align == rootAlign)
462 {
463 target->get_window_origin(x, y);
464 x = -x;
465 y = -y;
466 }
467 if (h_align != rootAlign)
468 x = make_align_position (h_align, target_width, w > 0 ? w : (int)original_asim->width);
469 if (v_align != rootAlign)
470 y = make_align_position (v_align, target_height, h > 0 ? h : (int)original_asim->height);
471 }
472 539
473 if (original_asim == NULL 540 if (!original_asim
474 || x >= target_width 541 || x >= target_width
475 || y >= target_height 542 || y >= target_height
476 || (w > 0 && x + w <= 0) 543 || (w > 0 && x + w <= 0)
477 || (h > 0 && y + h <= 0)) 544 || (h > 0 && y + h <= 0))
478 { 545 {
479 if (background) 546 if (background)
480 { 547 {
481 new_pmap_width = background->width; 548 new_pmap_width = background->width;
482 new_pmap_height = background->height; 549 new_pmap_height = background->height;
483 result = background; 550 result = background;
551
484 if (background_tint != TINT_LEAVE_SAME) 552 if (background_tint != TINT_LEAVE_SAME)
485 { 553 {
486 ASImage* tmp = tile_asimage (target->asv, background, 0, 0, 554 ASImage *tmp = tile_asimage (target->asv, background, 0, 0,
487 target_width, target_height, background_tint, 555 target_width, target_height, background_tint,
488 ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT); 556 ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT);
489 if (tmp) 557 if (tmp)
490 result = tmp; 558 result = tmp;
491 } 559 }
494 new_pmap_width = new_pmap_height = 0; 562 new_pmap_width = new_pmap_height = 0;
495 } 563 }
496 else 564 else
497 { 565 {
498 result = original_asim; 566 result = original_asim;
567
499 if ((w > 0 && w != original_asim->width) 568 if ((w > 0 && w != original_asim->width)
500 || (h > 0 && h != original_asim->height)) 569 || (h > 0 && h != original_asim->height))
501 { 570 {
502 result = scale_asimage (target->asv, original_asim, 571 result = scale_asimage (target->asv, original_asim,
503 w > 0 ? w : original_asim->width, 572 w > 0 ? w : original_asim->width,
504 h > 0 ? h : original_asim->height, 573 h > 0 ? h : original_asim->height,
505 background ? ASA_ASImage : ASA_XImage, 574 background ? ASA_ASImage : ASA_XImage,
506 100, ASIMAGE_QUALITY_DEFAULT); 575 100, ASIMAGE_QUALITY_DEFAULT);
507 } 576 }
577
508 if (background == NULL) 578 if (background == NULL)
509 {/* if tiling - pixmap has to be sized exactly as the image, 579 {
510 but there is no need to make it bigger then the window! */
511 if (h_scale == 0)
512 new_pmap_width = min (result->width, target_width);
513 if (v_scale == 0)
514 new_pmap_height = min (result->height, target_height);
515 /* we also need to tile our image in one or both directions */
516 if (h_scale == 0 || v_scale == 0) 580 if (h_scale == 0 || v_scale == 0)
517 { 581 {
582 /* if tiling - pixmap has to be sized exactly as the image,
583 but there is no need to make it bigger than the window! */
584 new_pmap_width = min (result->width, target_width);
585 new_pmap_height = min (result->height, target_height);
586
587 /* we also need to tile our image in both directions */
518 ASImage *tmp = tile_asimage (target->asv, result, 588 ASImage *tmp = tile_asimage (target->asv, result,
519 (h_scale > 0) ? 0 : (int)result->width - x, 589 (int)result->width - x,
520 (v_scale > 0) ? 0 : (int)result->height - y, 590 (int)result->height - y,
521 new_pmap_width, 591 new_pmap_width,
522 new_pmap_height, 592 new_pmap_height,
523 TINT_LEAVE_SAME, ASA_XImage, 593 TINT_LEAVE_SAME, ASA_XImage,
524 100, ASIMAGE_QUALITY_DEFAULT); 594 100, ASIMAGE_QUALITY_DEFAULT);
525 if (tmp) 595 if (tmp)
526 { 596 {
527 if (result != original_asim) 597 if (result != original_asim)
528 destroy_asimage (&result); 598 destroy_asimage (&result);
599
529 result = tmp; 600 result = tmp;
530 } 601 }
531 } 602 }
532 } 603 }
533 else 604 else
605 {
534 {/* if blending background and image - pixmap has to be sized same as target window */ 606 /* if blending background and image - pixmap has to be sized same as target window */
535 ASImageLayer *layers = create_image_layers (2); 607 ASImageLayer *layers = create_image_layers (2);
536 ASImage *merged_im = NULL;
537 608
538 layers[0].im = background; 609 layers[0].im = background;
539 layers[0].clip_width = target_width; 610 layers[0].clip_width = target_width;
540 layers[0].clip_height = target_height; 611 layers[0].clip_height = target_height;
541 layers[0].tint = background_tint; 612 layers[0].tint = background_tint;
542 layers[1].im = result; 613 layers[1].im = result;
614
543 if (w <= 0) 615 if (w <= 0)
616 {
544 {/* tile horizontally */ 617 /* tile horizontally */
545 while (x > 0) x -= (int)result->width; 618 while (x > 0) x -= (int)result->width;
546 layers[1].dst_x = x; 619 layers[1].dst_x = x;
547 layers[1].clip_width = result->width+target_width; 620 layers[1].clip_width = result->width+target_width;
548 } 621 }
549 else 622 else
623 {
550 {/* clip horizontally */ 624 /* clip horizontally */
551 layers[1].dst_x = x; 625 layers[1].dst_x = x;
552 layers[1].clip_width = result->width; 626 layers[1].clip_width = result->width;
553 } 627 }
628
554 if (h <= 0) 629 if (h <= 0)
555 { 630 {
556 while (y > 0) y -= (int)result->height; 631 while (y > 0) y -= (int)result->height;
557 layers[1].dst_y = y; 632 layers[1].dst_y = y;
558 layers[1].clip_height = result->height + target_height; 633 layers[1].clip_height = result->height + target_height;
560 else 635 else
561 { 636 {
562 layers[1].dst_y = y; 637 layers[1].dst_y = y;
563 layers[1].clip_height = result->height; 638 layers[1].clip_height = result->height;
564 } 639 }
640
565 if (target->rs[Rs_blendtype]) 641 if (target->rs[Rs_blendtype])
566 { 642 {
567 layers[1].merge_scanlines = blend_scanlines_name2func (target->rs[Rs_blendtype]); 643 layers[1].merge_scanlines = blend_scanlines_name2func (target->rs[Rs_blendtype]);
568 if (layers[1].merge_scanlines == NULL) 644 if (layers[1].merge_scanlines == NULL)
569 layers[1].merge_scanlines = alphablend_scanlines; 645 layers[1].merge_scanlines = alphablend_scanlines;
570 } 646 }
647
571 ASImage *tmp = merge_layers (target->asv, layers, 2, target_width, target_height, 648 ASImage *tmp = merge_layers (target->asv, layers, 2, target_width, target_height,
572 ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT); 649 ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT);
650
573 if (tmp) 651 if (tmp)
574 { 652 {
575 if (result != original_asim) 653 if (result != original_asim)
576 destroy_asimage (&result); 654 destroy_asimage (&result);
655
577 result = tmp; 656 result = tmp;
578 } 657 }
658
579 free (layers); 659 free (layers);
580 } 660 }
581 } 661 }
582 TIMING_TEST_PRINT_RESULT (asim); 662 TIMING_TEST_PRINT_RESULT (asim);
583 663
584 if (pixmap) 664 bool ret = false;
585 {
586 if (result == NULL
587 || pmap_width != new_pmap_width
588 || pmap_height != new_pmap_height
589 || pmap_depth != target->depth)
590 {
591 XFreePixmap (target->dpy, pixmap);
592 pixmap = None;
593 }
594 }
595 665
596 if (result) 666 if (result)
597 { 667 {
598 XGCValues gcv; 668 XGCValues gcv;
599 GC gc; 669 GC gc;
670
671 if (pixmap)
672 {
673 if (pmap_width != new_pmap_width
674 || pmap_height != new_pmap_height
675 || pmap_depth != target->depth)
676 {
677 XFreePixmap (target->dpy, pixmap);
678 pixmap = None;
679 }
680 }
600 681
601 /* create Pixmap */ 682 /* create Pixmap */
602 if (pixmap == None) 683 if (pixmap == None)
603 { 684 {
604 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); 685 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth);
605 pmap_width = new_pmap_width; 686 pmap_width = new_pmap_width;
606 pmap_height = new_pmap_height; 687 pmap_height = new_pmap_height;
607 pmap_depth = target->depth; 688 pmap_depth = target->depth;
608 } 689 }
609 /* fill with background color ( if result's not completely overlapping it)*/ 690 /* fill with background color (if result's not completely overlapping it) */
610 gcv.foreground = target->pix_colors[Color_bg]; 691 gcv.foreground = target->pix_colors[Color_bg];
611 gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv); 692 gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv);
612 693
613 int src_x = 0, src_y = 0, dst_x = 0, dst_y = 0; 694 int src_x = 0, src_y = 0, dst_x = 0, dst_y = 0;
614 int dst_width = result->width, dst_height = result->height; 695 int dst_width = result->width, dst_height = result->height;
615 if (background == NULL) 696 if (background == NULL)
616 { 697 {
617 if (h_scale > 0) 698 if (!(h_scale == 0 || v_scale == 0))
699 {
618 src_x = make_clip_rectangle (x, result->width, new_pmap_width, dst_x, dst_width); 700 src_x = make_clip_rectangle (x, result->width , new_pmap_width , dst_x, dst_width );
619 if (v_scale > 0)
620 src_y = make_clip_rectangle (y, result->height, new_pmap_height, dst_y, dst_height); 701 src_y = make_clip_rectangle (y, result->height, new_pmap_height, dst_y, dst_height);
702 }
621 703
622 if (dst_x > 0 || dst_y > 0 704 if (dst_x > 0 || dst_y > 0
623 || dst_x + dst_width < new_pmap_width 705 || dst_x + dst_width < new_pmap_width
624 || dst_y + dst_height < new_pmap_height) 706 || dst_y + dst_height < new_pmap_height)
625 {
626 XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); 707 XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height);
627 }
628 } 708 }
629 709
630 /* put result on pixmap */ 710 /* put result on pixmap */
631 if (dst_x < new_pmap_width && dst_y < new_pmap_height) 711 if (dst_x < new_pmap_width && dst_y < new_pmap_height)
632 asimage2drawable (target->asv, pixmap, result, gc, src_x, src_y, dst_x, dst_y, dst_width, dst_height, True); 712 asimage2drawable (target->asv, pixmap, result, gc, src_x, src_y, dst_x, dst_y, dst_width, dst_height, True);
634 if (result != background && result != original_asim) 714 if (result != background && result != original_asim)
635 destroy_asimage (&result); 715 destroy_asimage (&result);
636 716
637 XFreeGC (target->dpy, gc); 717 XFreeGC (target->dpy, gc);
638 TIMING_TEST_PRINT_RESULT (asim); 718 TIMING_TEST_PRINT_RESULT (asim);
639 }
640 719
720 ret = true;
721 }
722
723 if (background)
724 destroy_asimage (&background);
725
641 return true; 726 return ret;
642} 727}
643# endif /* HAVE_AFTERIMAGE */ 728# endif /* HAVE_AFTERIMAGE */
729
730# ifdef HAVE_PIXBUF
731bool
732bgPixmap_t::render_image (unsigned long background_flags)
733{
734 if (target == NULL)
735 return false;
736
737 if (!pixbuf)
738 return false;
739
740 // TODO: add alpha blending
741 if (background_flags)
742 return false;
743
744 GdkPixbuf *result;
745
746 int image_width = gdk_pixbuf_get_width (pixbuf);
747 int image_height = gdk_pixbuf_get_height (pixbuf);
748
749 int target_width = target->szHint.width;
750 int target_height = target->szHint.height;
751 int new_pmap_width = target_width;
752 int new_pmap_height = target_height;
753
754 int x = 0;
755 int y = 0;
756 int w = 0;
757 int h = 0;
758
759 get_image_geometry (image_width, image_height, w, h, x, y);
760
761 if (x >= target_width
762 || y >= target_height
763 || (w > 0 && x + w <= 0)
764 || (h > 0 && y + h <= 0))
765 return false;
766
767 result = pixbuf;
768
769 if ((w > 0 && w != image_width)
770 || (h > 0 && h != image_height))
771 {
772 result = gdk_pixbuf_scale_simple (pixbuf,
773 w > 0 ? w : image_width,
774 h > 0 ? h : image_height,
775 GDK_INTERP_BILINEAR);
776 }
777
778 bool ret = false;
779
780 if (result)
781 {
782 XGCValues gcv;
783 GC gc;
784
785 image_width = gdk_pixbuf_get_width (result);
786 image_height = gdk_pixbuf_get_height (result);
787
788 if (h_scale == 0 || v_scale == 0)
789 {
790 new_pmap_width = min (image_width, target_width);
791 new_pmap_height = min (image_height, target_height);
792 }
793
794 if (pixmap)
795 {
796 if (pmap_width != new_pmap_width
797 || pmap_height != new_pmap_height
798 || pmap_depth != target->depth)
799 {
800 XFreePixmap (target->dpy, pixmap);
801 pixmap = None;
802 }
803 }
804
805 if (pixmap == None)
806 {
807 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth);
808 pmap_width = new_pmap_width;
809 pmap_height = new_pmap_height;
810 pmap_depth = target->depth;
811 }
812
813 gcv.foreground = target->pix_colors[Color_bg];
814 gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv);
815
816 if (h_scale == 0 || v_scale == 0)
817 {
818 Pixmap tile = XCreatePixmap (target->dpy, target->vt, image_width, image_height, target->depth);
819 gdk_pixbuf_xlib_render_to_drawable (result, tile, gc,
820 0, 0,
821 0, 0,
822 image_width, image_height,
823 XLIB_RGB_DITHER_NONE,
824 0, 0);
825
826 gcv.tile = tile;
827 gcv.fill_style = FillTiled;
828 gcv.ts_x_origin = x;
829 gcv.ts_y_origin = y;
830 XChangeGC (target->dpy, gc, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv);
831
832 XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height);
833 XFreePixmap (target->dpy, tile);
834 }
835 else
836 {
837 int src_x, src_y, dst_x, dst_y;
838 int dst_width, dst_height;
839
840 src_x = make_clip_rectangle (x, image_width , new_pmap_width , dst_x, dst_width );
841 src_y = make_clip_rectangle (y, image_height, new_pmap_height, dst_y, dst_height);
842
843 if (dst_x > 0 || dst_y > 0
844 || dst_x + dst_width < new_pmap_width
845 || dst_y + dst_height < new_pmap_height)
846 XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height);
847
848 if (dst_x < new_pmap_width && dst_y < new_pmap_height)
849 gdk_pixbuf_xlib_render_to_drawable (result, pixmap, gc,
850 src_x, src_y,
851 dst_x, dst_y,
852 dst_width, dst_height,
853 XLIB_RGB_DITHER_NONE,
854 0, 0);
855 }
856
857 if (result != pixbuf)
858 g_object_unref (result);
859
860 XFreeGC (target->dpy, gc);
861
862 ret = true;
863 }
864
865 return ret;
866}
867# endif /* HAVE_PIXBUF */
644 868
645bool 869bool
646bgPixmap_t::set_file (const char *file) 870bgPixmap_t::set_file (const char *file)
647{ 871{
648 char *f;
649
650 assert (file != NULL); 872 assert (file);
651 873
652 if (*file != '\0') 874 if (*file)
653 { 875 {
876 if (const char *p = strchr (file, ';'))
877 {
878 size_t len = p - file;
879 char *f = rxvt_temp_buf<char> (len + 1);
880 memcpy (f, file, len);
881 f[len] = '\0';
882 file = f;
883 }
884
654# ifdef HAVE_AFTERIMAGE 885# ifdef HAVE_AFTERIMAGE
655 if (target->asimman == NULL) 886 if (!target->asimman)
656 target->asimman = create_generic_imageman (target->rs[Rs_path]); 887 target->asimman = create_generic_imageman (target->rs[Rs_path]);
657 if ((f = strchr (file, ';')) == NULL)
658 original_asim = get_asimage (target->asimman, file, 0xFFFFFFFF, 100); 888 original_asim = get_asimage (target->asimman, file, 0xFFFFFFFF, 100);
659 else 889 if (original_asim)
660 { 890 have_image = true;
661 size_t len = f - file; 891 return have_image;
662 f = (char *)malloc (len + 1);
663 strncpy (f, file, len);
664 f[len] = '\0';
665 original_asim = get_asimage (target->asimman, f, 0xFFFFFFFF, 100);
666 free (f);
667 }
668 return (original_asim != NULL);
669# endif 892# endif
893
894# ifdef HAVE_PIXBUF
895 pixbuf = gdk_pixbuf_new_from_file (file, NULL);
896 if (pixbuf)
897 have_image = true;
898 return have_image;
899# endif
670 } 900 }
901
671 return false; 902 return false;
672} 903}
673 904
674# endif /* BG_IMAGE_FROM_FILE */ 905# endif /* BG_IMAGE_FROM_FILE */
675 906
680 if (!(flags & isTransparent)) 911 if (!(flags & isTransparent))
681 { 912 {
682 flags |= isTransparent; 913 flags |= isTransparent;
683 return true; 914 return true;
684 } 915 }
916
685 return false; 917 return false;
686} 918}
687 919
688bool 920bool
689bgPixmap_t::set_blur_radius (const char *geom) 921bgPixmap_t::set_blur_radius (const char *geom)
691 int changed = 0; 923 int changed = 0;
692 unsigned int hr, vr; 924 unsigned int hr, vr;
693 int junk; 925 int junk;
694 int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); 926 int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr);
695 927
696 if (!(geom_flags&WidthValue)) 928 if (!(geom_flags & WidthValue))
697 hr = 1; 929 hr = 1;
698 if (!(geom_flags&HeightValue)) 930 if (!(geom_flags & HeightValue))
699 vr = hr; 931 vr = hr;
700 932
701 if (h_blurRadius != hr) 933 if (h_blurRadius != hr)
702 { 934 {
703 ++changed; 935 ++changed;
713 if (v_blurRadius == 0 && h_blurRadius == 0) 945 if (v_blurRadius == 0 && h_blurRadius == 0)
714 flags &= ~blurNeeded; 946 flags &= ~blurNeeded;
715 else 947 else
716 flags |= blurNeeded; 948 flags |= blurNeeded;
717 949
718 return (changed>0); 950 return (changed > 0);
719} 951}
720 952
721static inline unsigned long 953static inline unsigned long
722compute_tint_shade_flags (rxvt_color *tint, int shade) 954compute_tint_shade_flags (rxvt_color *tint, int shade)
723{ 955{
740 flags |= bgPixmap_t::tintNeeded; 972 flags |= bgPixmap_t::tintNeeded;
741 else if (tint) 973 else if (tint)
742 { 974 {
743 if ((c.r > 0x000700 || c.g > 0x000700 || c.b > 0x000700) 975 if ((c.r > 0x000700 || c.g > 0x000700 || c.b > 0x000700)
744 && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700)) 976 && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700))
745 { 977 {
746 flags |= bgPixmap_t::tintNeeded; 978 flags |= bgPixmap_t::tintNeeded;
747 } 979 }
748 } 980 }
749 981
750 if (flags & bgPixmap_t::tintNeeded) 982 if (flags & bgPixmap_t::tintNeeded)
751 { 983 {
752 if (flags & bgPixmap_t::tintWholesome) 984 if (flags & bgPixmap_t::tintWholesome)
770 unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade); 1002 unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade);
771 tint = new_tint; 1003 tint = new_tint;
772 flags = (flags & ~tintFlags) | new_flags | tintSet; 1004 flags = (flags & ~tintFlags) | new_flags | tintSet;
773 return true; 1005 return true;
774 } 1006 }
1007
775 return false; 1008 return false;
776} 1009}
777 1010
778bool 1011bool
779bgPixmap_t::unset_tint () 1012bgPixmap_t::unset_tint ()
780{ 1013{
781 unsigned long new_flags = compute_tint_shade_flags (NULL, shade); 1014 unsigned long new_flags = compute_tint_shade_flags (NULL, shade);
782 1015
783 if (new_flags != (flags & tintFlags)) 1016 if (new_flags != (flags & tintFlags))
784 { 1017 {
785 flags = (flags&~tintFlags)|new_flags; 1018 flags = (flags & ~tintFlags) | new_flags;
786 return true; 1019 return true;
787 } 1020 }
1021
788 return false; 1022 return false;
789} 1023}
790 1024
791bool 1025bool
792bgPixmap_t::set_shade (const char *shade_str) 1026bgPixmap_t::set_shade (const char *shade_str)
793{ 1027{
794 int new_shade = (shade_str) ? atoi (shade_str) : 0; 1028 int new_shade = (shade_str) ? atoi (shade_str) : 0;
795 1029
796 if (new_shade < 0 && new_shade > -100) 1030 if (new_shade < 0 && new_shade > -100)
797 new_shade = 200 - (100 + new_shade); 1031 new_shade = 200 - (100 + new_shade);
798 else if (new_shade == 100) 1032 else if (new_shade == 100)
799 new_shade = 0; 1033 new_shade = 0;
800 1034
801 if (new_shade != shade) 1035 if (new_shade != shade)
802 { 1036 {
803 unsigned long new_flags = compute_tint_shade_flags ((flags & tintSet) ? &tint : NULL, new_shade); 1037 unsigned long new_flags = compute_tint_shade_flags ((flags & tintSet) ? &tint : NULL, new_shade);
804 shade = new_shade; 1038 shade = new_shade;
805 flags = (flags & (~tintFlags | tintSet)) | new_flags; 1039 flags = (flags & (~tintFlags | tintSet)) | new_flags;
806 return true; 1040 return true;
807 } 1041 }
1042
808 return false; 1043 return false;
809} 1044}
810 1045
811/* make_transparency_pixmap() 1046/* make_transparency_pixmap()
812 * Builds a pixmap sized the same as terminal window, with depth same as the root window 1047 * Builds a pixmap sized the same as terminal window, with depth same as the root window
819 unsigned long result = 0; 1054 unsigned long result = 0;
820 1055
821 if (target == NULL) 1056 if (target == NULL)
822 return 0; 1057 return 0;
823 1058
824 /* root dimentions may change from call to call - but Display structure should 1059 /* root dimensions may change from call to call - but Display structure should
825 * be always up-to-date, so let's use it : 1060 * be always up-to-date, so let's use it :
826 */ 1061 */
827 Window root = target->display->root; 1062 Window root = target->display->root;
828 int screen = target->display->screen; 1063 int screen = target->display->screen;
829 Display *dpy = target->dpy; 1064 Display *dpy = target->dpy;
842 if (sx + window_width <= 0 || sy + window_height <= 0 1077 if (sx + window_width <= 0 || sy + window_height <= 0
843 || sx >= root_width || sy >= root_height) 1078 || sx >= root_width || sy >= root_height)
844 return 0; 1079 return 0;
845 1080
846 if (root_pixmap != None) 1081 if (root_pixmap != None)
1082 {
847 {/* we want to validate the pixmap and get it's size at the same time : */ 1083 /* we want to validate the pixmap and get it's size at the same time : */
848 int junk; 1084 int junk;
849 unsigned int ujunk; 1085 unsigned int ujunk;
850 /* root pixmap may be bad - allow a error */ 1086 /* root pixmap may be bad - allow a error */
851 target->allowedxerror = -1; 1087 target->allowedxerror = -1;
852 1088
861 1097
862 if (tiled_root_pmap == None) /* something really bad happened - abort */ 1098 if (tiled_root_pmap == None) /* something really bad happened - abort */
863 return 0; 1099 return 0;
864 1100
865 if (root_pixmap == None) 1101 if (root_pixmap == None)
1102 {
866 { /* use tricks to obtain the root background image :*/ 1103 /* use tricks to obtain the root background image :*/
867 /* we want to create Overrideredirect window overlapping out window 1104 /* we want to create Overrideredirect window overlapping out window
868 with background type of Parent Relative and then grab it */ 1105 with background type of Parent Relative and then grab it */
869 XSetWindowAttributes attr; 1106 XSetWindowAttributes attr;
870 Window src; 1107 Window src;
871 bool success = false; 1108 bool success = false;
872 1109
873 attr.background_pixmap = ParentRelative; 1110 attr.background_pixmap = ParentRelative;
874 attr.backing_store = Always; 1111 attr.backing_store = Always;
875 attr.event_mask = ExposureMask; 1112 attr.event_mask = ExposureMask;
876 attr.override_redirect = True; 1113 attr.override_redirect = True;
877 src = XCreateWindow (dpy, root, sx, sy, window_width, window_height, 0, 1114 src = XCreateWindow (dpy, root, sx, sy, window_width, window_height, 0,
878 CopyFromParent, CopyFromParent, CopyFromParent, 1115 CopyFromParent, CopyFromParent, CopyFromParent,
879 CWBackPixmap|CWBackingStore|CWOverrideRedirect|CWEventMask, 1116 CWBackPixmap|CWBackingStore|CWOverrideRedirect|CWEventMask,
880 &attr); 1117 &attr);
881 1118
882 if (src != None) 1119 if (src != None)
886 XGrabServer (dpy); 1123 XGrabServer (dpy);
887 XMapRaised (dpy, src); 1124 XMapRaised (dpy, src);
888 XSync (dpy, False); 1125 XSync (dpy, False);
889 1126
890 /* XSync should get window where it's properly exposed, 1127 /* XSync should get window where it's properly exposed,
891 * but to be on the safe side - let's check for the actuall event to arrive : */ 1128 * but to be on the safe side - let's check for the actual event to arrive : */
892 while (XCheckWindowEvent (dpy, src, ExposureMask, &event)) 1129 while (XCheckWindowEvent (dpy, src, ExposureMask, &event))
893 ++ev_count; 1130 ++ev_count;
894 1131
895 if (ev_count > 0); 1132 if (ev_count > 0);
1133 {
896 { /* hooray! - we can grab the image! */ 1134 /* hooray! - we can grab the image! */
897 gc = XCreateGC (dpy, root, 0, NULL); 1135 gc = XCreateGC (dpy, root, 0, NULL);
898 if (gc) 1136 if (gc)
899 { 1137 {
900 XCopyArea (dpy, src, tiled_root_pmap, gc, 0, 0, window_width, window_height, 0, 0); 1138 XCopyArea (dpy, src, tiled_root_pmap, gc, 0, 0, window_width, window_height, 0, 0);
901 success = true; 1139 success = true;
902 } 1140 }
903 } 1141 }
1142
904 XDestroyWindow (dpy, src); 1143 XDestroyWindow (dpy, src);
905 XUngrabServer (dpy); 1144 XUngrabServer (dpy);
906 //fprintf (stderr, "%s:%d: ev_count = %d\n", __FUNCTION__, __LINE__, ev_count); 1145 //fprintf (stderr, "%s:%d: ev_count = %d\n", __FUNCTION__, __LINE__, ev_count);
907 } 1146 }
908 1147
909 if (!success) 1148 if (!success)
910 { 1149 {
911 XFreePixmap (dpy, tiled_root_pmap); 1150 XFreePixmap (dpy, tiled_root_pmap);
912 tiled_root_pmap = None; 1151 tiled_root_pmap = None;
913 } 1152 }
914 else 1153 else
915 result |= transpPmapTiled; 1154 result |= transpPmapTiled;
916 } 1155 }
917 else 1156 else
1157 {
918 {/* strightforward pixmap copy */ 1158 /* straightforward pixmap copy */
919 gcv.tile = root_pixmap; 1159 gcv.tile = root_pixmap;
920 gcv.fill_style = FillTiled; 1160 gcv.fill_style = FillTiled;
921 1161
922 while (sx < 0) sx += (int)root_width; 1162 while (sx < 0) sx += (int)root_width;
923 while (sy < 0) sy += (int)root_height; 1163 while (sy < 0) sy += (int)root_height;
971 { 1211 {
972 c.r = (c.r * shade) / 100; 1212 c.r = (c.r * shade) / 100;
973 c.g = (c.g * shade) / 100; 1213 c.g = (c.g * shade) / 100;
974 c.b = (c.b * shade) / 100; 1214 c.b = (c.b * shade) / 100;
975 } 1215 }
976 else if( shade > 100 && shade < 200) 1216 else if (shade > 100 && shade < 200)
977 { 1217 {
978 c.r = (c.r * (200 - shade)) / 100; 1218 c.r = (c.r * (200 - shade)) / 100;
979 c.g = (c.g * (200 - shade)) / 100; 1219 c.g = (c.g * (200 - shade)) / 100;
980 c.b = (c.b * (200 - shade)) / 100; 1220 c.b = (c.b * (200 - shade)) / 100;
981 } 1221 }
1027 mask_c.blue = 0xffff - c.b; 1267 mask_c.blue = 0xffff - c.b;
1028 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1); 1268 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1);
1029 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, window_width, window_height); 1269 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, window_width, window_height);
1030 result |= transpPmapTinted; 1270 result |= transpPmapTinted;
1031 } 1271 }
1272
1032 XRenderFreePicture (dpy, mask_pic); 1273 XRenderFreePicture (dpy, mask_pic);
1033 XRenderFreePicture (dpy, overlay_pic); 1274 XRenderFreePicture (dpy, overlay_pic);
1034 XRenderFreePicture (dpy, back_pic); 1275 XRenderFreePicture (dpy, back_pic);
1035# if DO_TIMING_TEST 1276# if DO_TIMING_TEST
1036 XSync (dpy, False); 1277 XSync (dpy, False);
1037# endif 1278# endif
1038# endif 1279# endif
1039 } 1280 }
1040 } 1281 }
1041 } /* server side rendering completed */ 1282 } /* server side rendering completed */
1042 1283
1043 if (pixmap) 1284 if (pixmap)
1044 XFreePixmap (dpy, pixmap); 1285 XFreePixmap (dpy, pixmap);
1045 1286
1058} 1299}
1059 1300
1060bool 1301bool
1061bgPixmap_t::set_root_pixmap () 1302bgPixmap_t::set_root_pixmap ()
1062{ 1303{
1063 Pixmap new_root_pixmap = None;
1064
1065 new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID); 1304 Pixmap new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID);
1066 if (new_root_pixmap == None) 1305 if (new_root_pixmap == None)
1067 new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID); 1306 new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID);
1068 1307
1069 if (new_root_pixmap != root_pixmap) 1308 if (new_root_pixmap != root_pixmap)
1070 { 1309 {
1071 root_pixmap = new_root_pixmap; 1310 root_pixmap = new_root_pixmap;
1072 return true; 1311 return true;
1073 } 1312 }
1313
1074 return false; 1314 return false;
1075} 1315}
1076# endif /* ENABLE_TRANSPARENCY */ 1316# endif /* ENABLE_TRANSPARENCY */
1077 1317
1078# ifndef HAVE_AFTERIMAGE 1318# ifndef HAVE_AFTERIMAGE
1079static void ShadeXImage(rxvt_term *term, XImage* srcImage, int shade, int rm, int gm, int bm); 1319static void ShadeXImage(rxvt_term *term, XImage *srcImage, int shade, int rm, int gm, int bm);
1080# endif 1320# endif
1081
1082 1321
1083bool 1322bool
1084bgPixmap_t::render () 1323bgPixmap_t::render ()
1085{ 1324{
1086 unsigned long background_flags = 0; 1325 unsigned long background_flags = 0;
1088 if (target == NULL) 1327 if (target == NULL)
1089 return false; 1328 return false;
1090 1329
1091 TIMING_TEST_START (tp); 1330 TIMING_TEST_START (tp);
1092 1331
1093 invalidate(); 1332 invalidate ();
1094# ifdef ENABLE_TRANSPARENCY 1333# ifdef ENABLE_TRANSPARENCY
1095 if (flags & isTransparent) 1334 if (flags & isTransparent)
1096 { 1335 {
1097 /* we need to re-generate transparency pixmap in that case ! */ 1336 /* we need to re-generate transparency pixmap in that case ! */
1098 background_flags = make_transparency_pixmap (); 1337 background_flags = make_transparency_pixmap ();
1099 if (background_flags == 0) 1338 if (background_flags == 0)
1100 return false; 1339 return false;
1101 else if ((background_flags & transpTransformations) == (flags & transpTransformations) 1340 else if ((background_flags & transpTransformations) == (flags & transpTransformations)
1102 && pmap_depth == target->depth) 1341 && pmap_depth == target->depth)
1103 flags = flags & ~isInvalid; 1342 flags = flags & ~isInvalid;
1104 } 1343 }
1105# endif 1344# endif
1106 1345
1346# ifdef BG_IMAGE_FROM_FILE
1347 if (have_image
1348 || (background_flags & transpTransformations) != (flags & transpTransformations))
1349 {
1350 if (render_image (background_flags))
1351 flags = flags & ~isInvalid;
1352 }
1353# endif
1354
1107 XImage *result = NULL; 1355 XImage *result = NULL;
1108# ifdef HAVE_AFTERIMAGE 1356
1109 if (original_asim 1357 if (background_flags && (flags & isInvalid))
1110 || (background_flags & transpTransformations) != (flags & transpTransformations)) 1358 {
1359 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap);
1111 { 1360 }
1112 ASImage *background = NULL;
1113 ARGB32 as_tint = TINT_LEAVE_SAME;
1114 if (background_flags)
1115 background = pixmap2ximage (target->asv, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, 100);
1116 1361
1117# ifdef ENABLE_TRANSPARENCY 1362 if (result)
1363 {
1364# if !defined(HAVE_AFTERIMAGE) && !XFT
1365 /* our own client-side tinting */
1366 /* ATTENTION: We ASSUME that XFT will let us do all the tinting necessary server-side.
1367 This may need to be changed in need_client_side_rendering() logic is altered !!! */
1118 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) 1368 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded))
1119 {
1120 ShadingInfo as_shade;
1121 as_shade.shading = (shade == 0) ? 100 : shade;
1122
1123 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1124 if (flags & tintSet)
1125 tint.get (c);
1126 as_shade.tintColor.red = c.r;
1127 as_shade.tintColor.green = c.g;
1128 as_shade.tintColor.blue = c.b;
1129
1130 as_tint = shading2tint32 (&as_shade);
1131 }
1132 if (!(background_flags & transpPmapBlured) && (flags & blurNeeded) && background != NULL)
1133 {
1134 ASImage* tmp = blur_asimage_gauss (target->asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF,
1135 (original_asim == NULL || tint == TINT_LEAVE_SAME)?ASA_XImage:ASA_ASImage,
1136 100, ASIMAGE_QUALITY_DEFAULT);
1137 if (tmp)
1138 {
1139 destroy_asimage (&background);
1140 background = tmp;
1141 }
1142 }
1143# endif
1144
1145 if (render_asim (background, as_tint))
1146 flags = flags & ~isInvalid;
1147 if (background)
1148 destroy_asimage (&background);
1149 }
1150 else if (background_flags && pmap_depth != target->depth)
1151 {
1152 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap);
1153 }
1154
1155# elif !XFT /* our own client-side tinting */
1156
1157 /* ATTENTION: We ASSUME that XFT will let us do all the tinting neccessary server-side.
1158 This may need to be changed in need_client_side_rendering() logic is altered !!! */
1159
1160 if (background_flags && (flags & isInvalid))
1161 {
1162 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap);
1163 if (result != NULL && !(background_flags & transpPmapTinted) && (flags & tintNeeded))
1164 { 1369 {
1165 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 1370 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1166 if (flags & tintSet) 1371 if (flags & tintSet)
1167 tint.get (c); 1372 tint.get (c);
1168 ShadeXImage (target, result, shade, c.r, c.g, c.b); 1373 ShadeXImage (target, result, shade, c.r, c.g, c.b);
1169 } 1374 }
1170 } 1375# endif
1171# endif /* HAVE_AFTERIMAGE */
1172 1376
1173 if (result != NULL)
1174 {
1175 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); 1377 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL);
1378
1176 if (gc) 1379 if (gc)
1177 { 1380 {
1178 if (/*pmap_depth != target->depth &&*/ pixmap != None) 1381 if (/*pmap_depth != target->depth &&*/ pixmap != None)
1179 { 1382 {
1180 XFreePixmap (target->dpy, pixmap); 1383 XFreePixmap (target->dpy, pixmap);
1181 pixmap = None; 1384 pixmap = None;
1182 } 1385 }
1386
1183 if (pixmap == None) 1387 if (pixmap == None)
1184 { 1388 {
1185 pixmap = XCreatePixmap (target->dpy, target->vt, result->width, result->height, target->depth); 1389 pixmap = XCreatePixmap (target->dpy, target->vt, result->width, result->height, target->depth);
1186 pmap_width = result->width; 1390 pmap_width = result->width;
1187 pmap_height = result->height; 1391 pmap_height = result->height;
1188 pmap_depth = target->depth; 1392 pmap_depth = target->depth;
1189 } 1393 }
1394
1190 if (pmap_depth != result->depth) 1395 if (pmap_depth != result->depth)
1396 {
1191 { /* Bad Match error will ensue ! stupid X !!!! */ 1397 /* Bad Match error will ensue ! stupid X !!!! */
1192 if( result->depth == 24 && pmap_depth == 32) 1398 if (result->depth == 24 && pmap_depth == 32)
1193 result->depth = 32; 1399 result->depth = 32;
1194 else if( result->depth == 32 && pmap_depth == 24) 1400 else if (result->depth == 32 && pmap_depth == 24)
1195 result->depth = 24; 1401 result->depth = 24;
1196 else 1402 else
1197 { 1403 {
1198 /* TODO: implement image recoding */ 1404 /* TODO: implement image recoding */
1199 } 1405 }
1200 } 1406 }
1407
1201 if (pmap_depth == result->depth) 1408 if (pmap_depth == result->depth)
1202 XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height); 1409 XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height);
1410
1203 XFreeGC (target->dpy, gc); 1411 XFreeGC (target->dpy, gc);
1204 flags = flags & ~isInvalid; 1412 flags = flags & ~isInvalid;
1205 } 1413 }
1414
1206 XDestroyImage (result); 1415 XDestroyImage (result);
1207 } 1416 }
1208 1417
1209 if (flags & isInvalid) 1418 if (flags & isInvalid)
1210 { 1419 {
1211 if (pixmap != None) 1420 if (pixmap != None)
1214 pixmap = None; 1423 pixmap = None;
1215 } 1424 }
1216 } 1425 }
1217 1426
1218 apply (); 1427 apply ();
1428
1429 XSync (target->dpy, False);
1430 valid_since = ev::now ();
1219 1431
1220 TIMING_TEST_PRINT_RESULT (tp); 1432 TIMING_TEST_PRINT_RESULT (tp);
1221 1433
1222 return true; 1434 return true;
1223} 1435}
1232# ifdef ENABLE_TRANSPARENCY 1444# ifdef ENABLE_TRANSPARENCY
1233 root_depth = DefaultDepthOfScreen (ScreenOfDisplay (target->dpy, target->display->screen)); 1445 root_depth = DefaultDepthOfScreen (ScreenOfDisplay (target->dpy, target->display->screen));
1234# endif 1446# endif
1235 return true; 1447 return true;
1236 } 1448 }
1449
1237 return false; 1450 return false;
1238} 1451}
1239 1452
1240void 1453void
1241bgPixmap_t::apply() 1454bgPixmap_t::apply ()
1242{ 1455{
1243 if (target) 1456 if (target)
1244 { 1457 {
1245 flags &= ~isVtOrigin; 1458 flags &= ~isVtOrigin;
1459
1246 if (pixmap != None) 1460 if (pixmap != None)
1461 {
1247 { /* set target's background to pixmap */ 1462 /* set target's background to pixmap */
1248# ifdef ENABLE_TRANSPARENCY 1463# ifdef ENABLE_TRANSPARENCY
1249 if (flags & isTransparent) 1464 if (flags & isTransparent)
1250 { 1465 {
1251 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap); 1466 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap);
1252 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative); 1467 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative);
1253# if HAVE_SCROLLBARS 1468
1254 if (target->scrollBar.win) 1469 if (target->scrollBar.win)
1255 XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative); 1470 XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative);
1256# endif
1257 } 1471 }
1258 else 1472 else
1259# endif 1473# endif
1260 { 1474 {
1261 flags |= isVtOrigin; 1475 flags |= isVtOrigin;
1262 /* force old pixmap dereference in case it was transparent before :*/ 1476 /* force old pixmap dereference in case it was transparent before :*/
1263 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); 1477 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
1264 XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap); 1478 XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap);
1265 /* do we also need to set scrollbar's background here ? */ 1479 /* do we also need to set scrollbar's background here ? */
1266# if HAVE_SCROLLBARS 1480
1267 if (target->scrollBar.win) 1481 if (target->scrollBar.win)
1268 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); 1482 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1269# endif
1270 } 1483 }
1271 } 1484 }
1272 else 1485 else
1486 {
1273 { /* set target background to a pixel */ 1487 /* set target background to a pixel */
1274 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); 1488 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
1275 XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); 1489 XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]);
1276 /* do we also need to set scrollbar's background here ? */ 1490 /* do we also need to set scrollbar's background here ? */
1277# if HAVE_SCROLLBARS
1278 if (target->scrollBar.win) 1491 if (target->scrollBar.win)
1279 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); 1492 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1280# endif
1281 } 1493 }
1494
1282 /* don't want Expose on the parent or vt. It is better to use 1495 /* don't want Expose on the parent or vt. It is better to use
1283 scr_touch or we get a great deal of flicker otherwise: */ 1496 scr_touch or we get a great deal of flicker otherwise: */
1284 XClearWindow (target->dpy, target->parent[0]); 1497 XClearWindow (target->dpy, target->parent[0]);
1285 1498
1286# if HAVE_SCROLLBARS 1499 if (target->scrollBar.state && target->scrollBar.win)
1287 if (target->scrollBar.win)
1288 { 1500 {
1289 target->scrollBar.setIdle (); 1501 target->scrollBar.state = STATE_IDLE;
1290 target->scrollbar_show (0); 1502 target->scrollBar.show (0);
1291 } 1503 }
1292# endif
1293 1504
1294 target->want_refresh = 1; 1505 target->want_refresh = 1;
1295 flags |= hasChanged; 1506 flags |= hasChanged;
1296 } 1507 }
1297} 1508}
1302/* taken from aterm-0.4.2 */ 1513/* taken from aterm-0.4.2 */
1303 1514
1304typedef uint32_t RUINT32T; 1515typedef uint32_t RUINT32T;
1305 1516
1306static void 1517static void
1307ShadeXImage(rxvt_term *term, XImage* srcImage, int shade, int rm, int gm, int bm) 1518ShadeXImage(rxvt_term *term, XImage *srcImage, int shade, int rm, int gm, int bm)
1308{ 1519{
1309 int sh_r, sh_g, sh_b; 1520 int sh_r, sh_g, sh_b;
1310 RUINT32T mask_r, mask_g, mask_b; 1521 RUINT32T mask_r, mask_g, mask_b;
1311 RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b; 1522 RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b;
1312 unsigned int lower_lim_r, lower_lim_g, lower_lim_b; 1523 unsigned int lower_lim_r, lower_lim_g, lower_lim_b;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines