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.8 by ayin, Sat Oct 27 15:14:55 2007 UTC vs.
Revision 1.22 by sasha, Fri Jan 4 21:25:57 2008 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-2006 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
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{ struct timeval tv;gettimeofday (&tv, NULL); tv.tv_sec -= (timing_test_##id##_stv).tv_sec;\
39 fprintf (stderr, "%s: %s: %d: elapsed %ld usec\n", #id, __FILE__, __LINE__,\ 37 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) 38 tv.tv_sec * 1000000 + tv.tv_usec - (timing_test_##id##_stv).tv_usec);}while (0)
41 39
87 * scale Scale both up and down 85 * scale Scale both up and down
88 * auto Same as 100x100+50+50 86 * auto Same as 100x100+50+50
89 */ 87 */
90 88
91#ifdef HAVE_BG_PIXMAP 89#ifdef HAVE_BG_PIXMAP
92bgPixmap_t::bgPixmap_t() 90bgPixmap_t::bgPixmap_t ()
93{ 91{
94#ifdef HAVE_AFTERIMAGE 92#ifdef HAVE_AFTERIMAGE
95 original_asim = NULL; 93 original_asim = NULL;
96#endif 94#endif
97#ifdef BG_IMAGE_FROM_FILE 95#ifdef BG_IMAGE_FROM_FILE
98 h_scale = v_scale = 0; 96 h_scale = v_scale = 0;
99 h_align = v_align = 0; 97 h_align = v_align = 0;
100#endif 98#endif
101 flags = 0; 99 flags = 0;
102 pixmap = None; 100 pixmap = None;
101 valid_since = invalid_since = 0;
103} 102}
104 103
104void
105bgPixmap_t::destroy ()
106{
107#ifdef HAVE_AFTERIMAGE
108 if (original_asim)
109 safe_asimage_destroy (original_asim);
110#endif
111
112 if (pixmap && target)
113 XFreePixmap (target->dpy, pixmap);
114}
105 115
106bool 116bool
107bgPixmap_t::window_size_sensitive () 117bgPixmap_t::window_size_sensitive ()
108{ 118{
119# ifdef ENABLE_TRANSPARENCY
120 if (flags & isTransparent)
121 return true;
122# endif
123
109# ifdef BG_IMAGE_FROM_FILE 124# ifdef BG_IMAGE_FROM_FILE
110# ifdef HAVE_AFTERIMAGE 125# ifdef HAVE_AFTERIMAGE
111 if (original_asim != NULL) 126 if (original_asim != NULL)
112# endif 127# endif
113 { 128 {
114 if (h_scale != 0 || v_scale != 0 129 if (h_scale != 0 || v_scale != 0
115 || h_align != 0 || v_align != 0) 130 || h_align != 0 || v_align != 0)
116 return true; 131 return true;
117 } 132 }
118# endif 133# endif
134
135 return false;
136}
137
138bool
139bgPixmap_t::window_position_sensitive ()
140{
119# ifdef ENABLE_TRANSPARENCY 141# ifdef ENABLE_TRANSPARENCY
120 if (flags & isTransparent) 142 if (flags & isTransparent)
121 return true; 143 return true;
122# endif 144# endif
145
146# ifdef BG_IMAGE_FROM_FILE
147# ifdef HAVE_AFTERIMAGE
148 if (original_asim != NULL)
149# endif
150 {
151 if (h_align == rootAlign || v_align == rootAlign)
152 return true;
153 }
154# endif
155
123 return false; 156 return false;
124} 157};
125 158
126bool bgPixmap_t::need_client_side_rendering () 159bool bgPixmap_t::need_client_side_rendering ()
127{ 160{
128# ifdef HAVE_AFTERIMAGE 161# ifdef HAVE_AFTERIMAGE
129 if (original_asim != NULL) 162 if (original_asim != NULL)
163static inline bool 196static inline bool
164check_set_align_value (int geom_flags, int flag, int &align, int new_value) 197check_set_align_value (int geom_flags, int flag, int &align, int new_value)
165{ 198{
166 if (geom_flags & flag) 199 if (geom_flags & flag)
167 { 200 {
201 if (new_value != bgPixmap_t::rootAlign)
202 {
168 if (new_value < -100) 203 if (new_value < -100)
169 new_value = -100; 204 new_value = -100;
170 else if (new_value > 200) 205 else if (new_value > 200)
171 new_value = 200; 206 new_value = 200;
207 }
172 if (new_value != align) 208 if (new_value != align)
173 { 209 {
174 align = new_value; 210 align = new_value;
175 return true; 211 return true;
176 } 212 }
268 y = x; 304 y = x;
269 geom_flags |= YValue; 305 geom_flags |= YValue;
270 } 306 }
271 307
272 if (flags & geometrySet) 308 if (flags & geometrySet)
309 {
273 {/* new geometry is an adjustment to the old one ! */ 310 /* new geometry is an adjustment to the old one ! */
274 if ((geom_flags & WidthValue) && (geom_flags & HeightValue)) 311 if ((geom_flags & WidthValue) && (geom_flags & HeightValue))
275 { 312 {
276 if (w == 0 && h != 0) 313 if (w == 0 && h != 0)
277 { 314 {
278 w = h_scale; 315 w = h_scale;
294 } 331 }
295 } 332 }
296 else /* setting up geometry from scratch */ 333 else /* setting up geometry from scratch */
297 { 334 {
298 if (!(geom_flags & XValue)) 335 if (!(geom_flags & XValue))
336 {
299 {/* use default geometry - centered */ 337 /* use default geometry - centered */
300 x = y = defaultAlign; 338 x = y = defaultAlign;
301 } 339 }
302 else if (!(geom_flags & YValue)) 340 else if (!(geom_flags & YValue))
303 y = x; 341 y = x;
304 342
305 if ((geom_flags & (WidthValue|HeightValue)) == 0) 343 if ((geom_flags & (WidthValue|HeightValue)) == 0)
344 {
306 {/* use default geometry - scaled */ 345 /* use default geometry - scaled */
307 w = h = defaultScale; 346 w = h = defaultScale;
308 } 347 }
309 else if (geom_flags & WidthValue) 348 else if (geom_flags & WidthValue)
310 { 349 {
311 if (!(geom_flags & HeightValue)) 350 if (!(geom_flags & HeightValue))
314 else 353 else
315 w = h; 354 w = h;
316 } 355 }
317 } /* done parsing geometry string */ 356 } /* done parsing geometry string */
318 else if (!(flags & geometrySet)) 357 else if (!(flags & geometrySet))
358 {
319 { /* default geometry - scaled and centered */ 359 /* default geometry - scaled and centered */
320 x = y = defaultAlign; 360 x = y = defaultAlign;
321 w = h = defaultScale; 361 w = h = defaultScale;
322 } 362 }
323 363
324 if (!(flags & geometrySet)) 364 if (!(flags & geometrySet))
325 geom_flags |= WidthValue|HeightValue|XValue|YValue; 365 geom_flags |= WidthValue|HeightValue|XValue|YValue;
326 366
327 if (ops) 367 if (ops)
328 { 368 {
330 { 370 {
331 while (*ops == ':' || isspace(*ops)) ++ops; 371 while (*ops == ':' || isspace(*ops)) ++ops;
332# define CHECK_GEOM_OPS(op_str) (strncasecmp (ops, (op_str), sizeof(op_str)-1) == 0) 372# define CHECK_GEOM_OPS(op_str) (strncasecmp (ops, (op_str), sizeof(op_str)-1) == 0)
333 if (CHECK_GEOM_OPS("tile")) 373 if (CHECK_GEOM_OPS("tile"))
334 { 374 {
335 w = h = 0; 375 w = h = noScale;
336 geom_flags |= WidthValue|HeightValue; 376 geom_flags |= WidthValue|HeightValue;
337 } 377 }
338 else if (CHECK_GEOM_OPS("propscale")) 378 else if (CHECK_GEOM_OPS("propscale"))
339 { 379 {
340 if (w == 0 && h == 0) 380 if (w == 0 && h == 0)
341 { 381 {
342 w = 100; 382 w = windowScale;
343 geom_flags |= WidthValue; 383 geom_flags |= WidthValue;
344 } 384 }
345 new_flags |= propScale; 385 new_flags |= propScale;
346 } 386 }
347 else if (CHECK_GEOM_OPS("hscale")) 387 else if (CHECK_GEOM_OPS("hscale"))
348 { 388 {
349 if (w == 0) 389 if (w == 0)
350 w = 100; 390 w = windowScale;
351 h = 0; 391 h = noScale;
352 geom_flags |= WidthValue|HeightValue; 392 geom_flags |= WidthValue|HeightValue;
353 } 393 }
354 else if (CHECK_GEOM_OPS("vscale")) 394 else if (CHECK_GEOM_OPS("vscale"))
355 { 395 {
356 if (h == 0) 396 if (h == 0)
357 h = 100; 397 h = windowScale;
358 w = 0; 398 w = noScale;
359 geom_flags |= WidthValue|HeightValue; 399 geom_flags |= WidthValue|HeightValue;
360 } 400 }
361 else if (CHECK_GEOM_OPS("scale")) 401 else if (CHECK_GEOM_OPS("scale"))
362 { 402 {
363 if (h == 0) 403 if (h == 0)
364 h = 100; 404 h = windowScale;
365 if (w == 0) 405 if (w == 0)
366 w = 100; 406 w = windowScale;
367 geom_flags |= WidthValue|HeightValue; 407 geom_flags |= WidthValue|HeightValue;
368 } 408 }
369 else if (CHECK_GEOM_OPS("auto")) 409 else if (CHECK_GEOM_OPS("auto"))
370 { 410 {
411 w = h = windowScale;
412 x = y = centerAlign;
413 geom_flags |= WidthValue|HeightValue|XValue|YValue;
414 }
415 else if (CHECK_GEOM_OPS("root"))
416 {
371 w = h = 100; 417 w = h = noScale;
372 x = y = 50; 418 x = y = rootAlign;
373 geom_flags |= WidthValue|HeightValue|XValue|YValue; 419 geom_flags |= WidthValue|HeightValue|XValue|YValue;
374 } 420 }
375# undef CHECK_GEOM_OPS 421# undef CHECK_GEOM_OPS
376 while (*ops != ':' && *ops != '\0') ++ops; 422 while (*ops != ':' && *ops != '\0') ++ops;
377 } /* done parsing ops */ 423 } /* done parsing ops */
390 if (new_flags != flags) 436 if (new_flags != flags)
391 { 437 {
392 flags = new_flags; 438 flags = new_flags;
393 changed++; 439 changed++;
394 } 440 }
395//fprintf( stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n", 441//fprintf (stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n",
396// flags, h_scale, v_scale, h_align, v_align); 442// flags, h_scale, v_scale, h_align, v_align);
397 return (changed > 0); 443 return (changed > 0);
398} 444}
399 445
400# ifdef HAVE_AFTERIMAGE 446# ifdef HAVE_AFTERIMAGE
416 462
417 TIMING_TEST_START (asim); 463 TIMING_TEST_START (asim);
418 464
419 if (original_asim) 465 if (original_asim)
420 { 466 {
467 if (h_align == rootAlign || v_align == rootAlign)
468 {
469 target->get_window_origin(x, y);
470 x = -x;
471 y = -y;
472 }
473 if (h_align != rootAlign)
421 x = make_align_position (h_align, target_width, w > 0 ? w : (int)original_asim->width); 474 x = make_align_position (h_align, target_width, w > 0 ? w : (int)original_asim->width);
475 if (v_align != rootAlign)
422 y = make_align_position (v_align, target_height, h > 0 ? h : (int)original_asim->height); 476 y = make_align_position (v_align, target_height, h > 0 ? h : (int)original_asim->height);
423 } 477 }
424 478
425 if (original_asim == NULL 479 if (original_asim == NULL
426 || x >= target_width 480 || x >= target_width
427 || y >= target_height 481 || y >= target_height
449 { 503 {
450 result = original_asim; 504 result = original_asim;
451 if ((w > 0 && w != original_asim->width) 505 if ((w > 0 && w != original_asim->width)
452 || (h > 0 && h != original_asim->height)) 506 || (h > 0 && h != original_asim->height))
453 { 507 {
454 result = scale_asimage (target->asv, original_asim, 508 result = scale_asimage (target->asv, original_asim,
455 w > 0 ? w : original_asim->width, 509 w > 0 ? w : original_asim->width,
456 h > 0 ? h : original_asim->height, 510 h > 0 ? h : original_asim->height,
457 background ? ASA_ASImage : ASA_XImage, 511 background ? ASA_ASImage : ASA_XImage,
458 100, ASIMAGE_QUALITY_DEFAULT); 512 100, ASIMAGE_QUALITY_DEFAULT);
459 } 513 }
460 if (background == NULL) 514 if (background == NULL)
515 {
461 {/* if tiling - pixmap has to be sized exactly as the image */ 516 /* if tiling - pixmap has to be sized exactly as the image,
517 but there is no need to make it bigger then the window! */
462 if (h_scale == 0) 518 if (h_scale == 0)
463 new_pmap_width = result->width; 519 new_pmap_width = min (result->width, target_width);
464 if (v_scale == 0) 520 if (v_scale == 0)
465 new_pmap_height = result->height; 521 new_pmap_height = min (result->height, target_height);
466 /* we also need to tile our image in one or both directions */ 522 /* we also need to tile our image in one or both directions */
467 if (h_scale == 0 || v_scale == 0) 523 if (h_scale == 0 || v_scale == 0)
468 { 524 {
469 ASImage *tmp = tile_asimage (target->asv, result, 525 ASImage *tmp = tile_asimage (target->asv, result,
470 (h_scale > 0) ? 0 : (int)result->width - x, 526 (h_scale > 0) ? 0 : (int)result->width - x,
471 (v_scale > 0) ? 0 : (int)result->height - y, 527 (v_scale > 0) ? 0 : (int)result->height - y,
528 new_pmap_width,
472 result->width, result->height, 529 new_pmap_height,
473 TINT_LEAVE_SAME, ASA_XImage, 530 TINT_LEAVE_SAME, ASA_XImage,
474 100, ASIMAGE_QUALITY_DEFAULT); 531 100, ASIMAGE_QUALITY_DEFAULT);
475 if (tmp) 532 if (tmp)
476 { 533 {
477 if (result != original_asim) 534 if (result != original_asim)
479 result = tmp; 536 result = tmp;
480 } 537 }
481 } 538 }
482 } 539 }
483 else 540 else
541 {
484 {/* if blending background and image - pixmap has to be sized same as target window */ 542 /* if blending background and image - pixmap has to be sized same as target window */
485 ASImageLayer *layers = create_image_layers (2); 543 ASImageLayer *layers = create_image_layers (2);
486 ASImage *merged_im = NULL; 544 ASImage *merged_im = NULL;
487 545
488 layers[0].im = background; 546 layers[0].im = background;
489 layers[0].clip_width = target_width; 547 layers[0].clip_width = target_width;
490 layers[0].clip_height = target_height; 548 layers[0].clip_height = target_height;
491 layers[0].tint = background_tint; 549 layers[0].tint = background_tint;
492 layers[1].im = result; 550 layers[1].im = result;
493 if (w <= 0) 551 if (w <= 0)
552 {
494 {/* tile horizontally */ 553 /* tile horizontally */
495 while (x > 0) x -= (int)result->width; 554 while (x > 0) x -= (int)result->width;
496 layers[1].dst_x = x; 555 layers[1].dst_x = x;
497 layers[1].clip_width = result->width+target_width; 556 layers[1].clip_width = result->width+target_width;
498 } 557 }
499 else 558 else
559 {
500 {/* clip horizontally */ 560 /* clip horizontally */
501 layers[1].dst_x = x; 561 layers[1].dst_x = x;
502 layers[1].clip_width = result->width; 562 layers[1].clip_width = result->width;
503 } 563 }
504 if (h <= 0) 564 if (h <= 0)
505 { 565 {
578 } 638 }
579 639
580 /* put result on pixmap */ 640 /* put result on pixmap */
581 if (dst_x < new_pmap_width && dst_y < new_pmap_height) 641 if (dst_x < new_pmap_width && dst_y < new_pmap_height)
582 asimage2drawable (target->asv, pixmap, result, gc, src_x, src_y, dst_x, dst_y, dst_width, dst_height, True); 642 asimage2drawable (target->asv, pixmap, result, gc, src_x, src_y, dst_x, dst_y, dst_width, dst_height, True);
583 643
584 if (result != background && result != original_asim) 644 if (result != background && result != original_asim)
585 destroy_asimage (&result); 645 destroy_asimage (&result);
586 646
587 XFreeGC (target->dpy, gc); 647 XFreeGC (target->dpy, gc);
588 TIMING_TEST_PRINT_RESULT (asim); 648 TIMING_TEST_PRINT_RESULT (asim);
614 f[len] = '\0'; 674 f[len] = '\0';
615 original_asim = get_asimage (target->asimman, f, 0xFFFFFFFF, 100); 675 original_asim = get_asimage (target->asimman, f, 0xFFFFFFFF, 100);
616 free (f); 676 free (f);
617 } 677 }
618 return (original_asim != NULL); 678 return (original_asim != NULL);
619# endif 679# endif
620 } 680 }
621 return false; 681 return false;
622} 682}
623 683
624# endif /* BG_IMAGE_FROM_FILE */ 684# endif /* BG_IMAGE_FROM_FILE */
625 685
626# ifdef ENABLE_TRANSPARENCY 686# ifdef ENABLE_TRANSPARENCY
627bool 687bool
628bgPixmap_t::set_transparent () 688bgPixmap_t::set_transparent ()
629{ 689{
630 if (!(flags & isTransparent)) 690 if (!(flags & isTransparent))
631 { 691 {
632 flags |= isTransparent; 692 flags |= isTransparent;
657 if (v_blurRadius != vr) 717 if (v_blurRadius != vr)
658 { 718 {
659 ++changed; 719 ++changed;
660 v_blurRadius = vr; 720 v_blurRadius = vr;
661 } 721 }
662 722
663 if (v_blurRadius == 0 && h_blurRadius == 0) 723 if (v_blurRadius == 0 && h_blurRadius == 0)
664 flags &= ~blurNeeded; 724 flags &= ~blurNeeded;
665 else 725 else
666 flags |= blurNeeded; 726 flags |= blurNeeded;
667 727
694 && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700)) 754 && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700))
695 { 755 {
696 flags |= bgPixmap_t::tintNeeded; 756 flags |= bgPixmap_t::tintNeeded;
697 } 757 }
698 } 758 }
699 759
700 if (flags & bgPixmap_t::tintNeeded) 760 if (flags & bgPixmap_t::tintNeeded)
701 { 761 {
702 if (flags & bgPixmap_t::tintWholesome) 762 if (flags & bgPixmap_t::tintWholesome)
703 flags |= bgPixmap_t::tintServerSide; 763 flags |= bgPixmap_t::tintServerSide;
704 else 764 else
720 unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade); 780 unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade);
721 tint = new_tint; 781 tint = new_tint;
722 flags = (flags & ~tintFlags) | new_flags | tintSet; 782 flags = (flags & ~tintFlags) | new_flags | tintSet;
723 return true; 783 return true;
724 } 784 }
785
725 return false; 786 return false;
726} 787}
727 788
728bool 789bool
729bgPixmap_t::unset_tint () 790bgPixmap_t::unset_tint ()
733 if (new_flags != (flags & tintFlags)) 794 if (new_flags != (flags & tintFlags))
734 { 795 {
735 flags = (flags&~tintFlags)|new_flags; 796 flags = (flags&~tintFlags)|new_flags;
736 return true; 797 return true;
737 } 798 }
799
738 return false; 800 return false;
739} 801}
740 802
741bool 803bool
742bgPixmap_t::set_shade (const char *shade_str) 804bgPixmap_t::set_shade (const char *shade_str)
743{ 805{
744 int new_shade = (shade_str) ? atoi (shade_str) : 0; 806 int new_shade = (shade_str) ? atoi (shade_str) : 0;
745 807
808 if (new_shade < 0 && new_shade > -100)
809 new_shade = 200 - (100 + new_shade);
746 if (new_shade == 100) 810 else if (new_shade == 100)
747 new_shade = 0; 811 new_shade = 0;
748 812
749 if (new_shade != shade) 813 if (new_shade != shade)
750 { 814 {
751 unsigned long new_flags = compute_tint_shade_flags ((flags & tintSet) ? &tint : NULL, new_shade); 815 unsigned long new_flags = compute_tint_shade_flags ((flags & tintSet) ? &tint : NULL, new_shade);
752 shade = new_shade; 816 shade = new_shade;
753 flags = (flags & (~tintFlags | tintSet)) | new_flags; 817 flags = (flags & (~tintFlags | tintSet)) | new_flags;
754 return true; 818 return true;
755 } 819 }
820
756 return false; 821 return false;
757} 822}
758 823
759/* make_transparency_pixmap() 824/* make_transparency_pixmap()
760 * Builds a pixmap sized the same as terminal window, with depth same as the root window 825 * Builds a pixmap sized the same as terminal window, with depth same as the root window
761 * that pixmap contains tiled portion of the root pixmap that is supposed to be covered by 826 * that pixmap contains tiled portion of the root pixmap that is supposed to be covered by
762 * our window. 827 * our window.
763 */ 828 */
764unsigned long 829unsigned long
765bgPixmap_t::make_transparency_pixmap () 830bgPixmap_t::make_transparency_pixmap ()
766{ 831{
790 if (sx + window_width <= 0 || sy + window_height <= 0 855 if (sx + window_width <= 0 || sy + window_height <= 0
791 || sx >= root_width || sy >= root_height) 856 || sx >= root_width || sy >= root_height)
792 return 0; 857 return 0;
793 858
794 if (root_pixmap != None) 859 if (root_pixmap != None)
860 {
795 {/* we want to validate the pixmap and get it's size at the same time : */ 861 /* we want to validate the pixmap and get it's size at the same time : */
796 int junk; 862 int junk;
797 unsigned int ujunk; 863 unsigned int ujunk;
798 /* root pixmap may be bad - allow a error */ 864 /* root pixmap may be bad - allow a error */
799 target->allowedxerror = -1; 865 target->allowedxerror = -1;
800 866
809 875
810 if (tiled_root_pmap == None) /* something really bad happened - abort */ 876 if (tiled_root_pmap == None) /* something really bad happened - abort */
811 return 0; 877 return 0;
812 878
813 if (root_pixmap == None) 879 if (root_pixmap == None)
880 {
814 { /* use tricks to obtain the root background image :*/ 881 /* use tricks to obtain the root background image :*/
815 /* we want to create Overrideredirect window overlapping out window 882 /* we want to create Overrideredirect window overlapping out window
816 with background type of Parent Relative and then grab it */ 883 with background type of Parent Relative and then grab it */
817 XSetWindowAttributes attr; 884 XSetWindowAttributes attr;
818 Window src; 885 Window src;
819 bool success = false; 886 bool success = false;
834 XGrabServer (dpy); 901 XGrabServer (dpy);
835 XMapRaised (dpy, src); 902 XMapRaised (dpy, src);
836 XSync (dpy, False); 903 XSync (dpy, False);
837 904
838 /* XSync should get window where it's properly exposed, 905 /* XSync should get window where it's properly exposed,
839 * but to be on the safe side - let's check for the actuall event to arrive : */ 906 * but to be on the safe side - let's check for the actual event to arrive : */
840 while (XCheckWindowEvent (dpy, src, ExposureMask, &event)) 907 while (XCheckWindowEvent (dpy, src, ExposureMask, &event))
841 ++ev_count; 908 ++ev_count;
842 909
843 if (ev_count > 0); 910 if (ev_count > 0);
911 {
844 { /* hooray! - we can grab the image! */ 912 /* hooray! - we can grab the image! */
845 gc = XCreateGC (dpy, root, 0, NULL); 913 gc = XCreateGC (dpy, root, 0, NULL);
846 if (gc) 914 if (gc)
847 { 915 {
848 XCopyArea (dpy, src, tiled_root_pmap, gc, 0, 0, window_width, window_height, 0, 0); 916 XCopyArea (dpy, src, tiled_root_pmap, gc, 0, 0, window_width, window_height, 0, 0);
849 success = true; 917 success = true;
850 } 918 }
851 } 919 }
920
852 XDestroyWindow (dpy, src); 921 XDestroyWindow (dpy, src);
853 XUngrabServer (dpy); 922 XUngrabServer (dpy);
854 //fprintf (stderr, "%s:%d: ev_count = %d\n", __FUNCTION__, __LINE__, ev_count); 923 //fprintf (stderr, "%s:%d: ev_count = %d\n", __FUNCTION__, __LINE__, ev_count);
855 } 924 }
856 925
861 } 930 }
862 else 931 else
863 result |= transpPmapTiled; 932 result |= transpPmapTiled;
864 } 933 }
865 else 934 else
935 {
866 {/* strightforward pixmap copy */ 936 /* strightforward pixmap copy */
867 gcv.tile = root_pixmap; 937 gcv.tile = root_pixmap;
868 gcv.fill_style = FillTiled; 938 gcv.fill_style = FillTiled;
869 939
870 while (sx < 0) sx += (int)root_width; 940 while (sx < 0) sx += (int)root_width;
871 while (sy < 0) sy += (int)root_height; 941 while (sy < 0) sy += (int)root_height;
882 } 952 }
883 TIMING_TEST_PRINT_RESULT (tp); 953 TIMING_TEST_PRINT_RESULT (tp);
884 954
885 if (tiled_root_pmap != None) 955 if (tiled_root_pmap != None)
886 { 956 {
887 if (!need_client_side_rendering ()) 957 if (!need_client_side_rendering ())
888 { 958 {
889 if ((flags & tintNeeded)) 959 if ((flags & tintNeeded))
890 { 960 {
891 if (flags & tintWholesome) 961 if (flags & tintWholesome)
892 { 962 {
893 /* In this case we can tint image server-side getting significant 963 /* In this case we can tint image server-side getting significant
894 * performance improvements, as we eliminate XImage transfer 964 * performance improvements, as we eliminate XImage transfer
919 { 989 {
920 c.r = (c.r * shade) / 100; 990 c.r = (c.r * shade) / 100;
921 c.g = (c.g * shade) / 100; 991 c.g = (c.g * shade) / 100;
922 c.b = (c.b * shade) / 100; 992 c.b = (c.b * shade) / 100;
923 } 993 }
924 else if( shade > 100 && shade < 200) 994 else if (shade > 100 && shade < 200)
925 { 995 {
926 c.r = (c.r * (200 - shade)) / 100; 996 c.r = (c.r * (200 - shade)) / 100;
927 c.g = (c.g * (200 - shade)) / 100; 997 c.g = (c.g * (200 - shade)) / 100;
928 c.b = (c.b * (200 - shade)) / 100; 998 c.b = (c.b * (200 - shade)) / 100;
929 } 999 }
954 1024
955 Pixmap overlay_pmap = XCreatePixmap (dpy, root, 1, 1, 32); 1025 Pixmap overlay_pmap = XCreatePixmap (dpy, root, 1, 1, 32);
956 Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa); 1026 Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa);
957 XFreePixmap (dpy, overlay_pmap); 1027 XFreePixmap (dpy, overlay_pmap);
958 1028
959 pa.component_alpha = True; 1029 pa.component_alpha = True;
960 Pixmap mask_pmap = XCreatePixmap (dpy, root, 1, 1, 32); 1030 Pixmap mask_pmap = XCreatePixmap (dpy, root, 1, 1, 32);
961 Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat|CPComponentAlpha, &pa); 1031 Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat|CPComponentAlpha, &pa);
962 XFreePixmap (dpy, mask_pmap); 1032 XFreePixmap (dpy, mask_pmap);
963 1033
964 if (mask_pic && overlay_pic && back_pic) 1034 if (mask_pic && overlay_pic && back_pic)
975 mask_c.blue = 0xffff - c.b; 1045 mask_c.blue = 0xffff - c.b;
976 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1); 1046 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); 1047 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, window_width, window_height);
978 result |= transpPmapTinted; 1048 result |= transpPmapTinted;
979 } 1049 }
1050
980 XRenderFreePicture (dpy, mask_pic); 1051 XRenderFreePicture (dpy, mask_pic);
981 XRenderFreePicture (dpy, overlay_pic); 1052 XRenderFreePicture (dpy, overlay_pic);
982 XRenderFreePicture (dpy, back_pic); 1053 XRenderFreePicture (dpy, back_pic);
983# if DO_TIMING_TEST 1054# if DO_TIMING_TEST
984 XSync (dpy, False); 1055 XSync (dpy, False);
985# endif 1056# endif
986# endif 1057# endif
987 } 1058 }
988 } 1059 }
989 } /* server side rendering completed */ 1060 } /* server side rendering completed */
990 1061
994 pixmap = tiled_root_pmap; 1065 pixmap = tiled_root_pmap;
995 pmap_width = window_width; 1066 pmap_width = window_width;
996 pmap_height = window_height; 1067 pmap_height = window_height;
997 pmap_depth = root_depth; 1068 pmap_depth = root_depth;
998 } 1069 }
999 1070
1000 if (gc) 1071 if (gc)
1001 XFreeGC (dpy, gc); 1072 XFreeGC (dpy, gc);
1002 1073
1003 TIMING_TEST_PRINT_RESULT (tp); 1074 TIMING_TEST_PRINT_RESULT (tp);
1004 1075
1005 return result; 1076 return result;
1006} 1077}
1007 1078
1008bool 1079bool
1009bgPixmap_t::set_root_pixmap () 1080bgPixmap_t::set_root_pixmap ()
1010{ 1081{
1011 Pixmap new_root_pixmap = None;
1012
1013 new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID); 1082 Pixmap new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID);
1014 if (new_root_pixmap == None) 1083 if (new_root_pixmap == None)
1015 new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID); 1084 new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID);
1016 1085
1017 if (new_root_pixmap != root_pixmap) 1086 if (new_root_pixmap != root_pixmap)
1018 { 1087 {
1019 root_pixmap = new_root_pixmap; 1088 root_pixmap = new_root_pixmap;
1020 return true; 1089 return true;
1021 } 1090 }
1091
1022 return false; 1092 return false;
1023} 1093}
1024# endif /* ENABLE_TRANSPARENCY */ 1094# endif /* ENABLE_TRANSPARENCY */
1025 1095
1026# ifndef HAVE_AFTERIMAGE 1096# ifndef HAVE_AFTERIMAGE
1027static void ShadeXImage(rxvt_term *term, XImage* srcImage, int shade, int rm, int gm, int bm); 1097static void ShadeXImage(rxvt_term *term, XImage* srcImage, int shade, int rm, int gm, int bm);
1028# endif 1098# endif
1029
1030 1099
1031bool 1100bool
1032bgPixmap_t::render () 1101bgPixmap_t::render ()
1033{ 1102{
1034 unsigned long background_flags = 0; 1103 unsigned long background_flags = 0;
1116 ShadeXImage (target, result, shade, c.r, c.g, c.b); 1185 ShadeXImage (target, result, shade, c.r, c.g, c.b);
1117 } 1186 }
1118 } 1187 }
1119# endif /* HAVE_AFTERIMAGE */ 1188# endif /* HAVE_AFTERIMAGE */
1120 1189
1121 if (result != NULL) 1190 if (result)
1122 { 1191 {
1123 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); 1192 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL);
1193
1124 if (gc) 1194 if (gc)
1125 { 1195 {
1126 if (/*pmap_depth != target->depth &&*/ pixmap != None) 1196 if (/*pmap_depth != target->depth &&*/ pixmap != None)
1127 { 1197 {
1128 XFreePixmap (target->dpy, pixmap); 1198 XFreePixmap (target->dpy, pixmap);
1129 pixmap = None; 1199 pixmap = None;
1130 } 1200 }
1201
1131 if (pixmap == None) 1202 if (pixmap == None)
1132 { 1203 {
1133 pixmap = XCreatePixmap (target->dpy, target->vt, result->width, result->height, target->depth); 1204 pixmap = XCreatePixmap (target->dpy, target->vt, result->width, result->height, target->depth);
1134 pmap_width = result->width; 1205 pmap_width = result->width;
1135 pmap_height = result->height; 1206 pmap_height = result->height;
1136 pmap_depth = target->depth; 1207 pmap_depth = target->depth;
1137 } 1208 }
1209
1138 if (pmap_depth != result->depth) 1210 if (pmap_depth != result->depth)
1211 {
1139 { /* Bad Match error will ensue ! stupid X !!!! */ 1212 /* Bad Match error will ensue ! stupid X !!!! */
1140 if( result->depth == 24 && pmap_depth == 32) 1213 if (result->depth == 24 && pmap_depth == 32)
1141 result->depth = 32; 1214 result->depth = 32;
1142 else if( result->depth == 32 && pmap_depth == 24) 1215 else if (result->depth == 32 && pmap_depth == 24)
1143 result->depth = 24; 1216 result->depth = 24;
1144 else 1217 else
1145 { 1218 {
1146 /* TODO: implement image recoding */ 1219 /* TODO: implement image recoding */
1147 } 1220 }
1148 } 1221 }
1222
1149 if (pmap_depth == result->depth) 1223 if (pmap_depth == result->depth)
1150 XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height); 1224 XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height);
1225
1151 XFreeGC (target->dpy, gc); 1226 XFreeGC (target->dpy, gc);
1152 flags = flags & ~isInvalid; 1227 flags = flags & ~isInvalid;
1153 } 1228 }
1229
1154 XDestroyImage (result); 1230 XDestroyImage (result);
1155 } 1231 }
1156 1232
1157 if (flags & isInvalid) 1233 if (flags & isInvalid)
1158 { 1234 {
1163 } 1239 }
1164 } 1240 }
1165 1241
1166 apply (); 1242 apply ();
1167 1243
1244 XSync (target->dpy, False);
1245 valid_since = ev::now ();
1246
1168 TIMING_TEST_PRINT_RESULT (tp); 1247 TIMING_TEST_PRINT_RESULT (tp);
1169 1248
1170 return true; 1249 return true;
1171} 1250}
1172 1251
1173bool 1252bool
1174bgPixmap_t::set_target (rxvt_term *new_target) 1253bgPixmap_t::set_target (rxvt_term *new_target)
1175{ 1254{
1176 if (new_target) 1255 if (new_target)
1177 if (target != new_target) 1256 if (target != new_target)
1178 { 1257 {
1184 } 1263 }
1185 return false; 1264 return false;
1186} 1265}
1187 1266
1188void 1267void
1189bgPixmap_t::apply() 1268bgPixmap_t::apply ()
1190{ 1269{
1191 if (target) 1270 if (target)
1192 { 1271 {
1193 flags &= ~isVtOrigin; 1272 flags &= ~isVtOrigin;
1194 if (pixmap != None) 1273 if (pixmap != None)
1274 {
1195 { /* set target's background to pixmap */ 1275 /* set target's background to pixmap */
1196# ifdef ENABLE_TRANSPARENCY 1276# ifdef ENABLE_TRANSPARENCY
1197 if (flags & isTransparent) 1277 if (flags & isTransparent)
1198 { 1278 {
1199 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap); 1279 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap);
1200 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative); 1280 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative);
1216 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); 1296 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1217# endif 1297# endif
1218 } 1298 }
1219 } 1299 }
1220 else 1300 else
1301 {
1221 { /* set target background to a pixel */ 1302 /* set target background to a pixel */
1222 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); 1303 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
1223 XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); 1304 XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]);
1224 /* do we also need to set scrollbar's background here ? */ 1305 /* do we also need to set scrollbar's background here ? */
1225# if HAVE_SCROLLBARS 1306# if HAVE_SCROLLBARS
1226 if (target->scrollBar.win) 1307 if (target->scrollBar.win)
1227 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); 1308 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1228# endif 1309# endif
1229 } 1310 }
1230 /* don't want Expose on the parent or vt. It is better to use 1311 /* don't want Expose on the parent or vt. It is better to use
1231 scr_touch or we get a great deal of flicker otherwise: */ 1312 scr_touch or we get a great deal of flicker otherwise: */
1232 XClearWindow (target->dpy, target->parent[0]); 1313 XClearWindow (target->dpy, target->parent[0]);
1233 1314
1234# if HAVE_SCROLLBARS 1315# if HAVE_SCROLLBARS
1235 if (target->scrollBar.win) 1316 if (target->scrollBar.win)
1242 target->want_refresh = 1; 1323 target->want_refresh = 1;
1243 flags |= hasChanged; 1324 flags |= hasChanged;
1244 } 1325 }
1245} 1326}
1246 1327
1247#endif /* HAVE_BG_PIXMAP */ 1328#endif /* HAVE_BG_PIXMAP */
1248 1329
1249#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) && !XFT 1330#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) && !XFT
1250/* taken from aterm-0.4.2 */ 1331/* taken from aterm-0.4.2 */
1251 1332
1252typedef uint32_t RUINT32T; 1333typedef uint32_t RUINT32T;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines