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.3 by sasha, Wed Sep 12 22:12:54 2007 UTC vs.
Revision 1.17 by ayin, Wed Dec 5 08:46:27 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
92bgPixmap_t::bgPixmap_t() 89bgPixmap_t::bgPixmap_t ()
93{ 90{
94#ifdef HAVE_AFTERIMAGE 91#ifdef HAVE_AFTERIMAGE
95 original_asim = NULL; 92 original_asim = NULL;
96#endif 93#endif
97#ifdef BG_IMAGE_FROM_FILE 94#ifdef BG_IMAGE_FROM_FILE
100#endif 97#endif
101 flags = 0; 98 flags = 0;
102 pixmap = None; 99 pixmap = None;
103} 100}
104 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}
105 113
106bool 114bool
107bgPixmap_t::window_size_sensitive () 115bgPixmap_t::window_size_sensitive ()
108{ 116{
117# ifdef ENABLE_TRANSPARENCY
118 if (flags & isTransparent)
119 return true;
120# endif
121
109# ifdef BG_IMAGE_FROM_FILE 122# ifdef BG_IMAGE_FROM_FILE
110# ifdef HAVE_AFTERIMAGE 123# ifdef HAVE_AFTERIMAGE
111 if (original_asim != NULL) 124 if (original_asim != NULL)
112# endif 125# endif
113 { 126 {
114 if (h_scale != 0 || v_scale != 0 127 if (h_scale != 0 || v_scale != 0
115 || h_align != 0 || v_align != 0) 128 || h_align != 0 || v_align != 0)
116 return true; 129 return true;
117 } 130 }
118# endif 131# endif
132
133 return false;
134}
135
136bool
137bgPixmap_t::window_position_sensitive ()
138{
119# ifdef ENABLE_TRANSPARENCY 139# ifdef ENABLE_TRANSPARENCY
120 if (flags & isTransparent) 140 if (flags & isTransparent)
121 return true; 141 return true;
122# endif 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
123 return false; 154 return false;
124} 155};
125 156
126bool bgPixmap_t::need_client_side_rendering () 157bool bgPixmap_t::need_client_side_rendering ()
127{ 158{
128# ifdef HAVE_AFTERIMAGE 159# ifdef HAVE_AFTERIMAGE
129 if (original_asim != NULL) 160 if (original_asim != NULL)
130 return true; 161 return true;
131# endif 162# endif
132# ifdef ENABLE_TRANSPARENCY 163# ifdef ENABLE_TRANSPARENCY
133 if (flags & isTransparent) 164 if (flags & isTransparent)
134 { 165 {
166# ifdef HAVE_AFTERIMAGE // can't blur without libAI anyways
135 if (((flags & blurNeeded) && !(flags & blurServerSide)) 167 if ((flags & blurNeeded) && !(flags & blurServerSide))
168 return true;
169# endif
136 || ((flags & tintNeeded) && !(flags & tintServerSide))) 170 if ((flags & tintNeeded) && !(flags & tintServerSide))
137 return true; 171 return true;
138 } 172 }
139# endif 173# endif
140 return false; 174 return false;
141} 175}
142 176
160static inline bool 194static inline bool
161check_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)
162{ 196{
163 if (geom_flags & flag) 197 if (geom_flags & flag)
164 { 198 {
199 if (new_value != bgPixmap_t::rootAlign)
200 {
165 if (new_value < -100) 201 if (new_value < -100)
166 new_value = -100; 202 new_value = -100;
167 else if (new_value > 200) 203 else if (new_value > 200)
168 new_value = 200; 204 new_value = 200;
205 }
169 if (new_value != align) 206 if (new_value != align)
170 { 207 {
171 align = new_value; 208 align = new_value;
172 return true; 209 return true;
173 } 210 }
265 y = x; 302 y = x;
266 geom_flags |= YValue; 303 geom_flags |= YValue;
267 } 304 }
268 305
269 if (flags & geometrySet) 306 if (flags & geometrySet)
307 {
270 {/* new geometry is an adjustment to the old one ! */ 308 /* new geometry is an adjustment to the old one ! */
271 if ((geom_flags & WidthValue) && (geom_flags & HeightValue)) 309 if ((geom_flags & WidthValue) && (geom_flags & HeightValue))
272 { 310 {
273 if (w == 0 && h != 0) 311 if (w == 0 && h != 0)
274 { 312 {
275 w = h_scale; 313 w = h_scale;
291 } 329 }
292 } 330 }
293 else /* setting up geometry from scratch */ 331 else /* setting up geometry from scratch */
294 { 332 {
295 if (!(geom_flags & XValue)) 333 if (!(geom_flags & XValue))
334 {
296 {/* use default geometry - centered */ 335 /* use default geometry - centered */
297 x = y = defaultAlign; 336 x = y = defaultAlign;
298 } 337 }
299 else if (!(geom_flags & YValue)) 338 else if (!(geom_flags & YValue))
300 y = x; 339 y = x;
301 340
302 if ((geom_flags & (WidthValue|HeightValue)) == 0) 341 if ((geom_flags & (WidthValue|HeightValue)) == 0)
342 {
303 {/* use default geometry - scaled */ 343 /* use default geometry - scaled */
304 w = h = defaultScale; 344 w = h = defaultScale;
305 } 345 }
306 else if (geom_flags & WidthValue) 346 else if (geom_flags & WidthValue)
307 { 347 {
308 if (!(geom_flags & HeightValue)) 348 if (!(geom_flags & HeightValue))
311 else 351 else
312 w = h; 352 w = h;
313 } 353 }
314 } /* done parsing geometry string */ 354 } /* done parsing geometry string */
315 else if (!(flags & geometrySet)) 355 else if (!(flags & geometrySet))
356 {
316 { /* default geometry - scaled and centered */ 357 /* default geometry - scaled and centered */
317 x = y = defaultAlign; 358 x = y = defaultAlign;
318 w = h = defaultScale; 359 w = h = defaultScale;
319 } 360 }
320 361
321 if (!(flags & geometrySet)) 362 if (!(flags & geometrySet))
322 geom_flags |= WidthValue|HeightValue|XValue|YValue; 363 geom_flags |= WidthValue|HeightValue|XValue|YValue;
323 364
324 if (ops) 365 if (ops)
325 { 366 {
327 { 368 {
328 while (*ops == ':' || isspace(*ops)) ++ops; 369 while (*ops == ':' || isspace(*ops)) ++ops;
329# define CHECK_GEOM_OPS(op_str) (strncasecmp (ops, (op_str), sizeof(op_str)-1) == 0) 370# define CHECK_GEOM_OPS(op_str) (strncasecmp (ops, (op_str), sizeof(op_str)-1) == 0)
330 if (CHECK_GEOM_OPS("tile")) 371 if (CHECK_GEOM_OPS("tile"))
331 { 372 {
332 w = h = 0; 373 w = h = noScale;
333 geom_flags |= WidthValue|HeightValue; 374 geom_flags |= WidthValue|HeightValue;
334 } 375 }
335 else if (CHECK_GEOM_OPS("propscale")) 376 else if (CHECK_GEOM_OPS("propscale"))
336 { 377 {
337 if (w == 0 && h == 0) 378 if (w == 0 && h == 0)
338 { 379 {
339 w = 100; 380 w = windowScale;
340 geom_flags |= WidthValue; 381 geom_flags |= WidthValue;
341 } 382 }
342 new_flags |= propScale; 383 new_flags |= propScale;
343 } 384 }
344 else if (CHECK_GEOM_OPS("hscale")) 385 else if (CHECK_GEOM_OPS("hscale"))
345 { 386 {
346 if (w == 0) 387 if (w == 0)
347 w = 100; 388 w = windowScale;
348 h = 0; 389 h = noScale;
349 geom_flags |= WidthValue|HeightValue; 390 geom_flags |= WidthValue|HeightValue;
350 } 391 }
351 else if (CHECK_GEOM_OPS("vscale")) 392 else if (CHECK_GEOM_OPS("vscale"))
352 { 393 {
353 if (h == 0) 394 if (h == 0)
354 h = 100; 395 h = windowScale;
355 w = 0; 396 w = noScale;
356 geom_flags |= WidthValue|HeightValue; 397 geom_flags |= WidthValue|HeightValue;
357 } 398 }
358 else if (CHECK_GEOM_OPS("scale")) 399 else if (CHECK_GEOM_OPS("scale"))
359 { 400 {
360 if (h == 0) 401 if (h == 0)
361 h = 100; 402 h = windowScale;
362 if (w == 0) 403 if (w == 0)
363 w = 100; 404 w = windowScale;
364 geom_flags |= WidthValue|HeightValue; 405 geom_flags |= WidthValue|HeightValue;
365 } 406 }
366 else if (CHECK_GEOM_OPS("auto")) 407 else if (CHECK_GEOM_OPS("auto"))
367 { 408 {
409 w = h = windowScale;
410 x = y = centerAlign;
411 geom_flags |= WidthValue|HeightValue|XValue|YValue;
412 }
413 else if (CHECK_GEOM_OPS("root"))
414 {
368 w = h = 100; 415 w = h = noScale;
369 x = y = 50; 416 x = y = rootAlign;
370 geom_flags |= WidthValue|HeightValue|XValue|YValue; 417 geom_flags |= WidthValue|HeightValue|XValue|YValue;
371 } 418 }
372# undef CHECK_GEOM_OPS 419# undef CHECK_GEOM_OPS
373 while (*ops != ':' && *ops != '\0') ++ops; 420 while (*ops != ':' && *ops != '\0') ++ops;
374 } /* done parsing ops */ 421 } /* done parsing ops */
413 460
414 TIMING_TEST_START (asim); 461 TIMING_TEST_START (asim);
415 462
416 if (original_asim) 463 if (original_asim)
417 { 464 {
465 if (h_align == rootAlign || v_align == rootAlign)
466 {
467 target->get_window_origin(x, y);
468 x = -x;
469 y = -y;
470 }
471 if (h_align != rootAlign)
418 x = make_align_position (h_align, target_width, w > 0 ? w : (int)original_asim->width); 472 x = make_align_position (h_align, target_width, w > 0 ? w : (int)original_asim->width);
473 if (v_align != rootAlign)
419 y = make_align_position (v_align, target_height, h > 0 ? h : (int)original_asim->height); 474 y = make_align_position (v_align, target_height, h > 0 ? h : (int)original_asim->height);
420 } 475 }
421 476
422 if (original_asim == NULL 477 if (original_asim == NULL
423 || x >= target_width 478 || x >= target_width
424 || y >= target_height 479 || y >= target_height
446 { 501 {
447 result = original_asim; 502 result = original_asim;
448 if ((w > 0 && w != original_asim->width) 503 if ((w > 0 && w != original_asim->width)
449 || (h > 0 && h != original_asim->height)) 504 || (h > 0 && h != original_asim->height))
450 { 505 {
451 result = scale_asimage (target->asv, original_asim, 506 result = scale_asimage (target->asv, original_asim,
452 w > 0 ? w : original_asim->width, 507 w > 0 ? w : original_asim->width,
453 h > 0 ? h : original_asim->height, 508 h > 0 ? h : original_asim->height,
454 background ? ASA_ASImage : ASA_XImage, 509 background ? ASA_ASImage : ASA_XImage,
455 100, ASIMAGE_QUALITY_DEFAULT); 510 100, ASIMAGE_QUALITY_DEFAULT);
456 } 511 }
457 if (background == NULL) 512 if (background == NULL)
513 {
458 {/* if tiling - pixmap has to be sized exactly as the image */ 514 /* if tiling - pixmap has to be sized exactly as the image,
515 but there is no need to make it bigger then the window! */
459 if (h_scale == 0) 516 if (h_scale == 0)
460 new_pmap_width = result->width; 517 new_pmap_width = min (result->width, target_width);
461 if (v_scale == 0) 518 if (v_scale == 0)
462 new_pmap_height = result->height; 519 new_pmap_height = min (result->height, target_height);
463 /* we also need to tile our image in one or both directions */ 520 /* we also need to tile our image in one or both directions */
464 if (h_scale == 0 || v_scale == 0) 521 if (h_scale == 0 || v_scale == 0)
465 { 522 {
466 ASImage *tmp = tile_asimage (target->asv, result, 523 ASImage *tmp = tile_asimage (target->asv, result,
467 (h_scale > 0) ? 0 : (int)result->width - x, 524 (h_scale > 0) ? 0 : (int)result->width - x,
468 (v_scale > 0) ? 0 : (int)result->height - y, 525 (v_scale > 0) ? 0 : (int)result->height - y,
526 new_pmap_width,
469 result->width, result->height, 527 new_pmap_height,
470 TINT_LEAVE_SAME, ASA_XImage, 528 TINT_LEAVE_SAME, ASA_XImage,
471 100, ASIMAGE_QUALITY_DEFAULT); 529 100, ASIMAGE_QUALITY_DEFAULT);
472 if (tmp) 530 if (tmp)
473 { 531 {
474 if (result != original_asim) 532 if (result != original_asim)
476 result = tmp; 534 result = tmp;
477 } 535 }
478 } 536 }
479 } 537 }
480 else 538 else
539 {
481 {/* if blending background and image - pixmap has to be sized same as target window */ 540 /* if blending background and image - pixmap has to be sized same as target window */
482 ASImageLayer *layers = create_image_layers (2); 541 ASImageLayer *layers = create_image_layers (2);
483 ASImage *merged_im = NULL; 542 ASImage *merged_im = NULL;
484 543
485 layers[0].im = background; 544 layers[0].im = background;
486 layers[0].clip_width = target_width; 545 layers[0].clip_width = target_width;
487 layers[0].clip_height = target_height; 546 layers[0].clip_height = target_height;
488 layers[0].tint = background_tint; 547 layers[0].tint = background_tint;
489 layers[1].im = result; 548 layers[1].im = result;
490 if (w <= 0) 549 if (w <= 0)
550 {
491 {/* tile horizontally */ 551 /* tile horizontally */
492 while (x > 0) x -= (int)result->width; 552 while (x > 0) x -= (int)result->width;
493 layers[1].dst_x = x; 553 layers[1].dst_x = x;
494 layers[1].clip_width = result->width+target_width; 554 layers[1].clip_width = result->width+target_width;
495 } 555 }
496 else 556 else
557 {
497 {/* clip horizontally */ 558 /* clip horizontally */
498 layers[1].dst_x = x; 559 layers[1].dst_x = x;
499 layers[1].clip_width = result->width; 560 layers[1].clip_width = result->width;
500 } 561 }
501 if (h <= 0) 562 if (h <= 0)
502 { 563 {
575 } 636 }
576 637
577 /* put result on pixmap */ 638 /* put result on pixmap */
578 if (dst_x < new_pmap_width && dst_y < new_pmap_height) 639 if (dst_x < new_pmap_width && dst_y < new_pmap_height)
579 asimage2drawable (target->asv, pixmap, result, gc, src_x, src_y, dst_x, dst_y, dst_width, dst_height, True); 640 asimage2drawable (target->asv, pixmap, result, gc, src_x, src_y, dst_x, dst_y, dst_width, dst_height, True);
580 641
581 if (result != background && result != original_asim) 642 if (result != background && result != original_asim)
582 destroy_asimage (&result); 643 destroy_asimage (&result);
583 644
584 XFreeGC (target->dpy, gc); 645 XFreeGC (target->dpy, gc);
585 TIMING_TEST_PRINT_RESULT (asim); 646 TIMING_TEST_PRINT_RESULT (asim);
611 f[len] = '\0'; 672 f[len] = '\0';
612 original_asim = get_asimage (target->asimman, f, 0xFFFFFFFF, 100); 673 original_asim = get_asimage (target->asimman, f, 0xFFFFFFFF, 100);
613 free (f); 674 free (f);
614 } 675 }
615 return (original_asim != NULL); 676 return (original_asim != NULL);
616# endif 677# endif
617 } 678 }
618 return false; 679 return false;
619} 680}
620 681
621# endif /* BG_IMAGE_FROM_FILE */ 682# endif /* BG_IMAGE_FROM_FILE */
622 683
623# ifdef ENABLE_TRANSPARENCY 684# ifdef ENABLE_TRANSPARENCY
624bool 685bool
625bgPixmap_t::set_transparent () 686bgPixmap_t::set_transparent ()
626{ 687{
627 if (!(flags & isTransparent)) 688 if (!(flags & isTransparent))
628 { 689 {
629 flags |= isTransparent; 690 flags |= isTransparent;
654 if (v_blurRadius != vr) 715 if (v_blurRadius != vr)
655 { 716 {
656 ++changed; 717 ++changed;
657 v_blurRadius = vr; 718 v_blurRadius = vr;
658 } 719 }
659 720
660 if (v_blurRadius == 0 && h_blurRadius == 0) 721 if (v_blurRadius == 0 && h_blurRadius == 0)
661 flags &= ~blurNeeded; 722 flags &= ~blurNeeded;
662 else 723 else
663 flags |= blurNeeded; 724 flags |= blurNeeded;
664 725
691 && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700)) 752 && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700))
692 { 753 {
693 flags |= bgPixmap_t::tintNeeded; 754 flags |= bgPixmap_t::tintNeeded;
694 } 755 }
695 } 756 }
696 757
697 if (flags & bgPixmap_t::tintNeeded) 758 if (flags & bgPixmap_t::tintNeeded)
698 { 759 {
699 if (flags & bgPixmap_t::tintWholesome) 760 if (flags & bgPixmap_t::tintWholesome)
700 flags |= bgPixmap_t::tintServerSide; 761 flags |= bgPixmap_t::tintServerSide;
701 else 762 else
738bool 799bool
739bgPixmap_t::set_shade (const char *shade_str) 800bgPixmap_t::set_shade (const char *shade_str)
740{ 801{
741 int new_shade = (shade_str) ? atoi (shade_str) : 0; 802 int new_shade = (shade_str) ? atoi (shade_str) : 0;
742 803
804 if (new_shade < 0 && new_shade > -100)
805 new_shade = 200 - (100 + new_shade);
743 if (new_shade == 100) 806 else if (new_shade == 100)
744 new_shade = 0; 807 new_shade = 0;
745 808
746 if (new_shade != shade) 809 if (new_shade != shade)
747 { 810 {
748 unsigned long new_flags = compute_tint_shade_flags ((flags & tintSet) ? &tint : NULL, new_shade); 811 unsigned long new_flags = compute_tint_shade_flags ((flags & tintSet) ? &tint : NULL, new_shade);
751 return true; 814 return true;
752 } 815 }
753 return false; 816 return false;
754} 817}
755 818
756/* make_transparency_pixmap() 819/* make_transparency_pixmap()
757 * Builds a pixmap sized the same as terminal window, with depth same as the root window 820 * Builds a pixmap sized the same as terminal window, with depth same as the root window
758 * that pixmap contains tiled portion of the root pixmap that is supposed to be covered by 821 * that pixmap contains tiled portion of the root pixmap that is supposed to be covered by
759 * our window. 822 * our window.
760 */ 823 */
761unsigned long 824unsigned long
762bgPixmap_t::make_transparency_pixmap () 825bgPixmap_t::make_transparency_pixmap ()
763{ 826{
787 if (sx + window_width <= 0 || sy + window_height <= 0 850 if (sx + window_width <= 0 || sy + window_height <= 0
788 || sx >= root_width || sy >= root_height) 851 || sx >= root_width || sy >= root_height)
789 return 0; 852 return 0;
790 853
791 if (root_pixmap != None) 854 if (root_pixmap != None)
855 {
792 {/* we want to validate the pixmap and get it's size at the same time : */ 856 /* we want to validate the pixmap and get it's size at the same time : */
793 int junk; 857 int junk;
794 unsigned int ujunk; 858 unsigned int ujunk;
795 /* root pixmap may be bad - allow a error */ 859 /* root pixmap may be bad - allow a error */
796 target->allowedxerror = -1; 860 target->allowedxerror = -1;
797 861
806 870
807 if (tiled_root_pmap == None) /* something really bad happened - abort */ 871 if (tiled_root_pmap == None) /* something really bad happened - abort */
808 return 0; 872 return 0;
809 873
810 if (root_pixmap == None) 874 if (root_pixmap == None)
875 {
811 { /* use tricks to obtain the root background image :*/ 876 /* use tricks to obtain the root background image :*/
812 /* we want to create Overrideredirect window overlapping out window 877 /* we want to create Overrideredirect window overlapping out window
813 with background type of Parent Relative and then grab it */ 878 with background type of Parent Relative and then grab it */
814 XSetWindowAttributes attr; 879 XSetWindowAttributes attr;
815 Window src; 880 Window src;
816 bool success = false; 881 bool success = false;
836 * but to be on the safe side - let's check for the actuall event to arrive : */ 901 * but to be on the safe side - let's check for the actuall event to arrive : */
837 while (XCheckWindowEvent (dpy, src, ExposureMask, &event)) 902 while (XCheckWindowEvent (dpy, src, ExposureMask, &event))
838 ++ev_count; 903 ++ev_count;
839 904
840 if (ev_count > 0); 905 if (ev_count > 0);
906 {
841 { /* hooray! - we can grab the image! */ 907 /* hooray! - we can grab the image! */
842 gc = XCreateGC (dpy, root, 0, NULL); 908 gc = XCreateGC (dpy, root, 0, NULL);
843 if (gc) 909 if (gc)
844 { 910 {
845 XCopyArea (dpy, src, tiled_root_pmap, gc, 0, 0, window_width, window_height, 0, 0); 911 XCopyArea (dpy, src, tiled_root_pmap, gc, 0, 0, window_width, window_height, 0, 0);
846 success = true; 912 success = true;
858 } 924 }
859 else 925 else
860 result |= transpPmapTiled; 926 result |= transpPmapTiled;
861 } 927 }
862 else 928 else
929 {
863 {/* strightforward pixmap copy */ 930 /* strightforward pixmap copy */
864 gcv.tile = root_pixmap; 931 gcv.tile = root_pixmap;
865 gcv.fill_style = FillTiled; 932 gcv.fill_style = FillTiled;
866 933
867 while (sx < 0) sx += (int)window_width; 934 while (sx < 0) sx += (int)root_width;
868 while (sy < 0) sy += (int)window_height; 935 while (sy < 0) sy += (int)root_height;
869 936
870 gcv.ts_x_origin = -sx; 937 gcv.ts_x_origin = -sx;
871 gcv.ts_y_origin = -sy; 938 gcv.ts_y_origin = -sy;
872 gc = XCreateGC (dpy, root, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); 939 gc = XCreateGC (dpy, root, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv);
873 940
879 } 946 }
880 TIMING_TEST_PRINT_RESULT (tp); 947 TIMING_TEST_PRINT_RESULT (tp);
881 948
882 if (tiled_root_pmap != None) 949 if (tiled_root_pmap != None)
883 { 950 {
884 if (!need_client_side_rendering ()) 951 if (!need_client_side_rendering ())
885 { 952 {
886 if ((flags & tintNeeded)) 953 if ((flags & tintNeeded))
887 { 954 {
888 if (flags & tintWholesome) 955 if (flags & tintWholesome)
889 { 956 {
890 /* In this case we can tint image server-side getting significant 957 /* In this case we can tint image server-side getting significant
891 * performance improvements, as we eliminate XImage transfer 958 * performance improvements, as we eliminate XImage transfer
932 pf.direct.greenMask = 0xff; 999 pf.direct.greenMask = 0xff;
933 pf.direct.blueMask = 0xff; 1000 pf.direct.blueMask = 0xff;
934 pf.direct.alphaMask = 0xff; 1001 pf.direct.alphaMask = 0xff;
935 1002
936 XRenderPictFormat *solid_format = XRenderFindFormat (dpy, 1003 XRenderPictFormat *solid_format = XRenderFindFormat (dpy,
937 (PictFormatType| 1004 (PictFormatType|
938 PictFormatDepth| 1005 PictFormatDepth|
939 PictFormatRedMask| 1006 PictFormatRedMask|
940 PictFormatGreenMask| 1007 PictFormatGreenMask|
941 PictFormatBlueMask| 1008 PictFormatBlueMask|
942 PictFormatAlphaMask), 1009 PictFormatAlphaMask),
943 &pf, 1010 &pf,
944 0); 1011 0);
945 XRenderPictFormat *root_format = XRenderFindVisualFormat (dpy, DefaultVisualOfScreen (ScreenOfDisplay (dpy, target->display->screen))); 1012 XRenderPictFormat *root_format = XRenderFindVisualFormat (dpy, DefaultVisualOfScreen (ScreenOfDisplay (dpy, target->display->screen)));
946 XRenderPictureAttributes pa ; 1013 XRenderPictureAttributes pa ;
947 1014
948 back_pic = XRenderCreatePicture (dpy, tiled_root_pmap, root_format, 0, &pa); 1015 back_pic = XRenderCreatePicture (dpy, tiled_root_pmap, root_format, 0, &pa);
949 1016
951 1018
952 Pixmap overlay_pmap = XCreatePixmap (dpy, root, 1, 1, 32); 1019 Pixmap overlay_pmap = XCreatePixmap (dpy, root, 1, 1, 32);
953 Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa); 1020 Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa);
954 XFreePixmap (dpy, overlay_pmap); 1021 XFreePixmap (dpy, overlay_pmap);
955 1022
956 pa.component_alpha = True; 1023 pa.component_alpha = True;
957 Pixmap mask_pmap = XCreatePixmap (dpy, root, 1, 1, 32); 1024 Pixmap mask_pmap = XCreatePixmap (dpy, root, 1, 1, 32);
958 Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat|CPComponentAlpha, &pa); 1025 Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat|CPComponentAlpha, &pa);
959 XFreePixmap (dpy, mask_pmap); 1026 XFreePixmap (dpy, mask_pmap);
960 1027
961 if (mask_pic && overlay_pic && back_pic) 1028 if (mask_pic && overlay_pic && back_pic)
977 XRenderFreePicture (dpy, mask_pic); 1044 XRenderFreePicture (dpy, mask_pic);
978 XRenderFreePicture (dpy, overlay_pic); 1045 XRenderFreePicture (dpy, overlay_pic);
979 XRenderFreePicture (dpy, back_pic); 1046 XRenderFreePicture (dpy, back_pic);
980# if DO_TIMING_TEST 1047# if DO_TIMING_TEST
981 XSync (dpy, False); 1048 XSync (dpy, False);
982# endif 1049# endif
983# endif 1050# endif
984 } 1051 }
985 } 1052 }
986 } /* server side rendering completed */ 1053 } /* server side rendering completed */
987 1054
991 pixmap = tiled_root_pmap; 1058 pixmap = tiled_root_pmap;
992 pmap_width = window_width; 1059 pmap_width = window_width;
993 pmap_height = window_height; 1060 pmap_height = window_height;
994 pmap_depth = root_depth; 1061 pmap_depth = root_depth;
995 } 1062 }
996 1063
997 if (gc) 1064 if (gc)
998 XFreeGC (dpy, gc); 1065 XFreeGC (dpy, gc);
999 1066
1000 TIMING_TEST_PRINT_RESULT (tp); 1067 TIMING_TEST_PRINT_RESULT (tp);
1001 1068
1002 return result; 1069 return result;
1003} 1070}
1004 1071
1005bool 1072bool
1006bgPixmap_t::set_root_pixmap () 1073bgPixmap_t::set_root_pixmap ()
1007{ 1074{
1008 Pixmap new_root_pixmap = None; 1075 Pixmap new_root_pixmap = None;
1009 1076
1010 new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID); 1077 new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID);
1011 if (new_root_pixmap == None) 1078 if (new_root_pixmap == None)
1012 new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID); 1079 new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID);
1013 1080
1014 if (new_root_pixmap != root_pixmap) 1081 if (new_root_pixmap != root_pixmap)
1094 } 1161 }
1095 else if (background_flags && pmap_depth != target->depth) 1162 else if (background_flags && pmap_depth != target->depth)
1096 { 1163 {
1097 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); 1164 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap);
1098 } 1165 }
1166
1099# else /* our own client-side tinting */ 1167# elif !XFT /* our own client-side tinting */
1168
1169 /* ATTENTION: We ASSUME that XFT will let us do all the tinting neccessary server-side.
1170 This may need to be changed in need_client_side_rendering() logic is altered !!! */
1171
1100 if (background_flags && (flags & isInvalid)) 1172 if (background_flags && (flags & isInvalid))
1101 { 1173 {
1102 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); 1174 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap);
1103 if (result != NULL && !(background_flags & transpPmapTinted) && (flags & tintNeeded)) 1175 if (result != NULL && !(background_flags & transpPmapTinted) && (flags & tintNeeded))
1104 { 1176 {
1126 pmap_width = result->width; 1198 pmap_width = result->width;
1127 pmap_height = result->height; 1199 pmap_height = result->height;
1128 pmap_depth = target->depth; 1200 pmap_depth = target->depth;
1129 } 1201 }
1130 if (pmap_depth != result->depth) 1202 if (pmap_depth != result->depth)
1203 {
1131 { /* Bad Match error will ensue ! stupid X !!!! */ 1204 /* Bad Match error will ensue ! stupid X !!!! */
1132 if( result->depth == 24 && pmap_depth == 32) 1205 if( result->depth == 24 && pmap_depth == 32)
1133 result->depth = 32; 1206 result->depth = 32;
1134 else if( result->depth == 32 && pmap_depth == 24) 1207 else if( result->depth == 32 && pmap_depth == 24)
1135 result->depth = 24; 1208 result->depth = 24;
1136 else 1209 else
1157 1230
1158 apply (); 1231 apply ();
1159 1232
1160 TIMING_TEST_PRINT_RESULT (tp); 1233 TIMING_TEST_PRINT_RESULT (tp);
1161 1234
1162 return true; 1235 return true;
1163} 1236}
1164 1237
1165bool 1238bool
1166bgPixmap_t::set_target (rxvt_term *new_target) 1239bgPixmap_t::set_target (rxvt_term *new_target)
1167{ 1240{
1168 if (new_target) 1241 if (new_target)
1169 if (target != new_target) 1242 if (target != new_target)
1170 { 1243 {
1182{ 1255{
1183 if (target) 1256 if (target)
1184 { 1257 {
1185 flags &= ~isVtOrigin; 1258 flags &= ~isVtOrigin;
1186 if (pixmap != None) 1259 if (pixmap != None)
1260 {
1187 { /* set target's background to pixmap */ 1261 /* set target's background to pixmap */
1188# ifdef ENABLE_TRANSPARENCY 1262# ifdef ENABLE_TRANSPARENCY
1189 if (flags & isTransparent) 1263 if (flags & isTransparent)
1190 { 1264 {
1191 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap); 1265 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap);
1192 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative); 1266 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative);
1208 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); 1282 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1209# endif 1283# endif
1210 } 1284 }
1211 } 1285 }
1212 else 1286 else
1287 {
1213 { /* set target background to a pixel */ 1288 /* set target background to a pixel */
1214 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); 1289 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
1215 XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); 1290 XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]);
1216 /* do we also need to set scrollbar's background here ? */ 1291 /* do we also need to set scrollbar's background here ? */
1217# if HAVE_SCROLLBARS 1292# if HAVE_SCROLLBARS
1218 if (target->scrollBar.win) 1293 if (target->scrollBar.win)
1219 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); 1294 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1220# endif 1295# endif
1221 } 1296 }
1222 1297 /* don't want Expose on the parent or vt. It is better to use
1223 /* don't want Expose on the parent */ 1298 scr_touch or we get a great deal of flicker otherwise: */
1224 XClearArea (target->dpy, target->parent[0], 0, 0, 0, 0, False); 1299 XClearWindow (target->dpy, target->parent[0]);
1225 /* do want Expose on the vt, so we get refreshed properly */
1226 XClearArea (target->dpy, target->vt, 0, 0, 0, 0, True);
1227 1300
1228# if HAVE_SCROLLBARS 1301# if HAVE_SCROLLBARS
1229 if (target->scrollBar.win) 1302 if (target->scrollBar.win)
1230 { 1303 {
1231 target->scrollBar.setIdle (); 1304 target->scrollBar.setIdle ();
1232 target->scrollbar_show (0); 1305 target->scrollbar_show (0);
1233 } 1306 }
1234# endif 1307# endif
1235 }
1236}
1237 1308
1309 target->want_refresh = 1;
1310 flags |= hasChanged;
1311 }
1312}
1313
1238#endif /* HAVE_BG_PIXMAP */ 1314#endif /* HAVE_BG_PIXMAP */
1239 1315
1240#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) 1316#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) && !XFT
1241/* taken from aterm-0.4.2 */ 1317/* taken from aterm-0.4.2 */
1242 1318
1243typedef uint32_t RUINT32T; 1319typedef uint32_t RUINT32T;
1244 1320
1245static void 1321static void

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines