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.14 by root, Mon Nov 19 15:33:34 2007 UTC vs.
Revision 1.41 by sf-exg, Sat Aug 21 16:07:15 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) 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.
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
97#ifdef BG_IMAGE_FROM_FILE 101#ifdef BG_IMAGE_FROM_FILE
98 h_scale = v_scale = 0; 102 h_scale = v_scale = 0;
99 h_align = v_align = 0; 103 h_align = v_align = 0;
100#endif 104#endif
101 flags = 0; 105 flags = 0;
102 pixmap = None; 106 pixmap = None;
107 valid_since = invalid_since = 0;
108 target = 0;
103} 109}
104 110
105void 111void
106bgPixmap_t::destroy () 112bgPixmap_t::destroy ()
107{ 113{
122 return true; 128 return true;
123# endif 129# endif
124 130
125# ifdef BG_IMAGE_FROM_FILE 131# ifdef BG_IMAGE_FROM_FILE
126# ifdef HAVE_AFTERIMAGE 132# ifdef HAVE_AFTERIMAGE
127 if (original_asim != NULL) 133 if (original_asim)
128# endif 134# endif
129 { 135 {
130 if (h_scale != 0 || v_scale != 0 136 if (h_scale != 0 || v_scale != 0
131 || h_align != 0 || v_align != 0) 137 || h_align != 0 || v_align != 0)
132 return true; 138 return true;
134# endif 140# endif
135 141
136 return false; 142 return false;
137} 143}
138 144
139bool 145bool
140bgPixmap_t::window_position_sensitive () 146bgPixmap_t::window_position_sensitive ()
141{ 147{
142# ifdef ENABLE_TRANSPARENCY 148# ifdef ENABLE_TRANSPARENCY
143 if (flags & isTransparent) 149 if (flags & isTransparent)
144 return true; 150 return true;
145# endif 151# endif
146 152
147# ifdef BG_IMAGE_FROM_FILE 153# ifdef BG_IMAGE_FROM_FILE
148# ifdef HAVE_AFTERIMAGE 154# ifdef HAVE_AFTERIMAGE
149 if (original_asim != NULL) 155 if (original_asim)
150# endif 156# endif
151 { 157 {
152 if (h_align == rootAlign || v_align == rootAlign) 158 if (h_align == rootAlign || v_align == rootAlign)
153 return true; 159 return true;
154 } 160 }
158}; 164};
159 165
160bool bgPixmap_t::need_client_side_rendering () 166bool bgPixmap_t::need_client_side_rendering ()
161{ 167{
162# ifdef HAVE_AFTERIMAGE 168# ifdef HAVE_AFTERIMAGE
163 if (original_asim != NULL) 169 if (original_asim)
164 return true; 170 return true;
165# endif 171# endif
166# ifdef ENABLE_TRANSPARENCY 172# ifdef ENABLE_TRANSPARENCY
167 if (flags & isTransparent) 173 if (flags & isTransparent)
168 { 174 {
257 int geom_flags = 0, changed = 0; 263 int geom_flags = 0, changed = 0;
258 int x = 0, y = 0; 264 int x = 0, y = 0;
259 unsigned int w = 0, h = 0; 265 unsigned int w = 0, h = 0;
260 unsigned int n; 266 unsigned int n;
261 unsigned long new_flags = (flags & (~geometryFlags)); 267 unsigned long new_flags = (flags & (~geometryFlags));
262 char *p; 268 const char *p;
263# define MAXLEN_GEOM 256 /* could be longer then regular geometry string */ 269# define MAXLEN_GEOM 256 /* could be longer than regular geometry string */
264 270
265 if (geom == NULL) 271 if (geom == NULL)
266 return false; 272 return false;
267 273
268 char str[MAXLEN_GEOM]; 274 char str[MAXLEN_GEOM];
275 if (n < MAXLEN_GEOM) 281 if (n < MAXLEN_GEOM)
276 { 282 {
277 char *ops; 283 char *ops;
278 new_flags |= geometrySet; 284 new_flags |= geometrySet;
279 285
280 strncpy (str, geom, n); 286 memcpy (str, geom, n);
281 str[n] = '\0'; 287 str[n] = '\0';
282 if (str[0] == ':') 288 if (str[0] == ':')
283 ops = &str[0]; 289 ops = &str[0];
284 else if (str[0] != 'x' && str[0] != 'X' && isalpha(str[0])) 290 else if (str[0] != 'x' && str[0] != 'X' && isalpha(str[0]))
285 ops = &str[0]; 291 ops = &str[0];
305 y = x; 311 y = x;
306 geom_flags |= YValue; 312 geom_flags |= YValue;
307 } 313 }
308 314
309 if (flags & geometrySet) 315 if (flags & geometrySet)
316 {
310 {/* new geometry is an adjustment to the old one ! */ 317 /* new geometry is an adjustment to the old one ! */
311 if ((geom_flags & WidthValue) && (geom_flags & HeightValue)) 318 if ((geom_flags & WidthValue) && (geom_flags & HeightValue))
312 { 319 {
313 if (w == 0 && h != 0) 320 if (w == 0 && h != 0)
314 { 321 {
315 w = h_scale; 322 w = h_scale;
331 } 338 }
332 } 339 }
333 else /* setting up geometry from scratch */ 340 else /* setting up geometry from scratch */
334 { 341 {
335 if (!(geom_flags & XValue)) 342 if (!(geom_flags & XValue))
343 {
336 {/* use default geometry - centered */ 344 /* use default geometry - centered */
337 x = y = defaultAlign; 345 x = y = defaultAlign;
338 } 346 }
339 else if (!(geom_flags & YValue)) 347 else if (!(geom_flags & YValue))
340 y = x; 348 y = x;
341 349
342 if ((geom_flags & (WidthValue|HeightValue)) == 0) 350 if ((geom_flags & (WidthValue|HeightValue)) == 0)
351 {
343 {/* use default geometry - scaled */ 352 /* use default geometry - scaled */
344 w = h = defaultScale; 353 w = h = defaultScale;
345 } 354 }
346 else if (geom_flags & WidthValue) 355 else if (geom_flags & WidthValue)
347 { 356 {
348 if (!(geom_flags & HeightValue)) 357 if (!(geom_flags & HeightValue))
351 else 360 else
352 w = h; 361 w = h;
353 } 362 }
354 } /* done parsing geometry string */ 363 } /* done parsing geometry string */
355 else if (!(flags & geometrySet)) 364 else if (!(flags & geometrySet))
365 {
356 { /* default geometry - scaled and centered */ 366 /* default geometry - scaled and centered */
357 x = y = defaultAlign; 367 x = y = defaultAlign;
358 w = h = defaultScale; 368 w = h = defaultScale;
359 } 369 }
360 370
361 if (!(flags & geometrySet)) 371 if (!(flags & geometrySet))
364 if (ops) 374 if (ops)
365 { 375 {
366 while (*ops) 376 while (*ops)
367 { 377 {
368 while (*ops == ':' || isspace(*ops)) ++ops; 378 while (*ops == ':' || isspace(*ops)) ++ops;
379
369# define CHECK_GEOM_OPS(op_str) (strncasecmp (ops, (op_str), sizeof(op_str)-1) == 0) 380# define CHECK_GEOM_OPS(op_str) (strncasecmp (ops, (op_str), sizeof (op_str) - 1) == 0)
370 if (CHECK_GEOM_OPS("tile")) 381 if (CHECK_GEOM_OPS ("tile"))
371 { 382 {
372 w = h = noScale; 383 w = h = noScale;
373 geom_flags |= WidthValue|HeightValue; 384 geom_flags |= WidthValue|HeightValue;
374 } 385 }
375 else if (CHECK_GEOM_OPS("propscale")) 386 else if (CHECK_GEOM_OPS ("propscale"))
376 { 387 {
377 if (w == 0 && h == 0) 388 if (w == 0 && h == 0)
378 { 389 {
379 w = windowScale; 390 w = windowScale;
380 geom_flags |= WidthValue; 391 geom_flags |= WidthValue;
381 } 392 }
382 new_flags |= propScale; 393 new_flags |= propScale;
383 } 394 }
384 else if (CHECK_GEOM_OPS("hscale")) 395 else if (CHECK_GEOM_OPS ("hscale"))
385 { 396 {
386 if (w == 0)
387 w = windowScale; 397 if (w == 0) w = windowScale;
398
388 h = noScale; 399 h = noScale;
389 geom_flags |= WidthValue|HeightValue; 400 geom_flags |= WidthValue|HeightValue;
390 } 401 }
391 else if (CHECK_GEOM_OPS("vscale")) 402 else if (CHECK_GEOM_OPS ("vscale"))
392 { 403 {
393 if (h == 0)
394 h = windowScale; 404 if (h == 0) h = windowScale;
405
395 w = noScale; 406 w = noScale;
396 geom_flags |= WidthValue|HeightValue; 407 geom_flags |= WidthValue|HeightValue;
397 } 408 }
398 else if (CHECK_GEOM_OPS("scale")) 409 else if (CHECK_GEOM_OPS ("scale"))
399 { 410 {
400 if (h == 0)
401 h = windowScale; 411 if (h == 0) h = windowScale;
402 if (w == 0)
403 w = windowScale; 412 if (w == 0) w = windowScale;
413
404 geom_flags |= WidthValue|HeightValue; 414 geom_flags |= WidthValue|HeightValue;
405 } 415 }
406 else if (CHECK_GEOM_OPS("auto")) 416 else if (CHECK_GEOM_OPS ("auto"))
407 { 417 {
408 w = h = windowScale; 418 w = h = windowScale;
409 x = y = centerAlign; 419 x = y = centerAlign;
410 geom_flags |= WidthValue|HeightValue|XValue|YValue; 420 geom_flags |= WidthValue|HeightValue|XValue|YValue;
411 } 421 }
412 else if (CHECK_GEOM_OPS("root")) 422 else if (CHECK_GEOM_OPS ("root"))
413 { 423 {
414 w = h = noScale; 424 w = h = noScale;
415 x = y = rootAlign; 425 x = y = rootAlign;
416 geom_flags |= WidthValue|HeightValue|XValue|YValue; 426 geom_flags |= WidthValue|HeightValue|XValue|YValue;
417 } 427 }
418# undef CHECK_GEOM_OPS 428# undef CHECK_GEOM_OPS
429
419 while (*ops != ':' && *ops != '\0') ++ops; 430 while (*ops != ':' && *ops != '\0') ++ops;
420 } /* done parsing ops */ 431 } /* done parsing ops */
421 } 432 }
422 433
423 if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) 434 if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) ++changed;
424 ++changed;
425 if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) 435 if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) ++changed;
426 ++changed;
427 if (check_set_align_value (geom_flags, XValue, h_align, x)) 436 if (check_set_align_value (geom_flags, XValue, h_align, x)) ++changed;
428 ++changed;
429 if (check_set_align_value (geom_flags, YValue, v_align, y)) 437 if (check_set_align_value (geom_flags, YValue, v_align, y)) ++changed;
430 ++changed;
431 } 438 }
432 439
433 if (new_flags != flags) 440 if (new_flags != flags)
434 { 441 {
435 flags = new_flags; 442 flags = new_flags;
436 changed++; 443 changed++;
437 } 444 }
445
438//fprintf( stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n", 446//fprintf (stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n",
439// flags, h_scale, v_scale, h_align, v_align); 447// flags, h_scale, v_scale, h_align, v_align);
440 return (changed > 0); 448 return (changed > 0);
441} 449}
442 450
443# ifdef HAVE_AFTERIMAGE 451# ifdef HAVE_AFTERIMAGE
445bgPixmap_t::render_asim (ASImage *background, ARGB32 background_tint) 453bgPixmap_t::render_asim (ASImage *background, ARGB32 background_tint)
446{ 454{
447 if (target == NULL) 455 if (target == NULL)
448 return false; 456 return false;
449 457
458 target->init_asv ();
459
460 ASImage *result = 0;
461
450 int target_width = (int)target->szHint.width; 462 int target_width = target->szHint.width;
451 int target_height = (int)target->szHint.height; 463 int target_height = target->szHint.height;
452 int new_pmap_width = target_width, new_pmap_height = target_height; 464 int new_pmap_width = target_width;
453 ASImage *result = NULL; 465 int new_pmap_height = target_height;
454 466
455 int x = 0; 467 int x = 0;
456 int y = 0; 468 int y = 0;
457 int w = h_scale * target_width / 100; 469 int w = h_scale * target_width / 100;
458 int h = v_scale * target_height / 100; 470 int h = v_scale * target_height / 100;
465 { 477 {
466 target->get_window_origin(x, y); 478 target->get_window_origin(x, y);
467 x = -x; 479 x = -x;
468 y = -y; 480 y = -y;
469 } 481 }
482
470 if (h_align != rootAlign) 483 if (h_align != rootAlign)
471 x = make_align_position (h_align, target_width, w > 0 ? w : (int)original_asim->width); 484 x = make_align_position (h_align, target_width, w > 0 ? w : (int)original_asim->width);
485
472 if (v_align != rootAlign) 486 if (v_align != rootAlign)
473 y = make_align_position (v_align, target_height, h > 0 ? h : (int)original_asim->height); 487 y = make_align_position (v_align, target_height, h > 0 ? h : (int)original_asim->height);
474 } 488 }
475 489
476 if (original_asim == NULL 490 if (!original_asim
477 || x >= target_width 491 || x >= target_width
478 || y >= target_height 492 || y >= target_height
479 || (w > 0 && x + w <= 0) 493 || (w > 0 && x + w <= 0)
480 || (h > 0 && y + h <= 0)) 494 || (h > 0 && y + h <= 0))
481 { 495 {
482 if (background) 496 if (background)
483 { 497 {
484 new_pmap_width = background->width; 498 new_pmap_width = background->width;
485 new_pmap_height = background->height; 499 new_pmap_height = background->height;
486 result = background; 500 result = background;
501
487 if (background_tint != TINT_LEAVE_SAME) 502 if (background_tint != TINT_LEAVE_SAME)
488 { 503 {
489 ASImage* tmp = tile_asimage (target->asv, background, 0, 0, 504 ASImage *tmp = tile_asimage (target->asv, background, 0, 0,
490 target_width, target_height, background_tint, 505 target_width, target_height, background_tint,
491 ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT); 506 ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT);
492 if (tmp) 507 if (tmp)
493 result = tmp; 508 result = tmp;
494 } 509 }
497 new_pmap_width = new_pmap_height = 0; 512 new_pmap_width = new_pmap_height = 0;
498 } 513 }
499 else 514 else
500 { 515 {
501 result = original_asim; 516 result = original_asim;
517
502 if ((w > 0 && w != original_asim->width) 518 if ((w > 0 && w != original_asim->width)
503 || (h > 0 && h != original_asim->height)) 519 || (h > 0 && h != original_asim->height))
504 { 520 {
505 result = scale_asimage (target->asv, original_asim, 521 result = scale_asimage (target->asv, original_asim,
506 w > 0 ? w : original_asim->width, 522 w > 0 ? w : original_asim->width,
507 h > 0 ? h : original_asim->height, 523 h > 0 ? h : original_asim->height,
508 background ? ASA_ASImage : ASA_XImage, 524 background ? ASA_ASImage : ASA_XImage,
509 100, ASIMAGE_QUALITY_DEFAULT); 525 100, ASIMAGE_QUALITY_DEFAULT);
510 } 526 }
527
511 if (background == NULL) 528 if (background == NULL)
529 {
512 {/* if tiling - pixmap has to be sized exactly as the image, 530 /* if tiling - pixmap has to be sized exactly as the image,
513 but there is no need to make it bigger then the window! */ 531 but there is no need to make it bigger than the window! */
514 if (h_scale == 0) 532 if (h_scale == 0)
515 new_pmap_width = min (result->width, target_width); 533 new_pmap_width = min (result->width, target_width);
516 if (v_scale == 0) 534 if (v_scale == 0)
517 new_pmap_height = min (result->height, target_height); 535 new_pmap_height = min (result->height, target_height);
518 /* we also need to tile our image in one or both directions */ 536 /* we also need to tile our image in one or both directions */
519 if (h_scale == 0 || v_scale == 0) 537 if (h_scale == 0 || v_scale == 0)
520 { 538 {
521 ASImage *tmp = tile_asimage (target->asv, result, 539 ASImage *tmp = tile_asimage (target->asv, result,
522 (h_scale > 0) ? 0 : (int)result->width - x, 540 (h_scale > 0) ? 0 : (int)result->width - x,
523 (v_scale > 0) ? 0 : (int)result->height - y, 541 (v_scale > 0) ? 0 : (int)result->height - y,
524 new_pmap_width, 542 new_pmap_width,
525 new_pmap_height, 543 new_pmap_height,
526 TINT_LEAVE_SAME, ASA_XImage, 544 TINT_LEAVE_SAME, ASA_XImage,
527 100, ASIMAGE_QUALITY_DEFAULT); 545 100, ASIMAGE_QUALITY_DEFAULT);
528 if (tmp) 546 if (tmp)
529 { 547 {
530 if (result != original_asim) 548 if (result != original_asim)
531 destroy_asimage (&result); 549 destroy_asimage (&result);
550
532 result = tmp; 551 result = tmp;
533 } 552 }
534 } 553 }
535 } 554 }
536 else 555 else
556 {
537 {/* if blending background and image - pixmap has to be sized same as target window */ 557 /* if blending background and image - pixmap has to be sized same as target window */
538 ASImageLayer *layers = create_image_layers (2); 558 ASImageLayer *layers = create_image_layers (2);
539 ASImage *merged_im = NULL; 559 ASImage *merged_im = NULL;
540 560
541 layers[0].im = background; 561 layers[0].im = background;
542 layers[0].clip_width = target_width; 562 layers[0].clip_width = target_width;
543 layers[0].clip_height = target_height; 563 layers[0].clip_height = target_height;
544 layers[0].tint = background_tint; 564 layers[0].tint = background_tint;
545 layers[1].im = result; 565 layers[1].im = result;
566
546 if (w <= 0) 567 if (w <= 0)
568 {
547 {/* tile horizontally */ 569 /* tile horizontally */
548 while (x > 0) x -= (int)result->width; 570 while (x > 0) x -= (int)result->width;
549 layers[1].dst_x = x; 571 layers[1].dst_x = x;
550 layers[1].clip_width = result->width+target_width; 572 layers[1].clip_width = result->width+target_width;
551 } 573 }
552 else 574 else
575 {
553 {/* clip horizontally */ 576 /* clip horizontally */
554 layers[1].dst_x = x; 577 layers[1].dst_x = x;
555 layers[1].clip_width = result->width; 578 layers[1].clip_width = result->width;
556 } 579 }
580
557 if (h <= 0) 581 if (h <= 0)
558 { 582 {
559 while (y > 0) y -= (int)result->height; 583 while (y > 0) y -= (int)result->height;
560 layers[1].dst_y = y; 584 layers[1].dst_y = y;
561 layers[1].clip_height = result->height + target_height; 585 layers[1].clip_height = result->height + target_height;
563 else 587 else
564 { 588 {
565 layers[1].dst_y = y; 589 layers[1].dst_y = y;
566 layers[1].clip_height = result->height; 590 layers[1].clip_height = result->height;
567 } 591 }
592
568 if (target->rs[Rs_blendtype]) 593 if (target->rs[Rs_blendtype])
569 { 594 {
570 layers[1].merge_scanlines = blend_scanlines_name2func (target->rs[Rs_blendtype]); 595 layers[1].merge_scanlines = blend_scanlines_name2func (target->rs[Rs_blendtype]);
571 if (layers[1].merge_scanlines == NULL) 596 if (layers[1].merge_scanlines == NULL)
572 layers[1].merge_scanlines = alphablend_scanlines; 597 layers[1].merge_scanlines = alphablend_scanlines;
573 } 598 }
599
574 ASImage *tmp = merge_layers (target->asv, layers, 2, target_width, target_height, 600 ASImage *tmp = merge_layers (target->asv, layers, 2, target_width, target_height,
575 ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT); 601 ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT);
602
576 if (tmp) 603 if (tmp)
577 { 604 {
578 if (result != original_asim) 605 if (result != original_asim)
579 destroy_asimage (&result); 606 destroy_asimage (&result);
607
580 result = tmp; 608 result = tmp;
581 } 609 }
610
582 free (layers); 611 free (layers);
583 } 612 }
584 } 613 }
585 TIMING_TEST_PRINT_RESULT (asim); 614 TIMING_TEST_PRINT_RESULT (asim);
586 615
615 644
616 int src_x = 0, src_y = 0, dst_x = 0, dst_y = 0; 645 int src_x = 0, src_y = 0, dst_x = 0, dst_y = 0;
617 int dst_width = result->width, dst_height = result->height; 646 int dst_width = result->width, dst_height = result->height;
618 if (background == NULL) 647 if (background == NULL)
619 { 648 {
620 if (h_scale > 0)
621 src_x = make_clip_rectangle (x, result->width, new_pmap_width, dst_x, dst_width); 649 if (h_scale > 0) src_x = make_clip_rectangle (x, result->width , new_pmap_width , dst_x, dst_width );
622 if (v_scale > 0)
623 src_y = make_clip_rectangle (y, result->height, new_pmap_height, dst_y, dst_height); 650 if (v_scale > 0) src_y = make_clip_rectangle (y, result->height, new_pmap_height, dst_y, dst_height);
624 651
625 if (dst_x > 0 || dst_y > 0 652 if (dst_x > 0 || dst_y > 0
626 || dst_x + dst_width < new_pmap_width 653 || dst_x + dst_width < new_pmap_width
627 || dst_y + dst_height < new_pmap_height) 654 || dst_y + dst_height < new_pmap_height)
628 {
629 XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); 655 XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height);
630 }
631 } 656 }
632 657
633 /* put result on pixmap */ 658 /* put result on pixmap */
634 if (dst_x < new_pmap_width && dst_y < new_pmap_height) 659 if (dst_x < new_pmap_width && dst_y < new_pmap_height)
635 asimage2drawable (target->asv, pixmap, result, gc, src_x, src_y, dst_x, dst_y, dst_width, dst_height, True); 660 asimage2drawable (target->asv, pixmap, result, gc, src_x, src_y, dst_x, dst_y, dst_width, dst_height, True);
646# endif /* HAVE_AFTERIMAGE */ 671# endif /* HAVE_AFTERIMAGE */
647 672
648bool 673bool
649bgPixmap_t::set_file (const char *file) 674bgPixmap_t::set_file (const char *file)
650{ 675{
651 char *f;
652
653 assert (file != NULL); 676 assert (file);
654 677
655 if (*file != '\0') 678 if (*file)
656 { 679 {
657# ifdef HAVE_AFTERIMAGE 680# ifdef HAVE_AFTERIMAGE
658 if (target->asimman == NULL) 681 if (!target->asimman)
659 target->asimman = create_generic_imageman (target->rs[Rs_path]); 682 target->asimman = create_generic_imageman (target->rs[Rs_path]);
660 if ((f = strchr (file, ';')) == NULL) 683
661 original_asim = get_asimage (target->asimman, file, 0xFFFFFFFF, 100); 684 if (const char *p = strchr (file, ';'))
662 else
663 { 685 {
664 size_t len = f - file; 686 size_t len = p - file;
665 f = (char *)malloc (len + 1); 687 char *f = (char *)malloc (len + 1);
666 strncpy (f, file, len); 688 memcpy (f, file, len);
667 f[len] = '\0'; 689 f[len] = '\0';
668 original_asim = get_asimage (target->asimman, f, 0xFFFFFFFF, 100); 690 original_asim = get_asimage (target->asimman, f, 0xFFFFFFFF, 100);
669 free (f); 691 free (f);
670 } 692 }
693 else
694 original_asim = get_asimage (target->asimman, file, 0xFFFFFFFF, 100);
695
671 return (original_asim != NULL); 696 return original_asim;
672# endif 697# endif
673 } 698 }
699
674 return false; 700 return false;
675} 701}
676 702
677# endif /* BG_IMAGE_FROM_FILE */ 703# endif /* BG_IMAGE_FROM_FILE */
678 704
683 if (!(flags & isTransparent)) 709 if (!(flags & isTransparent))
684 { 710 {
685 flags |= isTransparent; 711 flags |= isTransparent;
686 return true; 712 return true;
687 } 713 }
714
688 return false; 715 return false;
689} 716}
690 717
691bool 718bool
692bgPixmap_t::set_blur_radius (const char *geom) 719bgPixmap_t::set_blur_radius (const char *geom)
773 unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade); 800 unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade);
774 tint = new_tint; 801 tint = new_tint;
775 flags = (flags & ~tintFlags) | new_flags | tintSet; 802 flags = (flags & ~tintFlags) | new_flags | tintSet;
776 return true; 803 return true;
777 } 804 }
805
778 return false; 806 return false;
779} 807}
780 808
781bool 809bool
782bgPixmap_t::unset_tint () 810bgPixmap_t::unset_tint ()
786 if (new_flags != (flags & tintFlags)) 814 if (new_flags != (flags & tintFlags))
787 { 815 {
788 flags = (flags&~tintFlags)|new_flags; 816 flags = (flags&~tintFlags)|new_flags;
789 return true; 817 return true;
790 } 818 }
819
791 return false; 820 return false;
792} 821}
793 822
794bool 823bool
795bgPixmap_t::set_shade (const char *shade_str) 824bgPixmap_t::set_shade (const char *shade_str)
796{ 825{
797 int new_shade = (shade_str) ? atoi (shade_str) : 0; 826 int new_shade = (shade_str) ? atoi (shade_str) : 0;
798 827
799 if (new_shade < 0 && new_shade > -100) 828 if (new_shade < 0 && new_shade > -100)
800 new_shade = 200 - (100 + new_shade); 829 new_shade = 200 - (100 + new_shade);
801 else if (new_shade == 100) 830 else if (new_shade == 100)
802 new_shade = 0; 831 new_shade = 0;
803 832
804 if (new_shade != shade) 833 if (new_shade != shade)
805 { 834 {
806 unsigned long new_flags = compute_tint_shade_flags ((flags & tintSet) ? &tint : NULL, new_shade); 835 unsigned long new_flags = compute_tint_shade_flags ((flags & tintSet) ? &tint : NULL, new_shade);
807 shade = new_shade; 836 shade = new_shade;
808 flags = (flags & (~tintFlags | tintSet)) | new_flags; 837 flags = (flags & (~tintFlags | tintSet)) | new_flags;
809 return true; 838 return true;
810 } 839 }
840
811 return false; 841 return false;
812} 842}
813 843
814/* make_transparency_pixmap() 844/* make_transparency_pixmap()
815 * Builds a pixmap sized the same as terminal window, with depth same as the root window 845 * Builds a pixmap sized the same as terminal window, with depth same as the root window
822 unsigned long result = 0; 852 unsigned long result = 0;
823 853
824 if (target == NULL) 854 if (target == NULL)
825 return 0; 855 return 0;
826 856
827 /* root dimentions may change from call to call - but Display structure should 857 /* root dimensions may change from call to call - but Display structure should
828 * be always up-to-date, so let's use it : 858 * be always up-to-date, so let's use it :
829 */ 859 */
830 Window root = target->display->root; 860 Window root = target->display->root;
831 int screen = target->display->screen; 861 int screen = target->display->screen;
832 Display *dpy = target->dpy; 862 Display *dpy = target->dpy;
845 if (sx + window_width <= 0 || sy + window_height <= 0 875 if (sx + window_width <= 0 || sy + window_height <= 0
846 || sx >= root_width || sy >= root_height) 876 || sx >= root_width || sy >= root_height)
847 return 0; 877 return 0;
848 878
849 if (root_pixmap != None) 879 if (root_pixmap != None)
880 {
850 {/* we want to validate the pixmap and get it's size at the same time : */ 881 /* we want to validate the pixmap and get it's size at the same time : */
851 int junk; 882 int junk;
852 unsigned int ujunk; 883 unsigned int ujunk;
853 /* root pixmap may be bad - allow a error */ 884 /* root pixmap may be bad - allow a error */
854 target->allowedxerror = -1; 885 target->allowedxerror = -1;
855 886
864 895
865 if (tiled_root_pmap == None) /* something really bad happened - abort */ 896 if (tiled_root_pmap == None) /* something really bad happened - abort */
866 return 0; 897 return 0;
867 898
868 if (root_pixmap == None) 899 if (root_pixmap == None)
900 {
869 { /* use tricks to obtain the root background image :*/ 901 /* use tricks to obtain the root background image :*/
870 /* we want to create Overrideredirect window overlapping out window 902 /* we want to create Overrideredirect window overlapping out window
871 with background type of Parent Relative and then grab it */ 903 with background type of Parent Relative and then grab it */
872 XSetWindowAttributes attr; 904 XSetWindowAttributes attr;
873 Window src; 905 Window src;
874 bool success = false; 906 bool success = false;
889 XGrabServer (dpy); 921 XGrabServer (dpy);
890 XMapRaised (dpy, src); 922 XMapRaised (dpy, src);
891 XSync (dpy, False); 923 XSync (dpy, False);
892 924
893 /* XSync should get window where it's properly exposed, 925 /* XSync should get window where it's properly exposed,
894 * but to be on the safe side - let's check for the actuall event to arrive : */ 926 * but to be on the safe side - let's check for the actual event to arrive : */
895 while (XCheckWindowEvent (dpy, src, ExposureMask, &event)) 927 while (XCheckWindowEvent (dpy, src, ExposureMask, &event))
896 ++ev_count; 928 ++ev_count;
897 929
898 if (ev_count > 0); 930 if (ev_count > 0);
931 {
899 { /* hooray! - we can grab the image! */ 932 /* hooray! - we can grab the image! */
900 gc = XCreateGC (dpy, root, 0, NULL); 933 gc = XCreateGC (dpy, root, 0, NULL);
901 if (gc) 934 if (gc)
902 { 935 {
903 XCopyArea (dpy, src, tiled_root_pmap, gc, 0, 0, window_width, window_height, 0, 0); 936 XCopyArea (dpy, src, tiled_root_pmap, gc, 0, 0, window_width, window_height, 0, 0);
904 success = true; 937 success = true;
905 } 938 }
906 } 939 }
940
907 XDestroyWindow (dpy, src); 941 XDestroyWindow (dpy, src);
908 XUngrabServer (dpy); 942 XUngrabServer (dpy);
909 //fprintf (stderr, "%s:%d: ev_count = %d\n", __FUNCTION__, __LINE__, ev_count); 943 //fprintf (stderr, "%s:%d: ev_count = %d\n", __FUNCTION__, __LINE__, ev_count);
910 } 944 }
911 945
916 } 950 }
917 else 951 else
918 result |= transpPmapTiled; 952 result |= transpPmapTiled;
919 } 953 }
920 else 954 else
955 {
921 {/* strightforward pixmap copy */ 956 /* straightforward pixmap copy */
922 gcv.tile = root_pixmap; 957 gcv.tile = root_pixmap;
923 gcv.fill_style = FillTiled; 958 gcv.fill_style = FillTiled;
924 959
925 while (sx < 0) sx += (int)root_width; 960 while (sx < 0) sx += (int)root_width;
926 while (sy < 0) sy += (int)root_height; 961 while (sy < 0) sy += (int)root_height;
974 { 1009 {
975 c.r = (c.r * shade) / 100; 1010 c.r = (c.r * shade) / 100;
976 c.g = (c.g * shade) / 100; 1011 c.g = (c.g * shade) / 100;
977 c.b = (c.b * shade) / 100; 1012 c.b = (c.b * shade) / 100;
978 } 1013 }
979 else if( shade > 100 && shade < 200) 1014 else if (shade > 100 && shade < 200)
980 { 1015 {
981 c.r = (c.r * (200 - shade)) / 100; 1016 c.r = (c.r * (200 - shade)) / 100;
982 c.g = (c.g * (200 - shade)) / 100; 1017 c.g = (c.g * (200 - shade)) / 100;
983 c.b = (c.b * (200 - shade)) / 100; 1018 c.b = (c.b * (200 - shade)) / 100;
984 } 1019 }
1030 mask_c.blue = 0xffff - c.b; 1065 mask_c.blue = 0xffff - c.b;
1031 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1); 1066 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1);
1032 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, window_width, window_height); 1067 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, window_width, window_height);
1033 result |= transpPmapTinted; 1068 result |= transpPmapTinted;
1034 } 1069 }
1070
1035 XRenderFreePicture (dpy, mask_pic); 1071 XRenderFreePicture (dpy, mask_pic);
1036 XRenderFreePicture (dpy, overlay_pic); 1072 XRenderFreePicture (dpy, overlay_pic);
1037 XRenderFreePicture (dpy, back_pic); 1073 XRenderFreePicture (dpy, back_pic);
1038# if DO_TIMING_TEST 1074# if DO_TIMING_TEST
1039 XSync (dpy, False); 1075 XSync (dpy, False);
1061} 1097}
1062 1098
1063bool 1099bool
1064bgPixmap_t::set_root_pixmap () 1100bgPixmap_t::set_root_pixmap ()
1065{ 1101{
1066 Pixmap new_root_pixmap = None;
1067
1068 new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID); 1102 Pixmap new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID);
1069 if (new_root_pixmap == None) 1103 if (new_root_pixmap == None)
1070 new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID); 1104 new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID);
1071 1105
1072 if (new_root_pixmap != root_pixmap) 1106 if (new_root_pixmap != root_pixmap)
1073 { 1107 {
1074 root_pixmap = new_root_pixmap; 1108 root_pixmap = new_root_pixmap;
1075 return true; 1109 return true;
1076 } 1110 }
1111
1077 return false; 1112 return false;
1078} 1113}
1079# endif /* ENABLE_TRANSPARENCY */ 1114# endif /* ENABLE_TRANSPARENCY */
1080 1115
1081# ifndef HAVE_AFTERIMAGE 1116# ifndef HAVE_AFTERIMAGE
1082static void ShadeXImage(rxvt_term *term, XImage* srcImage, int shade, int rm, int gm, int bm); 1117static void ShadeXImage(rxvt_term *term, XImage *srcImage, int shade, int rm, int gm, int bm);
1083# endif 1118# endif
1084
1085 1119
1086bool 1120bool
1087bgPixmap_t::render () 1121bgPixmap_t::render ()
1088{ 1122{
1089 unsigned long background_flags = 0; 1123 unsigned long background_flags = 0;
1091 if (target == NULL) 1125 if (target == NULL)
1092 return false; 1126 return false;
1093 1127
1094 TIMING_TEST_START (tp); 1128 TIMING_TEST_START (tp);
1095 1129
1096 invalidate(); 1130 invalidate ();
1097# ifdef ENABLE_TRANSPARENCY 1131# ifdef ENABLE_TRANSPARENCY
1098 if (flags & isTransparent) 1132 if (flags & isTransparent)
1099 { 1133 {
1100 /* we need to re-generate transparency pixmap in that case ! */ 1134 /* we need to re-generate transparency pixmap in that case ! */
1101 background_flags = make_transparency_pixmap (); 1135 background_flags = make_transparency_pixmap ();
1110 XImage *result = NULL; 1144 XImage *result = NULL;
1111# ifdef HAVE_AFTERIMAGE 1145# ifdef HAVE_AFTERIMAGE
1112 if (original_asim 1146 if (original_asim
1113 || (background_flags & transpTransformations) != (flags & transpTransformations)) 1147 || (background_flags & transpTransformations) != (flags & transpTransformations))
1114 { 1148 {
1149 target->init_asv ();
1150
1115 ASImage *background = NULL; 1151 ASImage *background = NULL;
1116 ARGB32 as_tint = TINT_LEAVE_SAME; 1152 ARGB32 as_tint = TINT_LEAVE_SAME;
1117 if (background_flags) 1153 if (background_flags)
1118 background = pixmap2ximage (target->asv, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, 100); 1154 background = pixmap2ximage (target->asv, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, 100);
1119 1155
1120# ifdef ENABLE_TRANSPARENCY 1156# ifdef ENABLE_TRANSPARENCY
1121 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) 1157 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded))
1122 { 1158 {
1123 ShadingInfo as_shade; 1159 ShadingInfo as_shade;
1130 as_shade.tintColor.green = c.g; 1166 as_shade.tintColor.green = c.g;
1131 as_shade.tintColor.blue = c.b; 1167 as_shade.tintColor.blue = c.b;
1132 1168
1133 as_tint = shading2tint32 (&as_shade); 1169 as_tint = shading2tint32 (&as_shade);
1134 } 1170 }
1171
1135 if (!(background_flags & transpPmapBlured) && (flags & blurNeeded) && background != NULL) 1172 if (!(background_flags & transpPmapBlured) && (flags & blurNeeded) && background != NULL)
1136 { 1173 {
1137 ASImage* tmp = blur_asimage_gauss (target->asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF, 1174 ASImage *tmp = blur_asimage_gauss (target->asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF,
1138 (original_asim == NULL || tint == TINT_LEAVE_SAME)?ASA_XImage:ASA_ASImage, 1175 (original_asim == NULL || tint == TINT_LEAVE_SAME)?ASA_XImage:ASA_ASImage,
1139 100, ASIMAGE_QUALITY_DEFAULT); 1176 100, ASIMAGE_QUALITY_DEFAULT);
1140 if (tmp) 1177 if (tmp)
1141 { 1178 {
1142 destroy_asimage (&background); 1179 destroy_asimage (&background);
1146# endif 1183# endif
1147 1184
1148 if (render_asim (background, as_tint)) 1185 if (render_asim (background, as_tint))
1149 flags = flags & ~isInvalid; 1186 flags = flags & ~isInvalid;
1150 if (background) 1187 if (background)
1151 destroy_asimage (&background); 1188 destroy_asimage (&background);
1152 } 1189 }
1153 else if (background_flags && pmap_depth != target->depth) 1190 else if (background_flags && pmap_depth != target->depth)
1191 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap);
1192
1193# elif !XFT /* our own client-side tinting */
1194
1195 /* ATTENTION: We ASSUME that XFT will let us do all the tinting necessary server-side.
1196 This may need to be changed in need_client_side_rendering() logic is altered !!! */
1197
1198 if (background_flags && (flags & isInvalid))
1154 { 1199 {
1155 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); 1200 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap);
1156 }
1157 1201
1158# elif !XFT /* our own client-side tinting */
1159
1160 /* ATTENTION: We ASSUME that XFT will let us do all the tinting neccessary server-side.
1161 This may need to be changed in need_client_side_rendering() logic is altered !!! */
1162
1163 if (background_flags && (flags & isInvalid))
1164 {
1165 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap);
1166 if (result != NULL && !(background_flags & transpPmapTinted) && (flags & tintNeeded)) 1202 if (result != NULL && !(background_flags & transpPmapTinted) && (flags & tintNeeded))
1167 { 1203 {
1168 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 1204 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1169 if (flags & tintSet) 1205 if (flags & tintSet)
1170 tint.get (c); 1206 tint.get (c);
1171 ShadeXImage (target, result, shade, c.r, c.g, c.b); 1207 ShadeXImage (target, result, shade, c.r, c.g, c.b);
1172 } 1208 }
1173 } 1209 }
1174# endif /* HAVE_AFTERIMAGE */ 1210# endif /* HAVE_AFTERIMAGE */
1175 1211
1176 if (result != NULL) 1212 if (result)
1177 { 1213 {
1178 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); 1214 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL);
1215
1179 if (gc) 1216 if (gc)
1180 { 1217 {
1181 if (/*pmap_depth != target->depth &&*/ pixmap != None) 1218 if (/*pmap_depth != target->depth &&*/ pixmap != None)
1182 { 1219 {
1183 XFreePixmap (target->dpy, pixmap); 1220 XFreePixmap (target->dpy, pixmap);
1184 pixmap = None; 1221 pixmap = None;
1185 } 1222 }
1223
1186 if (pixmap == None) 1224 if (pixmap == None)
1187 { 1225 {
1188 pixmap = XCreatePixmap (target->dpy, target->vt, result->width, result->height, target->depth); 1226 pixmap = XCreatePixmap (target->dpy, target->vt, result->width, result->height, target->depth);
1189 pmap_width = result->width; 1227 pmap_width = result->width;
1190 pmap_height = result->height; 1228 pmap_height = result->height;
1191 pmap_depth = target->depth; 1229 pmap_depth = target->depth;
1192 } 1230 }
1231
1193 if (pmap_depth != result->depth) 1232 if (pmap_depth != result->depth)
1233 {
1194 { /* Bad Match error will ensue ! stupid X !!!! */ 1234 /* Bad Match error will ensue ! stupid X !!!! */
1195 if( result->depth == 24 && pmap_depth == 32) 1235 if (result->depth == 24 && pmap_depth == 32)
1196 result->depth = 32; 1236 result->depth = 32;
1197 else if( result->depth == 32 && pmap_depth == 24) 1237 else if (result->depth == 32 && pmap_depth == 24)
1198 result->depth = 24; 1238 result->depth = 24;
1199 else 1239 else
1200 { 1240 {
1201 /* TODO: implement image recoding */ 1241 /* TODO: implement image recoding */
1202 } 1242 }
1203 } 1243 }
1244
1204 if (pmap_depth == result->depth) 1245 if (pmap_depth == result->depth)
1205 XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height); 1246 XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height);
1247
1206 XFreeGC (target->dpy, gc); 1248 XFreeGC (target->dpy, gc);
1207 flags = flags & ~isInvalid; 1249 flags = flags & ~isInvalid;
1208 } 1250 }
1251
1209 XDestroyImage (result); 1252 XDestroyImage (result);
1210 } 1253 }
1211 1254
1212 if (flags & isInvalid) 1255 if (flags & isInvalid)
1213 { 1256 {
1217 pixmap = None; 1260 pixmap = None;
1218 } 1261 }
1219 } 1262 }
1220 1263
1221 apply (); 1264 apply ();
1265
1266 XSync (target->dpy, False);
1267 valid_since = ev::now ();
1222 1268
1223 TIMING_TEST_PRINT_RESULT (tp); 1269 TIMING_TEST_PRINT_RESULT (tp);
1224 1270
1225 return true; 1271 return true;
1226} 1272}
1235# ifdef ENABLE_TRANSPARENCY 1281# ifdef ENABLE_TRANSPARENCY
1236 root_depth = DefaultDepthOfScreen (ScreenOfDisplay (target->dpy, target->display->screen)); 1282 root_depth = DefaultDepthOfScreen (ScreenOfDisplay (target->dpy, target->display->screen));
1237# endif 1283# endif
1238 return true; 1284 return true;
1239 } 1285 }
1286
1240 return false; 1287 return false;
1241} 1288}
1242 1289
1243void 1290void
1244bgPixmap_t::apply() 1291bgPixmap_t::apply ()
1245{ 1292{
1246 if (target) 1293 if (target)
1247 { 1294 {
1248 flags &= ~isVtOrigin; 1295 flags &= ~isVtOrigin;
1296
1249 if (pixmap != None) 1297 if (pixmap != None)
1298 {
1250 { /* set target's background to pixmap */ 1299 /* set target's background to pixmap */
1251# ifdef ENABLE_TRANSPARENCY 1300# ifdef ENABLE_TRANSPARENCY
1252 if (flags & isTransparent) 1301 if (flags & isTransparent)
1253 { 1302 {
1254 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap); 1303 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap);
1255 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative); 1304 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative);
1256# if HAVE_SCROLLBARS 1305
1257 if (target->scrollBar.win) 1306 if (target->scrollBar.win)
1258 XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative); 1307 XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative);
1259# endif
1260 } 1308 }
1261 else 1309 else
1262# endif 1310# endif
1263 { 1311 {
1264 flags |= isVtOrigin; 1312 flags |= isVtOrigin;
1265 /* force old pixmap dereference in case it was transparent before :*/ 1313 /* force old pixmap dereference in case it was transparent before :*/
1266 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); 1314 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
1267 XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap); 1315 XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap);
1268 /* do we also need to set scrollbar's background here ? */ 1316 /* do we also need to set scrollbar's background here ? */
1269# if HAVE_SCROLLBARS 1317
1270 if (target->scrollBar.win) 1318 if (target->scrollBar.win)
1271 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); 1319 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1272# endif
1273 } 1320 }
1274 } 1321 }
1275 else 1322 else
1323 {
1276 { /* set target background to a pixel */ 1324 /* set target background to a pixel */
1277 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); 1325 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
1278 XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); 1326 XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]);
1279 /* do we also need to set scrollbar's background here ? */ 1327 /* do we also need to set scrollbar's background here ? */
1280# if HAVE_SCROLLBARS
1281 if (target->scrollBar.win) 1328 if (target->scrollBar.win)
1282 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); 1329 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1283# endif
1284 } 1330 }
1331
1285 /* don't want Expose on the parent or vt. It is better to use 1332 /* don't want Expose on the parent or vt. It is better to use
1286 scr_touch or we get a great deal of flicker otherwise: */ 1333 scr_touch or we get a great deal of flicker otherwise: */
1287 XClearWindow (target->dpy, target->parent[0]); 1334 XClearWindow (target->dpy, target->parent[0]);
1288 1335
1289# if HAVE_SCROLLBARS 1336 if (target->scrollBar.state && target->scrollBar.win)
1290 if (target->scrollBar.win)
1291 { 1337 {
1292 target->scrollBar.setIdle (); 1338 target->scrollBar.state = STATE_IDLE;
1293 target->scrollbar_show (0); 1339 target->scrollBar.show (0);
1294 } 1340 }
1295# endif
1296 1341
1297 target->want_refresh = 1; 1342 target->want_refresh = 1;
1298 flags |= hasChanged; 1343 flags |= hasChanged;
1299 } 1344 }
1300} 1345}
1305/* taken from aterm-0.4.2 */ 1350/* taken from aterm-0.4.2 */
1306 1351
1307typedef uint32_t RUINT32T; 1352typedef uint32_t RUINT32T;
1308 1353
1309static void 1354static void
1310ShadeXImage(rxvt_term *term, XImage* srcImage, int shade, int rm, int gm, int bm) 1355ShadeXImage(rxvt_term *term, XImage *srcImage, int shade, int rm, int gm, int bm)
1311{ 1356{
1312 int sh_r, sh_g, sh_b; 1357 int sh_r, sh_g, sh_b;
1313 RUINT32T mask_r, mask_g, mask_b; 1358 RUINT32T mask_r, mask_g, mask_b;
1314 RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b; 1359 RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b;
1315 unsigned int lower_lim_r, lower_lim_g, lower_lim_b; 1360 unsigned int lower_lim_r, lower_lim_g, lower_lim_b;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines