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.2 by sasha, Wed Sep 12 21:06:08 2007 UTC vs.
Revision 1.62 by sf-exg, Sun Oct 3 21:44:13 2010 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines