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.1 by sasha, Wed Sep 12 20:29:24 2007 UTC vs.
Revision 1.16 by ayin, Mon Nov 26 11:20:13 2007 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-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
31 28
32#if DO_TIMING_TEST 29#if DO_TIMING_TEST
33#define TIMING_TEST_START(id) \ 30#define TIMING_TEST_START(id) \
34 struct timeval timing_test_##id##_stv;\ 31 struct timeval timing_test_##id##_stv;\
35 gettimeofday (&timing_test_##id##_stv, NULL); 32 gettimeofday (&timing_test_##id##_stv, NULL);
36 33
37#define TIMING_TEST_PRINT_RESULT(id) \ 34#define TIMING_TEST_PRINT_RESULT(id) \
38 do{ struct timeval tv;gettimeofday (&tv, NULL); tv.tv_sec -= (timing_test_##id##_stv).tv_sec;\ 35 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__,\ 36 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) 37 tv.tv_sec * 1000000 + tv.tv_usec - (timing_test_##id##_stv).tv_usec);}while (0)
41 38
87 * scale Scale both up and down 84 * scale Scale both up and down
88 * auto Same as 100x100+50+50 85 * auto Same as 100x100+50+50
89 */ 86 */
90 87
91#ifdef HAVE_BG_PIXMAP 88#ifdef HAVE_BG_PIXMAP
89bgPixmap_t::bgPixmap_t ()
90{
91#ifdef HAVE_AFTERIMAGE
92 original_asim = NULL;
93#endif
94#ifdef BG_IMAGE_FROM_FILE
95 h_scale = v_scale = 0;
96 h_align = v_align = 0;
97#endif
98 flags = 0;
99 pixmap = None;
100}
101
102void
103bgPixmap_t::destroy ()
104{
105#ifdef HAVE_AFTERIMAGE
106 if (original_asim)
107 safe_asimage_destroy (original_asim);
108#endif
109
110 if (pixmap && target)
111 XFreePixmap (target->dpy, pixmap);
112}
113
92bool 114bool
93bgPixmap_t::window_size_sensitive () 115bgPixmap_t::window_size_sensitive ()
94{ 116{
95# ifdef XPM_BACKGROUND
96# ifdef HAVE_AFTERIMAGE
97 if (original_asim != NULL)
98# endif
99 {
100 if (h_scale != 0 || v_scale != 0
101 || h_align != 0 || v_align != 0)
102 return true;
103 }
104# endif
105# ifdef ENABLE_TRANSPARENCY 117# ifdef ENABLE_TRANSPARENCY
106 if (flags & isTransparent) 118 if (flags & isTransparent)
107 return true; 119 return true;
108# endif 120# endif
121
122# ifdef BG_IMAGE_FROM_FILE
123# ifdef HAVE_AFTERIMAGE
124 if (original_asim != NULL)
125# endif
126 {
127 if (h_scale != 0 || v_scale != 0
128 || h_align != 0 || v_align != 0)
129 return true;
130 }
131# endif
132
109 return false; 133 return false;
110} 134}
135
136bool
137bgPixmap_t::window_position_sensitive ()
138{
139# ifdef ENABLE_TRANSPARENCY
140 if (flags & isTransparent)
141 return true;
142# endif
143
144# ifdef BG_IMAGE_FROM_FILE
145# ifdef HAVE_AFTERIMAGE
146 if (original_asim != NULL)
147# endif
148 {
149 if (h_align == rootAlign || v_align == rootAlign)
150 return true;
151 }
152# endif
153
154 return false;
155};
111 156
112bool bgPixmap_t::need_client_side_rendering () 157bool bgPixmap_t::need_client_side_rendering ()
113{ 158{
114# ifdef HAVE_AFTERIMAGE 159# ifdef HAVE_AFTERIMAGE
115 if (original_asim != NULL) 160 if (original_asim != NULL)
116 return true; 161 return true;
117# endif 162# endif
118# ifdef ENABLE_TRANSPARENCY 163# ifdef ENABLE_TRANSPARENCY
119 if (flags & isTransparent) 164 if (flags & isTransparent)
120 { 165 {
166# ifdef HAVE_AFTERIMAGE // can't blur without libAI anyways
121 if (((flags & blurNeeded) && !(flags & blurServerSide)) 167 if ((flags & blurNeeded) && !(flags & blurServerSide))
168 return true;
169# endif
122 || ((flags & tintNeeded) && !(flags & tintServerSide))) 170 if ((flags & tintNeeded) && !(flags & tintServerSide))
123 return true; 171 return true;
124 } 172 }
125# endif 173# endif
126 return false; 174 return false;
127} 175}
128 176
129# ifdef XPM_BACKGROUND 177# ifdef BG_IMAGE_FROM_FILE
130static inline bool 178static inline bool
131check_set_scale_value (int geom_flags, int flag, unsigned int &scale, unsigned int new_value) 179check_set_scale_value (int geom_flags, int flag, unsigned int &scale, unsigned int new_value)
132{ 180{
133 if (geom_flags & flag) 181 if (geom_flags & flag)
134 { 182 {
146static inline bool 194static inline bool
147check_set_align_value (int geom_flags, int flag, int &align, int new_value) 195check_set_align_value (int geom_flags, int flag, int &align, int new_value)
148{ 196{
149 if (geom_flags & flag) 197 if (geom_flags & flag)
150 { 198 {
199 if (new_value != bgPixmap_t::rootAlign)
200 {
151 if (new_value < -100) 201 if (new_value < -100)
152 new_value = -100; 202 new_value = -100;
153 else if (new_value > 200) 203 else if (new_value > 200)
154 new_value = 200; 204 new_value = 200;
205 }
155 if (new_value != align) 206 if (new_value != align)
156 { 207 {
157 align = new_value; 208 align = new_value;
158 return true; 209 return true;
159 } 210 }
297 else 348 else
298 w = h; 349 w = h;
299 } 350 }
300 } /* done parsing geometry string */ 351 } /* done parsing geometry string */
301 else if (!(flags & geometrySet)) 352 else if (!(flags & geometrySet))
353 {
302 { /* default geometry - scaled and centered */ 354 /* default geometry - scaled and centered */
303 x = y = defaultAlign; 355 x = y = defaultAlign;
304 w = h = defaultScale; 356 w = h = defaultScale;
305 } 357 }
306 358
307 if (!(flags & geometrySet)) 359 if (!(flags & geometrySet))
308 geom_flags |= WidthValue|HeightValue|XValue|YValue; 360 geom_flags |= WidthValue|HeightValue|XValue|YValue;
309 361
310 if (ops) 362 if (ops)
311 { 363 {
313 { 365 {
314 while (*ops == ':' || isspace(*ops)) ++ops; 366 while (*ops == ':' || isspace(*ops)) ++ops;
315# define CHECK_GEOM_OPS(op_str) (strncasecmp (ops, (op_str), sizeof(op_str)-1) == 0) 367# define CHECK_GEOM_OPS(op_str) (strncasecmp (ops, (op_str), sizeof(op_str)-1) == 0)
316 if (CHECK_GEOM_OPS("tile")) 368 if (CHECK_GEOM_OPS("tile"))
317 { 369 {
318 w = h = 0; 370 w = h = noScale;
319 geom_flags |= WidthValue|HeightValue; 371 geom_flags |= WidthValue|HeightValue;
320 } 372 }
321 else if (CHECK_GEOM_OPS("propscale")) 373 else if (CHECK_GEOM_OPS("propscale"))
322 { 374 {
323 if (w == 0 && h == 0) 375 if (w == 0 && h == 0)
324 { 376 {
325 w = 100; 377 w = windowScale;
326 geom_flags |= WidthValue; 378 geom_flags |= WidthValue;
327 } 379 }
328 new_flags |= propScale; 380 new_flags |= propScale;
329 } 381 }
330 else if (CHECK_GEOM_OPS("hscale")) 382 else if (CHECK_GEOM_OPS("hscale"))
331 { 383 {
332 if (w == 0) 384 if (w == 0)
333 w = 100; 385 w = windowScale;
334 h = 0; 386 h = noScale;
335 geom_flags |= WidthValue|HeightValue; 387 geom_flags |= WidthValue|HeightValue;
336 } 388 }
337 else if (CHECK_GEOM_OPS("vscale")) 389 else if (CHECK_GEOM_OPS("vscale"))
338 { 390 {
339 if (h == 0) 391 if (h == 0)
340 h = 100; 392 h = windowScale;
341 w = 0; 393 w = noScale;
342 geom_flags |= WidthValue|HeightValue; 394 geom_flags |= WidthValue|HeightValue;
343 } 395 }
344 else if (CHECK_GEOM_OPS("scale")) 396 else if (CHECK_GEOM_OPS("scale"))
345 { 397 {
346 if (h == 0) 398 if (h == 0)
347 h = 100; 399 h = windowScale;
348 if (w == 0) 400 if (w == 0)
349 w = 100; 401 w = windowScale;
350 geom_flags |= WidthValue|HeightValue; 402 geom_flags |= WidthValue|HeightValue;
351 } 403 }
352 else if (CHECK_GEOM_OPS("auto")) 404 else if (CHECK_GEOM_OPS("auto"))
353 { 405 {
406 w = h = windowScale;
407 x = y = centerAlign;
408 geom_flags |= WidthValue|HeightValue|XValue|YValue;
409 }
410 else if (CHECK_GEOM_OPS("root"))
411 {
354 w = h = 100; 412 w = h = noScale;
355 x = y = 50; 413 x = y = rootAlign;
356 geom_flags |= WidthValue|HeightValue|XValue|YValue; 414 geom_flags |= WidthValue|HeightValue|XValue|YValue;
357 } 415 }
358# undef CHECK_GEOM_OPS 416# undef CHECK_GEOM_OPS
359 while (*ops != ':' && *ops != '\0') ++ops; 417 while (*ops != ':' && *ops != '\0') ++ops;
360 } /* done parsing ops */ 418 } /* done parsing ops */
399 457
400 TIMING_TEST_START (asim); 458 TIMING_TEST_START (asim);
401 459
402 if (original_asim) 460 if (original_asim)
403 { 461 {
462 if (h_align == rootAlign || v_align == rootAlign)
463 {
464 target->get_window_origin(x, y);
465 x = -x;
466 y = -y;
467 }
468 if (h_align != rootAlign)
404 x = make_align_position (h_align, target_width, w > 0 ? w : (int)original_asim->width); 469 x = make_align_position (h_align, target_width, w > 0 ? w : (int)original_asim->width);
470 if (v_align != rootAlign)
405 y = make_align_position (v_align, target_height, h > 0 ? h : (int)original_asim->height); 471 y = make_align_position (v_align, target_height, h > 0 ? h : (int)original_asim->height);
406 } 472 }
407 473
408 if (original_asim == NULL 474 if (original_asim == NULL
409 || x >= target_width 475 || x >= target_width
410 || y >= target_height 476 || y >= target_height
432 { 498 {
433 result = original_asim; 499 result = original_asim;
434 if ((w > 0 && w != original_asim->width) 500 if ((w > 0 && w != original_asim->width)
435 || (h > 0 && h != original_asim->height)) 501 || (h > 0 && h != original_asim->height))
436 { 502 {
437 result = scale_asimage (target->asv, original_asim, 503 result = scale_asimage (target->asv, original_asim,
438 w > 0 ? w : original_asim->width, 504 w > 0 ? w : original_asim->width,
439 h > 0 ? h : original_asim->height, 505 h > 0 ? h : original_asim->height,
440 background ? ASA_ASImage : ASA_XImage, 506 background ? ASA_ASImage : ASA_XImage,
441 100, ASIMAGE_QUALITY_DEFAULT); 507 100, ASIMAGE_QUALITY_DEFAULT);
442 } 508 }
443 if (background == NULL) 509 if (background == NULL)
444 {/* if tiling - pixmap has to be sized exactly as the image */ 510 {/* if tiling - pixmap has to be sized exactly as the image,
511 but there is no need to make it bigger then the window! */
445 if (h_scale == 0) 512 if (h_scale == 0)
446 new_pmap_width = result->width; 513 new_pmap_width = min (result->width, target_width);
447 if (v_scale == 0) 514 if (v_scale == 0)
448 new_pmap_height = result->height; 515 new_pmap_height = min (result->height, target_height);
449 /* we also need to tile our image in one or both directions */ 516 /* we also need to tile our image in one or both directions */
450 if (h_scale == 0 || v_scale == 0) 517 if (h_scale == 0 || v_scale == 0)
451 { 518 {
452 ASImage *tmp = tile_asimage (target->asv, result, 519 ASImage *tmp = tile_asimage (target->asv, result,
453 (h_scale > 0) ? 0 : (int)result->width - x, 520 (h_scale > 0) ? 0 : (int)result->width - x,
454 (v_scale > 0) ? 0 : (int)result->height - y, 521 (v_scale > 0) ? 0 : (int)result->height - y,
522 new_pmap_width,
455 result->width, result->height, 523 new_pmap_height,
456 TINT_LEAVE_SAME, ASA_XImage, 524 TINT_LEAVE_SAME, ASA_XImage,
457 100, ASIMAGE_QUALITY_DEFAULT); 525 100, ASIMAGE_QUALITY_DEFAULT);
458 if (tmp) 526 if (tmp)
459 { 527 {
460 if (result != original_asim) 528 if (result != original_asim)
561 } 629 }
562 630
563 /* put result on pixmap */ 631 /* put result on pixmap */
564 if (dst_x < new_pmap_width && dst_y < new_pmap_height) 632 if (dst_x < new_pmap_width && dst_y < new_pmap_height)
565 asimage2drawable (target->asv, pixmap, result, gc, src_x, src_y, dst_x, dst_y, dst_width, dst_height, True); 633 asimage2drawable (target->asv, pixmap, result, gc, src_x, src_y, dst_x, dst_y, dst_width, dst_height, True);
566 634
567 if (result != background && result != original_asim) 635 if (result != background && result != original_asim)
568 destroy_asimage (&result); 636 destroy_asimage (&result);
569 637
570 XFreeGC (target->dpy, gc); 638 XFreeGC (target->dpy, gc);
571 TIMING_TEST_PRINT_RESULT (asim); 639 TIMING_TEST_PRINT_RESULT (asim);
597 f[len] = '\0'; 665 f[len] = '\0';
598 original_asim = get_asimage (target->asimman, f, 0xFFFFFFFF, 100); 666 original_asim = get_asimage (target->asimman, f, 0xFFFFFFFF, 100);
599 free (f); 667 free (f);
600 } 668 }
601 return (original_asim != NULL); 669 return (original_asim != NULL);
602# endif 670# endif
603 } 671 }
604 return false; 672 return false;
605} 673}
606 674
607# endif /* XPM_BACKGROUND */ 675# endif /* BG_IMAGE_FROM_FILE */
608 676
609# ifdef ENABLE_TRANSPARENCY 677# ifdef ENABLE_TRANSPARENCY
610bool 678bool
611bgPixmap_t::set_transparent () 679bgPixmap_t::set_transparent ()
612{ 680{
613 if (!(flags & isTransparent)) 681 if (!(flags & isTransparent))
614 { 682 {
615 flags |= isTransparent; 683 flags |= isTransparent;
640 if (v_blurRadius != vr) 708 if (v_blurRadius != vr)
641 { 709 {
642 ++changed; 710 ++changed;
643 v_blurRadius = vr; 711 v_blurRadius = vr;
644 } 712 }
645 713
646 if (v_blurRadius == 0 && h_blurRadius == 0) 714 if (v_blurRadius == 0 && h_blurRadius == 0)
647 flags &= ~blurNeeded; 715 flags &= ~blurNeeded;
648 else 716 else
649 flags |= blurNeeded; 717 flags |= blurNeeded;
650 718
654static inline unsigned long 722static inline unsigned long
655compute_tint_shade_flags (rxvt_color *tint, int shade) 723compute_tint_shade_flags (rxvt_color *tint, int shade)
656{ 724{
657 unsigned long flags = 0; 725 unsigned long flags = 0;
658 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 726 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
727 bool has_shade = (shade > 0 && shade < 100) || (shade > 100 && shade < 200);
659 728
660 if (tint) 729 if (tint)
661 { 730 {
662 tint->get (c); 731 tint->get (c);
663# define IS_COMPONENT_WHOLESOME(cmp) ((cmp) <= 0x000700 || (cmp) >= 0x00f700) 732# define IS_COMPONENT_WHOLESOME(cmp) ((cmp) <= 0x000700 || (cmp) >= 0x00f700)
664 if (IS_COMPONENT_WHOLESOME (c.r) 733 if (!has_shade && IS_COMPONENT_WHOLESOME (c.r)
665 && IS_COMPONENT_WHOLESOME (c.g) 734 && IS_COMPONENT_WHOLESOME (c.g)
666 && IS_COMPONENT_WHOLESOME (c.b)) 735 && IS_COMPONENT_WHOLESOME (c.b))
667 flags |= bgPixmap_t::tintWholesome; 736 flags |= bgPixmap_t::tintWholesome;
668# undef IS_COMPONENT_WHOLESOME 737# undef IS_COMPONENT_WHOLESOME
669 } 738 }
670 739
671 if ((shade > 0 && shade < 100) || (shade > 100 && shade < 200)) 740 if (has_shade)
672 flags |= bgPixmap_t::tintNeeded; 741 flags |= bgPixmap_t::tintNeeded;
673 else if (tint) 742 else if (tint)
674 { 743 {
675 if ((c.r > 0x000700 || c.g > 0x000700 || c.b > 0x000700) 744 if ((c.r > 0x000700 || c.g > 0x000700 || c.b > 0x000700)
676 && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700)) 745 && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700))
677 { 746 {
678 flags |= bgPixmap_t::tintNeeded; 747 flags |= bgPixmap_t::tintNeeded;
679 } 748 }
680 } 749 }
681 750
682 if (flags & bgPixmap_t::tintNeeded) 751 if (flags & bgPixmap_t::tintNeeded)
683 { 752 {
684 if (flags & bgPixmap_t::tintWholesome) 753 if (flags & bgPixmap_t::tintWholesome)
685 flags |= bgPixmap_t::tintServerSide; 754 flags |= bgPixmap_t::tintServerSide;
755 else
756 {
686#if XFT 757#if XFT
687 flags |= bgPixmap_t::tintServerSide; 758 flags |= bgPixmap_t::tintServerSide;
688#endif 759#endif
760 }
689 } 761 }
690 762
691 return flags; 763 return flags;
692} 764}
693 765
720bool 792bool
721bgPixmap_t::set_shade (const char *shade_str) 793bgPixmap_t::set_shade (const char *shade_str)
722{ 794{
723 int new_shade = (shade_str) ? atoi (shade_str) : 0; 795 int new_shade = (shade_str) ? atoi (shade_str) : 0;
724 796
797 if (new_shade < 0 && new_shade > -100)
798 new_shade = 200 - (100 + new_shade);
725 if (new_shade == 100) 799 else if (new_shade == 100)
726 new_shade = 0; 800 new_shade = 0;
727 801
728 if (new_shade != shade) 802 if (new_shade != shade)
729 { 803 {
730 unsigned long new_flags = compute_tint_shade_flags ((flags & tintSet) ? &tint : NULL, new_shade); 804 unsigned long new_flags = compute_tint_shade_flags ((flags & tintSet) ? &tint : NULL, new_shade);
731 shade = new_shade; 805 shade = new_shade;
732 flags = (flags & ~tintFlags) | new_flags; 806 flags = (flags & (~tintFlags | tintSet)) | new_flags;
733 return true; 807 return true;
734 } 808 }
735 return false; 809 return false;
736} 810}
737 811
738/* make_transparency_pixmap() 812/* make_transparency_pixmap()
739 * Builds a pixmap sized the same as terminal window, with depth same as the root window 813 * Builds a pixmap sized the same as terminal window, with depth same as the root window
740 * that pixmap contains tiled portion of the root pixmap that is supposed to be covered by 814 * that pixmap contains tiled portion of the root pixmap that is supposed to be covered by
741 * our window. 815 * our window.
742 */ 816 */
743unsigned long 817unsigned long
744bgPixmap_t::make_transparency_pixmap () 818bgPixmap_t::make_transparency_pixmap ()
745{ 819{
788 862
789 if (tiled_root_pmap == None) /* something really bad happened - abort */ 863 if (tiled_root_pmap == None) /* something really bad happened - abort */
790 return 0; 864 return 0;
791 865
792 if (root_pixmap == None) 866 if (root_pixmap == None)
867 {
793 { /* use tricks to obtain the root background image :*/ 868 /* use tricks to obtain the root background image :*/
794 /* we want to create Overrideredirect window overlapping out window 869 /* we want to create Overrideredirect window overlapping out window
795 with background type of Parent Relative and then grab it */ 870 with background type of Parent Relative and then grab it */
796 XSetWindowAttributes attr; 871 XSetWindowAttributes attr;
797 Window src; 872 Window src;
798 bool success = false; 873 bool success = false;
818 * but to be on the safe side - let's check for the actuall event to arrive : */ 893 * but to be on the safe side - let's check for the actuall event to arrive : */
819 while (XCheckWindowEvent (dpy, src, ExposureMask, &event)) 894 while (XCheckWindowEvent (dpy, src, ExposureMask, &event))
820 ++ev_count; 895 ++ev_count;
821 896
822 if (ev_count > 0); 897 if (ev_count > 0);
898 {
823 { /* hooray! - we can grab the image! */ 899 /* hooray! - we can grab the image! */
824 gc = XCreateGC (dpy, root, 0, NULL); 900 gc = XCreateGC (dpy, root, 0, NULL);
825 if (gc) 901 if (gc)
826 { 902 {
827 XCopyArea (dpy, src, tiled_root_pmap, gc, 0, 0, window_width, window_height, 0, 0); 903 XCopyArea (dpy, src, tiled_root_pmap, gc, 0, 0, window_width, window_height, 0, 0);
828 success = true; 904 success = true;
844 else 920 else
845 {/* strightforward pixmap copy */ 921 {/* strightforward pixmap copy */
846 gcv.tile = root_pixmap; 922 gcv.tile = root_pixmap;
847 gcv.fill_style = FillTiled; 923 gcv.fill_style = FillTiled;
848 924
849 while (sx < 0) sx += (int)window_width; 925 while (sx < 0) sx += (int)root_width;
850 while (sy < 0) sy += (int)window_height; 926 while (sy < 0) sy += (int)root_height;
851 927
852 gcv.ts_x_origin = -sx; 928 gcv.ts_x_origin = -sx;
853 gcv.ts_y_origin = -sy; 929 gcv.ts_y_origin = -sy;
854 gc = XCreateGC (dpy, root, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); 930 gc = XCreateGC (dpy, root, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv);
855 931
861 } 937 }
862 TIMING_TEST_PRINT_RESULT (tp); 938 TIMING_TEST_PRINT_RESULT (tp);
863 939
864 if (tiled_root_pmap != None) 940 if (tiled_root_pmap != None)
865 { 941 {
866 if (!need_client_side_rendering ()) 942 if (!need_client_side_rendering ())
867 { 943 {
868 if ((flags & tintNeeded)) 944 if ((flags & tintNeeded))
869 { 945 {
870 if (flags & tintWholesome) 946 if (flags & tintWholesome)
871 { 947 {
872 /* In this case we can tint image server-side getting significant 948 /* In this case we can tint image server-side getting significant
873 * performance improvements, as we eliminate XImage transfer 949 * performance improvements, as we eliminate XImage transfer
914 pf.direct.greenMask = 0xff; 990 pf.direct.greenMask = 0xff;
915 pf.direct.blueMask = 0xff; 991 pf.direct.blueMask = 0xff;
916 pf.direct.alphaMask = 0xff; 992 pf.direct.alphaMask = 0xff;
917 993
918 XRenderPictFormat *solid_format = XRenderFindFormat (dpy, 994 XRenderPictFormat *solid_format = XRenderFindFormat (dpy,
919 (PictFormatType| 995 (PictFormatType|
920 PictFormatDepth| 996 PictFormatDepth|
921 PictFormatRedMask| 997 PictFormatRedMask|
922 PictFormatGreenMask| 998 PictFormatGreenMask|
923 PictFormatBlueMask| 999 PictFormatBlueMask|
924 PictFormatAlphaMask), 1000 PictFormatAlphaMask),
925 &pf, 1001 &pf,
926 0); 1002 0);
927 XRenderPictFormat *root_format = XRenderFindVisualFormat (dpy, DefaultVisualOfScreen (ScreenOfDisplay (dpy, target->display->screen))); 1003 XRenderPictFormat *root_format = XRenderFindVisualFormat (dpy, DefaultVisualOfScreen (ScreenOfDisplay (dpy, target->display->screen)));
928 XRenderPictureAttributes pa ; 1004 XRenderPictureAttributes pa ;
929 1005
930 back_pic = XRenderCreatePicture (dpy, tiled_root_pmap, root_format, 0, &pa); 1006 back_pic = XRenderCreatePicture (dpy, tiled_root_pmap, root_format, 0, &pa);
931 1007
933 1009
934 Pixmap overlay_pmap = XCreatePixmap (dpy, root, 1, 1, 32); 1010 Pixmap overlay_pmap = XCreatePixmap (dpy, root, 1, 1, 32);
935 Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa); 1011 Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa);
936 XFreePixmap (dpy, overlay_pmap); 1012 XFreePixmap (dpy, overlay_pmap);
937 1013
938 pa.component_alpha = True; 1014 pa.component_alpha = True;
939 Pixmap mask_pmap = XCreatePixmap (dpy, root, 1, 1, 32); 1015 Pixmap mask_pmap = XCreatePixmap (dpy, root, 1, 1, 32);
940 Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat|CPComponentAlpha, &pa); 1016 Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat|CPComponentAlpha, &pa);
941 XFreePixmap (dpy, mask_pmap); 1017 XFreePixmap (dpy, mask_pmap);
942 1018
943 if (mask_pic && overlay_pic && back_pic) 1019 if (mask_pic && overlay_pic && back_pic)
945 XRenderColor mask_c; 1021 XRenderColor mask_c;
946 1022
947 memset (&mask_c, (shade > 100) ? 0xFF : 0x0, sizeof (mask_c)); 1023 memset (&mask_c, (shade > 100) ? 0xFF : 0x0, sizeof (mask_c));
948 mask_c.alpha = 0xffff; 1024 mask_c.alpha = 0xffff;
949 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); 1025 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1);
950 memset (&mask_c, 0x0, sizeof (mask_c)); 1026
951 mask_c.alpha = 0; 1027 mask_c.alpha = 0;
952 1028 mask_c.red = 0xffff - c.r;
953 if (c.r == c.b && c.b == c.g) /* pure shading */ 1029 mask_c.green = 0xffff - c.g;
954 { 1030 mask_c.blue = 0xffff - c.b;
955 mask_c.red = mask_c.green = mask_c.blue = 0xffff - c.r;
956 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1); 1031 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1);
957 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, window_width, window_height); 1032 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, window_width, window_height);
958 }
959 else
960 {
961 mask_c.red = 0xffff - c.r;
962 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1);
963 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, window_width, window_height);
964 mask_c.red = 0;
965 mask_c.green = 0xffff - c.g;
966 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1);
967 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, window_width, window_height);
968 mask_c.green = 0;
969 mask_c.blue = 0xffff - c.b;
970 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);
972 }
973 result |= transpPmapTinted; 1033 result |= transpPmapTinted;
974 } 1034 }
975 XRenderFreePicture (dpy, mask_pic); 1035 XRenderFreePicture (dpy, mask_pic);
976 XRenderFreePicture (dpy, overlay_pic); 1036 XRenderFreePicture (dpy, overlay_pic);
977 XRenderFreePicture (dpy, back_pic); 1037 XRenderFreePicture (dpy, back_pic);
978# if DO_TIMING_TEST 1038# if DO_TIMING_TEST
979 XSync (dpy, False); 1039 XSync (dpy, False);
980# endif 1040# endif
981# endif 1041# endif
982 } 1042 }
983 } 1043 }
984 } /* server side rendering completed */ 1044 } /* server side rendering completed */
985 1045
989 pixmap = tiled_root_pmap; 1049 pixmap = tiled_root_pmap;
990 pmap_width = window_width; 1050 pmap_width = window_width;
991 pmap_height = window_height; 1051 pmap_height = window_height;
992 pmap_depth = root_depth; 1052 pmap_depth = root_depth;
993 } 1053 }
994 1054
995 if (gc) 1055 if (gc)
996 XFreeGC (dpy, gc); 1056 XFreeGC (dpy, gc);
997 1057
998 TIMING_TEST_PRINT_RESULT (tp); 1058 TIMING_TEST_PRINT_RESULT (tp);
999 1059
1000 return result; 1060 return result;
1001} 1061}
1002 1062
1003bool 1063bool
1004bgPixmap_t::set_root_pixmap () 1064bgPixmap_t::set_root_pixmap ()
1005{ 1065{
1006 Pixmap new_root_pixmap = None; 1066 Pixmap new_root_pixmap = None;
1007 1067
1008 new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID); 1068 new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID);
1009 if (new_root_pixmap == None) 1069 if (new_root_pixmap == None)
1010 new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID); 1070 new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID);
1011 1071
1012 if (new_root_pixmap != root_pixmap) 1072 if (new_root_pixmap != root_pixmap)
1028{ 1088{
1029 unsigned long background_flags = 0; 1089 unsigned long background_flags = 0;
1030 1090
1031 if (target == NULL) 1091 if (target == NULL)
1032 return false; 1092 return false;
1093
1094 TIMING_TEST_START (tp);
1033 1095
1034 invalidate(); 1096 invalidate();
1035# ifdef ENABLE_TRANSPARENCY 1097# ifdef ENABLE_TRANSPARENCY
1036 if (flags & isTransparent) 1098 if (flags & isTransparent)
1037 { 1099 {
1090 } 1152 }
1091 else if (background_flags && pmap_depth != target->depth) 1153 else if (background_flags && pmap_depth != target->depth)
1092 { 1154 {
1093 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); 1155 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap);
1094 } 1156 }
1157
1095# else /* our own client-side tinting */ 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
1096 if (background_flags && (flags & isInvalid)) 1163 if (background_flags && (flags & isInvalid))
1097 { 1164 {
1098 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); 1165 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap);
1099 if (result != NULL && !(background_flags & transpPmapTinted) && (flags & tintNeeded)) 1166 if (result != NULL && !(background_flags & transpPmapTinted) && (flags & tintNeeded))
1100 { 1167 {
1122 pmap_width = result->width; 1189 pmap_width = result->width;
1123 pmap_height = result->height; 1190 pmap_height = result->height;
1124 pmap_depth = target->depth; 1191 pmap_depth = target->depth;
1125 } 1192 }
1126 if (pmap_depth != result->depth) 1193 if (pmap_depth != result->depth)
1194 {
1127 { /* Bad Match error will ensue ! stupid X !!!! */ 1195 /* Bad Match error will ensue ! stupid X !!!! */
1128 if( result->depth == 24 && pmap_depth == 32) 1196 if( result->depth == 24 && pmap_depth == 32)
1129 result->depth = 32; 1197 result->depth = 32;
1130 else if( result->depth == 32 && pmap_depth == 24) 1198 else if( result->depth == 32 && pmap_depth == 24)
1131 result->depth = 24; 1199 result->depth = 24;
1132 else 1200 else
1151 } 1219 }
1152 } 1220 }
1153 1221
1154 apply (); 1222 apply ();
1155 1223
1224 TIMING_TEST_PRINT_RESULT (tp);
1225
1156 return true; 1226 return true;
1157} 1227}
1158 1228
1159bool 1229bool
1160bgPixmap_t::set_target (rxvt_term *new_target) 1230bgPixmap_t::set_target (rxvt_term *new_target)
1161{ 1231{
1162 if (new_target) 1232 if (new_target)
1163 if (target != new_target) 1233 if (target != new_target)
1164 { 1234 {
1176{ 1246{
1177 if (target) 1247 if (target)
1178 { 1248 {
1179 flags &= ~isVtOrigin; 1249 flags &= ~isVtOrigin;
1180 if (pixmap != None) 1250 if (pixmap != None)
1251 {
1181 { /* set target's background to pixmap */ 1252 /* set target's background to pixmap */
1182# ifdef ENABLE_TRANSPARENCY 1253# ifdef ENABLE_TRANSPARENCY
1183 if (flags & isTransparent) 1254 if (flags & isTransparent)
1184 { 1255 {
1185 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap); 1256 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap);
1186 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative); 1257 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative);
1202 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); 1273 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1203# endif 1274# endif
1204 } 1275 }
1205 } 1276 }
1206 else 1277 else
1278 {
1207 { /* set target background to a pixel */ 1279 /* set target background to a pixel */
1208 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); 1280 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
1209 XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); 1281 XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]);
1210 /* do we also need to set scrollbar's background here ? */ 1282 /* do we also need to set scrollbar's background here ? */
1211# if HAVE_SCROLLBARS 1283# if HAVE_SCROLLBARS
1212 if (target->scrollBar.win) 1284 if (target->scrollBar.win)
1213 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); 1285 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1214# endif 1286# endif
1215 } 1287 }
1216 1288 /* don't want Expose on the parent or vt. It is better to use
1217 /* don't want Expose on the parent */ 1289 scr_touch or we get a great deal of flicker otherwise: */
1218 XClearArea (target->dpy, target->parent[0], 0, 0, 0, 0, False); 1290 XClearWindow (target->dpy, target->parent[0]);
1219 /* do want Expose on the vt, so we get refreshed properly */
1220 XClearArea (target->dpy, target->vt, 0, 0, 0, 0, True);
1221 1291
1222# if HAVE_SCROLLBARS 1292# if HAVE_SCROLLBARS
1223 if (target->scrollBar.win) 1293 if (target->scrollBar.win)
1224 { 1294 {
1225 target->scrollBar.setIdle (); 1295 target->scrollBar.setIdle ();
1226 target->scrollbar_show (0); 1296 target->scrollbar_show (0);
1227 } 1297 }
1228# endif 1298# endif
1229 }
1230}
1231 1299
1300 target->want_refresh = 1;
1301 flags |= hasChanged;
1302 }
1303}
1304
1232#endif /* HAVE_BG_PIXMAP */ 1305#endif /* HAVE_BG_PIXMAP */
1233 1306
1234#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) 1307#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) && !XFT
1235/* taken from aterm-0.4.2 */ 1308/* taken from aterm-0.4.2 */
1236 1309
1237typedef uint32_t RUINT32T; 1310typedef uint32_t RUINT32T;
1238 1311
1239static void 1312static void

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines