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.6 by sasha, Thu Sep 20 22:15:02 2007 UTC vs.
Revision 1.23 by ayin, Sat Jan 5 13:52:23 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)
130 return true; 163 return true;
131# endif 164# endif
132# ifdef ENABLE_TRANSPARENCY 165# ifdef ENABLE_TRANSPARENCY
133 if (flags & isTransparent) 166 if (flags & isTransparent)
134 { 167 {
168# ifdef HAVE_AFTERIMAGE // can't blur without libAI anyways
135 if (((flags & blurNeeded) && !(flags & blurServerSide)) 169 if ((flags & blurNeeded) && !(flags & blurServerSide))
170 return true;
171# endif
136 || ((flags & tintNeeded) && !(flags & tintServerSide))) 172 if ((flags & tintNeeded) && !(flags & tintServerSide))
137 return true; 173 return true;
138 } 174 }
139# endif 175# endif
140 return false; 176 return false;
141} 177}
142 178
160static inline bool 196static inline bool
161check_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)
162{ 198{
163 if (geom_flags & flag) 199 if (geom_flags & flag)
164 { 200 {
201 if (new_value != bgPixmap_t::rootAlign)
202 {
165 if (new_value < -100) 203 if (new_value < -100)
166 new_value = -100; 204 new_value = -100;
167 else if (new_value > 200) 205 else if (new_value > 200)
168 new_value = 200; 206 new_value = 200;
207 }
169 if (new_value != align) 208 if (new_value != align)
170 { 209 {
171 align = new_value; 210 align = new_value;
172 return true; 211 return true;
173 } 212 }
218 int x = 0, y = 0; 257 int x = 0, y = 0;
219 unsigned int w = 0, h = 0; 258 unsigned int w = 0, h = 0;
220 unsigned int n; 259 unsigned int n;
221 unsigned long new_flags = (flags & (~geometryFlags)); 260 unsigned long new_flags = (flags & (~geometryFlags));
222 char *p; 261 char *p;
223# define MAXLEN_GEOM 256 /* could be longer then regular geometry string */ 262# define MAXLEN_GEOM 256 /* could be longer than regular geometry string */
224 263
225 if (geom == NULL) 264 if (geom == NULL)
226 return false; 265 return false;
227 266
228 char str[MAXLEN_GEOM]; 267 char str[MAXLEN_GEOM];
265 y = x; 304 y = x;
266 geom_flags |= YValue; 305 geom_flags |= YValue;
267 } 306 }
268 307
269 if (flags & geometrySet) 308 if (flags & geometrySet)
309 {
270 {/* new geometry is an adjustment to the old one ! */ 310 /* new geometry is an adjustment to the old one ! */
271 if ((geom_flags & WidthValue) && (geom_flags & HeightValue)) 311 if ((geom_flags & WidthValue) && (geom_flags & HeightValue))
272 { 312 {
273 if (w == 0 && h != 0) 313 if (w == 0 && h != 0)
274 { 314 {
275 w = h_scale; 315 w = h_scale;
291 } 331 }
292 } 332 }
293 else /* setting up geometry from scratch */ 333 else /* setting up geometry from scratch */
294 { 334 {
295 if (!(geom_flags & XValue)) 335 if (!(geom_flags & XValue))
336 {
296 {/* use default geometry - centered */ 337 /* use default geometry - centered */
297 x = y = defaultAlign; 338 x = y = defaultAlign;
298 } 339 }
299 else if (!(geom_flags & YValue)) 340 else if (!(geom_flags & YValue))
300 y = x; 341 y = x;
301 342
302 if ((geom_flags & (WidthValue|HeightValue)) == 0) 343 if ((geom_flags & (WidthValue|HeightValue)) == 0)
344 {
303 {/* use default geometry - scaled */ 345 /* use default geometry - scaled */
304 w = h = defaultScale; 346 w = h = defaultScale;
305 } 347 }
306 else if (geom_flags & WidthValue) 348 else if (geom_flags & WidthValue)
307 { 349 {
308 if (!(geom_flags & HeightValue)) 350 if (!(geom_flags & HeightValue))
311 else 353 else
312 w = h; 354 w = h;
313 } 355 }
314 } /* done parsing geometry string */ 356 } /* done parsing geometry string */
315 else if (!(flags & geometrySet)) 357 else if (!(flags & geometrySet))
358 {
316 { /* default geometry - scaled and centered */ 359 /* default geometry - scaled and centered */
317 x = y = defaultAlign; 360 x = y = defaultAlign;
318 w = h = defaultScale; 361 w = h = defaultScale;
319 } 362 }
320 363
321 if (!(flags & geometrySet)) 364 if (!(flags & geometrySet))
322 geom_flags |= WidthValue|HeightValue|XValue|YValue; 365 geom_flags |= WidthValue|HeightValue|XValue|YValue;
323 366
324 if (ops) 367 if (ops)
325 { 368 {
327 { 370 {
328 while (*ops == ':' || isspace(*ops)) ++ops; 371 while (*ops == ':' || isspace(*ops)) ++ops;
329# 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)
330 if (CHECK_GEOM_OPS("tile")) 373 if (CHECK_GEOM_OPS("tile"))
331 { 374 {
332 w = h = 0; 375 w = h = noScale;
333 geom_flags |= WidthValue|HeightValue; 376 geom_flags |= WidthValue|HeightValue;
334 } 377 }
335 else if (CHECK_GEOM_OPS("propscale")) 378 else if (CHECK_GEOM_OPS("propscale"))
336 { 379 {
337 if (w == 0 && h == 0) 380 if (w == 0 && h == 0)
338 { 381 {
339 w = 100; 382 w = windowScale;
340 geom_flags |= WidthValue; 383 geom_flags |= WidthValue;
341 } 384 }
342 new_flags |= propScale; 385 new_flags |= propScale;
343 } 386 }
344 else if (CHECK_GEOM_OPS("hscale")) 387 else if (CHECK_GEOM_OPS("hscale"))
345 { 388 {
346 if (w == 0) 389 if (w == 0)
347 w = 100; 390 w = windowScale;
348 h = 0; 391 h = noScale;
349 geom_flags |= WidthValue|HeightValue; 392 geom_flags |= WidthValue|HeightValue;
350 } 393 }
351 else if (CHECK_GEOM_OPS("vscale")) 394 else if (CHECK_GEOM_OPS("vscale"))
352 { 395 {
353 if (h == 0) 396 if (h == 0)
354 h = 100; 397 h = windowScale;
355 w = 0; 398 w = noScale;
356 geom_flags |= WidthValue|HeightValue; 399 geom_flags |= WidthValue|HeightValue;
357 } 400 }
358 else if (CHECK_GEOM_OPS("scale")) 401 else if (CHECK_GEOM_OPS("scale"))
359 { 402 {
360 if (h == 0) 403 if (h == 0)
361 h = 100; 404 h = windowScale;
362 if (w == 0) 405 if (w == 0)
363 w = 100; 406 w = windowScale;
364 geom_flags |= WidthValue|HeightValue; 407 geom_flags |= WidthValue|HeightValue;
365 } 408 }
366 else if (CHECK_GEOM_OPS("auto")) 409 else if (CHECK_GEOM_OPS("auto"))
367 { 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 {
368 w = h = 100; 417 w = h = noScale;
369 x = y = 50; 418 x = y = rootAlign;
370 geom_flags |= WidthValue|HeightValue|XValue|YValue; 419 geom_flags |= WidthValue|HeightValue|XValue|YValue;
371 } 420 }
372# undef CHECK_GEOM_OPS 421# undef CHECK_GEOM_OPS
373 while (*ops != ':' && *ops != '\0') ++ops; 422 while (*ops != ':' && *ops != '\0') ++ops;
374 } /* done parsing ops */ 423 } /* done parsing ops */
387 if (new_flags != flags) 436 if (new_flags != flags)
388 { 437 {
389 flags = new_flags; 438 flags = new_flags;
390 changed++; 439 changed++;
391 } 440 }
392//fprintf( stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n", 441//fprintf (stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n",
393// flags, h_scale, v_scale, h_align, v_align); 442// flags, h_scale, v_scale, h_align, v_align);
394 return (changed > 0); 443 return (changed > 0);
395} 444}
396 445
397# ifdef HAVE_AFTERIMAGE 446# ifdef HAVE_AFTERIMAGE
413 462
414 TIMING_TEST_START (asim); 463 TIMING_TEST_START (asim);
415 464
416 if (original_asim) 465 if (original_asim)
417 { 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)
418 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)
419 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);
420 } 477 }
421 478
422 if (original_asim == NULL 479 if (original_asim == NULL
423 || x >= target_width 480 || x >= target_width
424 || y >= target_height 481 || y >= target_height
446 { 503 {
447 result = original_asim; 504 result = original_asim;
448 if ((w > 0 && w != original_asim->width) 505 if ((w > 0 && w != original_asim->width)
449 || (h > 0 && h != original_asim->height)) 506 || (h > 0 && h != original_asim->height))
450 { 507 {
451 result = scale_asimage (target->asv, original_asim, 508 result = scale_asimage (target->asv, original_asim,
452 w > 0 ? w : original_asim->width, 509 w > 0 ? w : original_asim->width,
453 h > 0 ? h : original_asim->height, 510 h > 0 ? h : original_asim->height,
454 background ? ASA_ASImage : ASA_XImage, 511 background ? ASA_ASImage : ASA_XImage,
455 100, ASIMAGE_QUALITY_DEFAULT); 512 100, ASIMAGE_QUALITY_DEFAULT);
456 } 513 }
457 if (background == NULL) 514 if (background == NULL)
515 {
458 {/* 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 than the window! */
459 if (h_scale == 0) 518 if (h_scale == 0)
460 new_pmap_width = result->width; 519 new_pmap_width = min (result->width, target_width);
461 if (v_scale == 0) 520 if (v_scale == 0)
462 new_pmap_height = result->height; 521 new_pmap_height = min (result->height, target_height);
463 /* 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 */
464 if (h_scale == 0 || v_scale == 0) 523 if (h_scale == 0 || v_scale == 0)
465 { 524 {
466 ASImage *tmp = tile_asimage (target->asv, result, 525 ASImage *tmp = tile_asimage (target->asv, result,
467 (h_scale > 0) ? 0 : (int)result->width - x, 526 (h_scale > 0) ? 0 : (int)result->width - x,
468 (v_scale > 0) ? 0 : (int)result->height - y, 527 (v_scale > 0) ? 0 : (int)result->height - y,
528 new_pmap_width,
469 result->width, result->height, 529 new_pmap_height,
470 TINT_LEAVE_SAME, ASA_XImage, 530 TINT_LEAVE_SAME, ASA_XImage,
471 100, ASIMAGE_QUALITY_DEFAULT); 531 100, ASIMAGE_QUALITY_DEFAULT);
472 if (tmp) 532 if (tmp)
473 { 533 {
474 if (result != original_asim) 534 if (result != original_asim)
476 result = tmp; 536 result = tmp;
477 } 537 }
478 } 538 }
479 } 539 }
480 else 540 else
541 {
481 {/* 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 */
482 ASImageLayer *layers = create_image_layers (2); 543 ASImageLayer *layers = create_image_layers (2);
483 ASImage *merged_im = NULL; 544 ASImage *merged_im = NULL;
484 545
485 layers[0].im = background; 546 layers[0].im = background;
486 layers[0].clip_width = target_width; 547 layers[0].clip_width = target_width;
487 layers[0].clip_height = target_height; 548 layers[0].clip_height = target_height;
488 layers[0].tint = background_tint; 549 layers[0].tint = background_tint;
489 layers[1].im = result; 550 layers[1].im = result;
490 if (w <= 0) 551 if (w <= 0)
552 {
491 {/* tile horizontally */ 553 /* tile horizontally */
492 while (x > 0) x -= (int)result->width; 554 while (x > 0) x -= (int)result->width;
493 layers[1].dst_x = x; 555 layers[1].dst_x = x;
494 layers[1].clip_width = result->width+target_width; 556 layers[1].clip_width = result->width+target_width;
495 } 557 }
496 else 558 else
559 {
497 {/* clip horizontally */ 560 /* clip horizontally */
498 layers[1].dst_x = x; 561 layers[1].dst_x = x;
499 layers[1].clip_width = result->width; 562 layers[1].clip_width = result->width;
500 } 563 }
501 if (h <= 0) 564 if (h <= 0)
502 { 565 {
575 } 638 }
576 639
577 /* put result on pixmap */ 640 /* put result on pixmap */
578 if (dst_x < new_pmap_width && dst_y < new_pmap_height) 641 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); 642 asimage2drawable (target->asv, pixmap, result, gc, src_x, src_y, dst_x, dst_y, dst_width, dst_height, True);
580 643
581 if (result != background && result != original_asim) 644 if (result != background && result != original_asim)
582 destroy_asimage (&result); 645 destroy_asimage (&result);
583 646
584 XFreeGC (target->dpy, gc); 647 XFreeGC (target->dpy, gc);
585 TIMING_TEST_PRINT_RESULT (asim); 648 TIMING_TEST_PRINT_RESULT (asim);
611 f[len] = '\0'; 674 f[len] = '\0';
612 original_asim = get_asimage (target->asimman, f, 0xFFFFFFFF, 100); 675 original_asim = get_asimage (target->asimman, f, 0xFFFFFFFF, 100);
613 free (f); 676 free (f);
614 } 677 }
615 return (original_asim != NULL); 678 return (original_asim != NULL);
616# endif 679# endif
617 } 680 }
618 return false; 681 return false;
619} 682}
620 683
621# endif /* BG_IMAGE_FROM_FILE */ 684# endif /* BG_IMAGE_FROM_FILE */
622 685
623# ifdef ENABLE_TRANSPARENCY 686# ifdef ENABLE_TRANSPARENCY
624bool 687bool
625bgPixmap_t::set_transparent () 688bgPixmap_t::set_transparent ()
626{ 689{
627 if (!(flags & isTransparent)) 690 if (!(flags & isTransparent))
628 { 691 {
629 flags |= isTransparent; 692 flags |= isTransparent;
654 if (v_blurRadius != vr) 717 if (v_blurRadius != vr)
655 { 718 {
656 ++changed; 719 ++changed;
657 v_blurRadius = vr; 720 v_blurRadius = vr;
658 } 721 }
659 722
660 if (v_blurRadius == 0 && h_blurRadius == 0) 723 if (v_blurRadius == 0 && h_blurRadius == 0)
661 flags &= ~blurNeeded; 724 flags &= ~blurNeeded;
662 else 725 else
663 flags |= blurNeeded; 726 flags |= blurNeeded;
664 727
691 && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700)) 754 && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700))
692 { 755 {
693 flags |= bgPixmap_t::tintNeeded; 756 flags |= bgPixmap_t::tintNeeded;
694 } 757 }
695 } 758 }
696 759
697 if (flags & bgPixmap_t::tintNeeded) 760 if (flags & bgPixmap_t::tintNeeded)
698 { 761 {
699 if (flags & bgPixmap_t::tintWholesome) 762 if (flags & bgPixmap_t::tintWholesome)
700 flags |= bgPixmap_t::tintServerSide; 763 flags |= bgPixmap_t::tintServerSide;
701 else 764 else
717 unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade); 780 unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade);
718 tint = new_tint; 781 tint = new_tint;
719 flags = (flags & ~tintFlags) | new_flags | tintSet; 782 flags = (flags & ~tintFlags) | new_flags | tintSet;
720 return true; 783 return true;
721 } 784 }
785
722 return false; 786 return false;
723} 787}
724 788
725bool 789bool
726bgPixmap_t::unset_tint () 790bgPixmap_t::unset_tint ()
730 if (new_flags != (flags & tintFlags)) 794 if (new_flags != (flags & tintFlags))
731 { 795 {
732 flags = (flags&~tintFlags)|new_flags; 796 flags = (flags&~tintFlags)|new_flags;
733 return true; 797 return true;
734 } 798 }
799
735 return false; 800 return false;
736} 801}
737 802
738bool 803bool
739bgPixmap_t::set_shade (const char *shade_str) 804bgPixmap_t::set_shade (const char *shade_str)
740{ 805{
741 int new_shade = (shade_str) ? atoi (shade_str) : 0; 806 int new_shade = (shade_str) ? atoi (shade_str) : 0;
742 807
808 if (new_shade < 0 && new_shade > -100)
809 new_shade = 200 - (100 + new_shade);
743 if (new_shade == 100) 810 else if (new_shade == 100)
744 new_shade = 0; 811 new_shade = 0;
745 812
746 if (new_shade != shade) 813 if (new_shade != shade)
747 { 814 {
748 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);
749 shade = new_shade; 816 shade = new_shade;
750 flags = (flags & (~tintFlags | tintSet)) | new_flags; 817 flags = (flags & (~tintFlags | tintSet)) | new_flags;
751 return true; 818 return true;
752 } 819 }
820
753 return false; 821 return false;
754} 822}
755 823
756/* make_transparency_pixmap() 824/* make_transparency_pixmap()
757 * 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
758 * 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
759 * our window. 827 * our window.
760 */ 828 */
761unsigned long 829unsigned long
762bgPixmap_t::make_transparency_pixmap () 830bgPixmap_t::make_transparency_pixmap ()
763{ 831{
787 if (sx + window_width <= 0 || sy + window_height <= 0 855 if (sx + window_width <= 0 || sy + window_height <= 0
788 || sx >= root_width || sy >= root_height) 856 || sx >= root_width || sy >= root_height)
789 return 0; 857 return 0;
790 858
791 if (root_pixmap != None) 859 if (root_pixmap != None)
860 {
792 {/* 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 : */
793 int junk; 862 int junk;
794 unsigned int ujunk; 863 unsigned int ujunk;
795 /* root pixmap may be bad - allow a error */ 864 /* root pixmap may be bad - allow a error */
796 target->allowedxerror = -1; 865 target->allowedxerror = -1;
797 866
806 875
807 if (tiled_root_pmap == None) /* something really bad happened - abort */ 876 if (tiled_root_pmap == None) /* something really bad happened - abort */
808 return 0; 877 return 0;
809 878
810 if (root_pixmap == None) 879 if (root_pixmap == None)
880 {
811 { /* use tricks to obtain the root background image :*/ 881 /* use tricks to obtain the root background image :*/
812 /* we want to create Overrideredirect window overlapping out window 882 /* we want to create Overrideredirect window overlapping out window
813 with background type of Parent Relative and then grab it */ 883 with background type of Parent Relative and then grab it */
814 XSetWindowAttributes attr; 884 XSetWindowAttributes attr;
815 Window src; 885 Window src;
816 bool success = false; 886 bool success = false;
831 XGrabServer (dpy); 901 XGrabServer (dpy);
832 XMapRaised (dpy, src); 902 XMapRaised (dpy, src);
833 XSync (dpy, False); 903 XSync (dpy, False);
834 904
835 /* XSync should get window where it's properly exposed, 905 /* XSync should get window where it's properly exposed,
836 * 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 : */
837 while (XCheckWindowEvent (dpy, src, ExposureMask, &event)) 907 while (XCheckWindowEvent (dpy, src, ExposureMask, &event))
838 ++ev_count; 908 ++ev_count;
839 909
840 if (ev_count > 0); 910 if (ev_count > 0);
911 {
841 { /* hooray! - we can grab the image! */ 912 /* hooray! - we can grab the image! */
842 gc = XCreateGC (dpy, root, 0, NULL); 913 gc = XCreateGC (dpy, root, 0, NULL);
843 if (gc) 914 if (gc)
844 { 915 {
845 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);
846 success = true; 917 success = true;
847 } 918 }
848 } 919 }
920
849 XDestroyWindow (dpy, src); 921 XDestroyWindow (dpy, src);
850 XUngrabServer (dpy); 922 XUngrabServer (dpy);
851 //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);
852 } 924 }
853 925
858 } 930 }
859 else 931 else
860 result |= transpPmapTiled; 932 result |= transpPmapTiled;
861 } 933 }
862 else 934 else
935 {
863 {/* strightforward pixmap copy */ 936 /* strightforward pixmap copy */
864 gcv.tile = root_pixmap; 937 gcv.tile = root_pixmap;
865 gcv.fill_style = FillTiled; 938 gcv.fill_style = FillTiled;
866 939
867 while (sx < 0) sx += (int)root_width; 940 while (sx < 0) sx += (int)root_width;
868 while (sy < 0) sy += (int)root_height; 941 while (sy < 0) sy += (int)root_height;
879 } 952 }
880 TIMING_TEST_PRINT_RESULT (tp); 953 TIMING_TEST_PRINT_RESULT (tp);
881 954
882 if (tiled_root_pmap != None) 955 if (tiled_root_pmap != None)
883 { 956 {
884 if (!need_client_side_rendering ()) 957 if (!need_client_side_rendering ())
885 { 958 {
886 if ((flags & tintNeeded)) 959 if ((flags & tintNeeded))
887 { 960 {
888 if (flags & tintWholesome) 961 if (flags & tintWholesome)
889 { 962 {
890 /* In this case we can tint image server-side getting significant 963 /* In this case we can tint image server-side getting significant
891 * performance improvements, as we eliminate XImage transfer 964 * performance improvements, as we eliminate XImage transfer
916 { 989 {
917 c.r = (c.r * shade) / 100; 990 c.r = (c.r * shade) / 100;
918 c.g = (c.g * shade) / 100; 991 c.g = (c.g * shade) / 100;
919 c.b = (c.b * shade) / 100; 992 c.b = (c.b * shade) / 100;
920 } 993 }
921 else if( shade > 100 && shade < 200) 994 else if (shade > 100 && shade < 200)
922 { 995 {
923 c.r = (c.r * (200 - shade)) / 100; 996 c.r = (c.r * (200 - shade)) / 100;
924 c.g = (c.g * (200 - shade)) / 100; 997 c.g = (c.g * (200 - shade)) / 100;
925 c.b = (c.b * (200 - shade)) / 100; 998 c.b = (c.b * (200 - shade)) / 100;
926 } 999 }
932 pf.direct.greenMask = 0xff; 1005 pf.direct.greenMask = 0xff;
933 pf.direct.blueMask = 0xff; 1006 pf.direct.blueMask = 0xff;
934 pf.direct.alphaMask = 0xff; 1007 pf.direct.alphaMask = 0xff;
935 1008
936 XRenderPictFormat *solid_format = XRenderFindFormat (dpy, 1009 XRenderPictFormat *solid_format = XRenderFindFormat (dpy,
937 (PictFormatType| 1010 (PictFormatType|
938 PictFormatDepth| 1011 PictFormatDepth|
939 PictFormatRedMask| 1012 PictFormatRedMask|
940 PictFormatGreenMask| 1013 PictFormatGreenMask|
941 PictFormatBlueMask| 1014 PictFormatBlueMask|
942 PictFormatAlphaMask), 1015 PictFormatAlphaMask),
943 &pf, 1016 &pf,
944 0); 1017 0);
945 XRenderPictFormat *root_format = XRenderFindVisualFormat (dpy, DefaultVisualOfScreen (ScreenOfDisplay (dpy, target->display->screen))); 1018 XRenderPictFormat *root_format = XRenderFindVisualFormat (dpy, DefaultVisualOfScreen (ScreenOfDisplay (dpy, target->display->screen)));
946 XRenderPictureAttributes pa ; 1019 XRenderPictureAttributes pa ;
947 1020
948 back_pic = XRenderCreatePicture (dpy, tiled_root_pmap, root_format, 0, &pa); 1021 back_pic = XRenderCreatePicture (dpy, tiled_root_pmap, root_format, 0, &pa);
949 1022
951 1024
952 Pixmap overlay_pmap = XCreatePixmap (dpy, root, 1, 1, 32); 1025 Pixmap overlay_pmap = XCreatePixmap (dpy, root, 1, 1, 32);
953 Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa); 1026 Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa);
954 XFreePixmap (dpy, overlay_pmap); 1027 XFreePixmap (dpy, overlay_pmap);
955 1028
956 pa.component_alpha = True; 1029 pa.component_alpha = True;
957 Pixmap mask_pmap = XCreatePixmap (dpy, root, 1, 1, 32); 1030 Pixmap mask_pmap = XCreatePixmap (dpy, root, 1, 1, 32);
958 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);
959 XFreePixmap (dpy, mask_pmap); 1032 XFreePixmap (dpy, mask_pmap);
960 1033
961 if (mask_pic && overlay_pic && back_pic) 1034 if (mask_pic && overlay_pic && back_pic)
972 mask_c.blue = 0xffff - c.b; 1045 mask_c.blue = 0xffff - c.b;
973 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1); 1046 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1);
974 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);
975 result |= transpPmapTinted; 1048 result |= transpPmapTinted;
976 } 1049 }
1050
977 XRenderFreePicture (dpy, mask_pic); 1051 XRenderFreePicture (dpy, mask_pic);
978 XRenderFreePicture (dpy, overlay_pic); 1052 XRenderFreePicture (dpy, overlay_pic);
979 XRenderFreePicture (dpy, back_pic); 1053 XRenderFreePicture (dpy, back_pic);
980# if DO_TIMING_TEST 1054# if DO_TIMING_TEST
981 XSync (dpy, False); 1055 XSync (dpy, False);
982# endif 1056# endif
983# endif 1057# endif
984 } 1058 }
985 } 1059 }
986 } /* server side rendering completed */ 1060 } /* server side rendering completed */
987 1061
991 pixmap = tiled_root_pmap; 1065 pixmap = tiled_root_pmap;
992 pmap_width = window_width; 1066 pmap_width = window_width;
993 pmap_height = window_height; 1067 pmap_height = window_height;
994 pmap_depth = root_depth; 1068 pmap_depth = root_depth;
995 } 1069 }
996 1070
997 if (gc) 1071 if (gc)
998 XFreeGC (dpy, gc); 1072 XFreeGC (dpy, gc);
999 1073
1000 TIMING_TEST_PRINT_RESULT (tp); 1074 TIMING_TEST_PRINT_RESULT (tp);
1001 1075
1002 return result; 1076 return result;
1003} 1077}
1004 1078
1005bool 1079bool
1006bgPixmap_t::set_root_pixmap () 1080bgPixmap_t::set_root_pixmap ()
1007{ 1081{
1008 Pixmap new_root_pixmap = None;
1009
1010 new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID); 1082 Pixmap new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID);
1011 if (new_root_pixmap == None) 1083 if (new_root_pixmap == None)
1012 new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID); 1084 new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID);
1013 1085
1014 if (new_root_pixmap != root_pixmap) 1086 if (new_root_pixmap != root_pixmap)
1015 { 1087 {
1016 root_pixmap = new_root_pixmap; 1088 root_pixmap = new_root_pixmap;
1017 return true; 1089 return true;
1018 } 1090 }
1091
1019 return false; 1092 return false;
1020} 1093}
1021# endif /* ENABLE_TRANSPARENCY */ 1094# endif /* ENABLE_TRANSPARENCY */
1022 1095
1023# ifndef HAVE_AFTERIMAGE 1096# ifndef HAVE_AFTERIMAGE
1024static 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);
1025# endif 1098# endif
1026
1027 1099
1028bool 1100bool
1029bgPixmap_t::render () 1101bgPixmap_t::render ()
1030{ 1102{
1031 unsigned long background_flags = 0; 1103 unsigned long background_flags = 0;
1094 } 1166 }
1095 else if (background_flags && pmap_depth != target->depth) 1167 else if (background_flags && pmap_depth != target->depth)
1096 { 1168 {
1097 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); 1169 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap);
1098 } 1170 }
1171
1099# else /* our own client-side tinting */ 1172# elif !XFT /* our own client-side tinting */
1173
1174 /* ATTENTION: We ASSUME that XFT will let us do all the tinting neccessary server-side.
1175 This may need to be changed in need_client_side_rendering() logic is altered !!! */
1176
1100 if (background_flags && (flags & isInvalid)) 1177 if (background_flags && (flags & isInvalid))
1101 { 1178 {
1102 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); 1179 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap);
1103 if (result != NULL && !(background_flags & transpPmapTinted) && (flags & tintNeeded)) 1180 if (result != NULL && !(background_flags & transpPmapTinted) && (flags & tintNeeded))
1104 { 1181 {
1108 ShadeXImage (target, result, shade, c.r, c.g, c.b); 1185 ShadeXImage (target, result, shade, c.r, c.g, c.b);
1109 } 1186 }
1110 } 1187 }
1111# endif /* HAVE_AFTERIMAGE */ 1188# endif /* HAVE_AFTERIMAGE */
1112 1189
1113 if (result != NULL) 1190 if (result)
1114 { 1191 {
1115 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); 1192 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL);
1193
1116 if (gc) 1194 if (gc)
1117 { 1195 {
1118 if (/*pmap_depth != target->depth &&*/ pixmap != None) 1196 if (/*pmap_depth != target->depth &&*/ pixmap != None)
1119 { 1197 {
1120 XFreePixmap (target->dpy, pixmap); 1198 XFreePixmap (target->dpy, pixmap);
1121 pixmap = None; 1199 pixmap = None;
1122 } 1200 }
1201
1123 if (pixmap == None) 1202 if (pixmap == None)
1124 { 1203 {
1125 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);
1126 pmap_width = result->width; 1205 pmap_width = result->width;
1127 pmap_height = result->height; 1206 pmap_height = result->height;
1128 pmap_depth = target->depth; 1207 pmap_depth = target->depth;
1129 } 1208 }
1209
1130 if (pmap_depth != result->depth) 1210 if (pmap_depth != result->depth)
1211 {
1131 { /* Bad Match error will ensue ! stupid X !!!! */ 1212 /* Bad Match error will ensue ! stupid X !!!! */
1132 if( result->depth == 24 && pmap_depth == 32) 1213 if (result->depth == 24 && pmap_depth == 32)
1133 result->depth = 32; 1214 result->depth = 32;
1134 else if( result->depth == 32 && pmap_depth == 24) 1215 else if (result->depth == 32 && pmap_depth == 24)
1135 result->depth = 24; 1216 result->depth = 24;
1136 else 1217 else
1137 { 1218 {
1138 /* TODO: implement image recoding */ 1219 /* TODO: implement image recoding */
1139 } 1220 }
1140 } 1221 }
1222
1141 if (pmap_depth == result->depth) 1223 if (pmap_depth == result->depth)
1142 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
1143 XFreeGC (target->dpy, gc); 1226 XFreeGC (target->dpy, gc);
1144 flags = flags & ~isInvalid; 1227 flags = flags & ~isInvalid;
1145 } 1228 }
1229
1146 XDestroyImage (result); 1230 XDestroyImage (result);
1147 } 1231 }
1148 1232
1149 if (flags & isInvalid) 1233 if (flags & isInvalid)
1150 { 1234 {
1155 } 1239 }
1156 } 1240 }
1157 1241
1158 apply (); 1242 apply ();
1159 1243
1244 XSync (target->dpy, False);
1245 valid_since = ev::now ();
1246
1160 TIMING_TEST_PRINT_RESULT (tp); 1247 TIMING_TEST_PRINT_RESULT (tp);
1161 1248
1162 return true; 1249 return true;
1163} 1250}
1164 1251
1165bool 1252bool
1166bgPixmap_t::set_target (rxvt_term *new_target) 1253bgPixmap_t::set_target (rxvt_term *new_target)
1167{ 1254{
1168 if (new_target) 1255 if (new_target)
1169 if (target != new_target) 1256 if (target != new_target)
1170 { 1257 {
1176 } 1263 }
1177 return false; 1264 return false;
1178} 1265}
1179 1266
1180void 1267void
1181bgPixmap_t::apply() 1268bgPixmap_t::apply ()
1182{ 1269{
1183 if (target) 1270 if (target)
1184 { 1271 {
1185 flags &= ~isVtOrigin; 1272 flags &= ~isVtOrigin;
1186 if (pixmap != None) 1273 if (pixmap != None)
1274 {
1187 { /* set target's background to pixmap */ 1275 /* set target's background to pixmap */
1188# ifdef ENABLE_TRANSPARENCY 1276# ifdef ENABLE_TRANSPARENCY
1189 if (flags & isTransparent) 1277 if (flags & isTransparent)
1190 { 1278 {
1191 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap); 1279 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap);
1192 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative); 1280 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative);
1208 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); 1296 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1209# endif 1297# endif
1210 } 1298 }
1211 } 1299 }
1212 else 1300 else
1301 {
1213 { /* set target background to a pixel */ 1302 /* set target background to a pixel */
1214 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); 1303 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
1215 XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); 1304 XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]);
1216 /* do we also need to set scrollbar's background here ? */ 1305 /* do we also need to set scrollbar's background here ? */
1217# if HAVE_SCROLLBARS 1306# if HAVE_SCROLLBARS
1218 if (target->scrollBar.win) 1307 if (target->scrollBar.win)
1219 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); 1308 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1220# endif 1309# endif
1221 } 1310 }
1222 /* 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
1223 scr_touch or we get a great deal of flicker otherwise: */ 1312 scr_touch or we get a great deal of flicker otherwise: */
1224 XClearWindow (target->dpy, target->parent[0]); 1313 XClearWindow (target->dpy, target->parent[0]);
1225 1314
1226# if HAVE_SCROLLBARS 1315# if HAVE_SCROLLBARS
1227 if (target->scrollBar.win) 1316 if (target->scrollBar.win)
1234 target->want_refresh = 1; 1323 target->want_refresh = 1;
1235 flags |= hasChanged; 1324 flags |= hasChanged;
1236 } 1325 }
1237} 1326}
1238 1327
1239#endif /* HAVE_BG_PIXMAP */ 1328#endif /* HAVE_BG_PIXMAP */
1240 1329
1241#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) 1330#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) && !XFT
1242/* taken from aterm-0.4.2 */ 1331/* taken from aterm-0.4.2 */
1243 1332
1244typedef uint32_t RUINT32T; 1333typedef uint32_t RUINT32T;
1245 1334
1246static void 1335static void

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines