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.9 by sasha, Mon Oct 29 13:39:43 2007 UTC vs.
Revision 1.24 by ayin, Mon Jan 7 12:41:31 2008 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines