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.10 by ayin, Wed Oct 31 09:55:23 2007 UTC vs.
Revision 1.25 by root, Sat Jan 19 00:21:59 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) \
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{
92 // this is basically redundant as bgPixmap_t is only used in
93 // zero_initialised-derived structs
94#ifdef HAVE_AFTERIMAGE 94#ifdef HAVE_AFTERIMAGE
95 original_asim = NULL; 95 original_asim = NULL;
96#endif 96#endif
97#ifdef BG_IMAGE_FROM_FILE 97#ifdef BG_IMAGE_FROM_FILE
98 h_scale = v_scale = 0; 98 h_scale = v_scale = 0;
99 h_align = v_align = 0; 99 h_align = v_align = 0;
100#endif 100#endif
101 flags = 0; 101 flags = 0;
102 pixmap = None; 102 pixmap = None;
103 valid_since = invalid_since = 0;
104 target = 0;
103} 105}
104 106
107void
108bgPixmap_t::destroy ()
109{
110#ifdef HAVE_AFTERIMAGE
111 if (original_asim)
112 safe_asimage_destroy (original_asim);
113#endif
114
115 if (pixmap && target)
116 XFreePixmap (target->dpy, pixmap);
117}
105 118
106bool 119bool
107bgPixmap_t::window_size_sensitive () 120bgPixmap_t::window_size_sensitive ()
108{ 121{
109# ifdef BG_IMAGE_FROM_FILE
110# ifdef HAVE_AFTERIMAGE
111 if (original_asim != NULL)
112# endif
113 {
114 if (h_scale != 0 || v_scale != 0
115 || h_align != 0 || v_align != 0)
116 return true;
117 }
118# endif
119# ifdef ENABLE_TRANSPARENCY 122# ifdef ENABLE_TRANSPARENCY
120 if (flags & isTransparent) 123 if (flags & isTransparent)
121 return true; 124 return true;
122# endif 125# endif
126
127# ifdef BG_IMAGE_FROM_FILE
128# ifdef HAVE_AFTERIMAGE
129 if (original_asim)
130# endif
131 {
132 if (h_scale != 0 || v_scale != 0
133 || h_align != 0 || v_align != 0)
134 return true;
135 }
136# endif
137
123 return false; 138 return false;
124} 139}
125 140
141bool
142bgPixmap_t::window_position_sensitive ()
143{
144# ifdef ENABLE_TRANSPARENCY
145 if (flags & isTransparent)
146 return true;
147# endif
148
149# ifdef BG_IMAGE_FROM_FILE
150# ifdef HAVE_AFTERIMAGE
151 if (original_asim)
152# endif
153 {
154 if (h_align == rootAlign || v_align == rootAlign)
155 return true;
156 }
157# endif
158
159 return false;
160};
161
126bool bgPixmap_t::need_client_side_rendering () 162bool bgPixmap_t::need_client_side_rendering ()
127{ 163{
128# ifdef HAVE_AFTERIMAGE 164# ifdef HAVE_AFTERIMAGE
129 if (original_asim != NULL) 165 if (original_asim)
130 return true; 166 return true;
131# endif 167# endif
132# ifdef ENABLE_TRANSPARENCY 168# ifdef ENABLE_TRANSPARENCY
133 if (flags & isTransparent) 169 if (flags & isTransparent)
134 { 170 {
163static inline bool 199static inline bool
164check_set_align_value (int geom_flags, int flag, int &align, int new_value) 200check_set_align_value (int geom_flags, int flag, int &align, int new_value)
165{ 201{
166 if (geom_flags & flag) 202 if (geom_flags & flag)
167 { 203 {
204 if (new_value != bgPixmap_t::rootAlign)
205 {
168 if (new_value < -100) 206 if (new_value < -100)
169 new_value = -100; 207 new_value = -100;
170 else if (new_value > 200) 208 else if (new_value > 200)
171 new_value = 200; 209 new_value = 200;
210 }
172 if (new_value != align) 211 if (new_value != align)
173 { 212 {
174 align = new_value; 213 align = new_value;
175 return true; 214 return true;
176 } 215 }
221 int x = 0, y = 0; 260 int x = 0, y = 0;
222 unsigned int w = 0, h = 0; 261 unsigned int w = 0, h = 0;
223 unsigned int n; 262 unsigned int n;
224 unsigned long new_flags = (flags & (~geometryFlags)); 263 unsigned long new_flags = (flags & (~geometryFlags));
225 char *p; 264 char *p;
226# define MAXLEN_GEOM 256 /* could be longer then regular geometry string */ 265# define MAXLEN_GEOM 256 /* could be longer than regular geometry string */
227 266
228 if (geom == NULL) 267 if (geom == NULL)
229 return false; 268 return false;
230 269
231 char str[MAXLEN_GEOM]; 270 char str[MAXLEN_GEOM];
238 if (n < MAXLEN_GEOM) 277 if (n < MAXLEN_GEOM)
239 { 278 {
240 char *ops; 279 char *ops;
241 new_flags |= geometrySet; 280 new_flags |= geometrySet;
242 281
243 strncpy (str, geom, n); 282 memcpy (str, geom, n);
244 str[n] = '\0'; 283 str[n] = '\0';
245 if (str[0] == ':') 284 if (str[0] == ':')
246 ops = &str[0]; 285 ops = &str[0];
247 else if (str[0] != 'x' && str[0] != 'X' && isalpha(str[0])) 286 else if (str[0] != 'x' && str[0] != 'X' && isalpha(str[0]))
248 ops = &str[0]; 287 ops = &str[0];
268 y = x; 307 y = x;
269 geom_flags |= YValue; 308 geom_flags |= YValue;
270 } 309 }
271 310
272 if (flags & geometrySet) 311 if (flags & geometrySet)
312 {
273 {/* new geometry is an adjustment to the old one ! */ 313 /* new geometry is an adjustment to the old one ! */
274 if ((geom_flags & WidthValue) && (geom_flags & HeightValue)) 314 if ((geom_flags & WidthValue) && (geom_flags & HeightValue))
275 { 315 {
276 if (w == 0 && h != 0) 316 if (w == 0 && h != 0)
277 { 317 {
278 w = h_scale; 318 w = h_scale;
294 } 334 }
295 } 335 }
296 else /* setting up geometry from scratch */ 336 else /* setting up geometry from scratch */
297 { 337 {
298 if (!(geom_flags & XValue)) 338 if (!(geom_flags & XValue))
339 {
299 {/* use default geometry - centered */ 340 /* use default geometry - centered */
300 x = y = defaultAlign; 341 x = y = defaultAlign;
301 } 342 }
302 else if (!(geom_flags & YValue)) 343 else if (!(geom_flags & YValue))
303 y = x; 344 y = x;
304 345
305 if ((geom_flags & (WidthValue|HeightValue)) == 0) 346 if ((geom_flags & (WidthValue|HeightValue)) == 0)
347 {
306 {/* use default geometry - scaled */ 348 /* use default geometry - scaled */
307 w = h = defaultScale; 349 w = h = defaultScale;
308 } 350 }
309 else if (geom_flags & WidthValue) 351 else if (geom_flags & WidthValue)
310 { 352 {
311 if (!(geom_flags & HeightValue)) 353 if (!(geom_flags & HeightValue))
314 else 356 else
315 w = h; 357 w = h;
316 } 358 }
317 } /* done parsing geometry string */ 359 } /* done parsing geometry string */
318 else if (!(flags & geometrySet)) 360 else if (!(flags & geometrySet))
361 {
319 { /* default geometry - scaled and centered */ 362 /* default geometry - scaled and centered */
320 x = y = defaultAlign; 363 x = y = defaultAlign;
321 w = h = defaultScale; 364 w = h = defaultScale;
322 } 365 }
323 366
324 if (!(flags & geometrySet)) 367 if (!(flags & geometrySet))
330 { 373 {
331 while (*ops == ':' || isspace(*ops)) ++ops; 374 while (*ops == ':' || isspace(*ops)) ++ops;
332# define CHECK_GEOM_OPS(op_str) (strncasecmp (ops, (op_str), sizeof(op_str)-1) == 0) 375# define CHECK_GEOM_OPS(op_str) (strncasecmp (ops, (op_str), sizeof(op_str)-1) == 0)
333 if (CHECK_GEOM_OPS("tile")) 376 if (CHECK_GEOM_OPS("tile"))
334 { 377 {
335 w = h = 0; 378 w = h = noScale;
336 geom_flags |= WidthValue|HeightValue; 379 geom_flags |= WidthValue|HeightValue;
337 } 380 }
338 else if (CHECK_GEOM_OPS("propscale")) 381 else if (CHECK_GEOM_OPS("propscale"))
339 { 382 {
340 if (w == 0 && h == 0) 383 if (w == 0 && h == 0)
341 { 384 {
342 w = 100; 385 w = windowScale;
343 geom_flags |= WidthValue; 386 geom_flags |= WidthValue;
344 } 387 }
345 new_flags |= propScale; 388 new_flags |= propScale;
346 } 389 }
347 else if (CHECK_GEOM_OPS("hscale")) 390 else if (CHECK_GEOM_OPS("hscale"))
348 { 391 {
349 if (w == 0) 392 if (w == 0)
350 w = 100; 393 w = windowScale;
351 h = 0; 394 h = noScale;
352 geom_flags |= WidthValue|HeightValue; 395 geom_flags |= WidthValue|HeightValue;
353 } 396 }
354 else if (CHECK_GEOM_OPS("vscale")) 397 else if (CHECK_GEOM_OPS("vscale"))
355 { 398 {
356 if (h == 0) 399 if (h == 0)
357 h = 100; 400 h = windowScale;
358 w = 0; 401 w = noScale;
359 geom_flags |= WidthValue|HeightValue; 402 geom_flags |= WidthValue|HeightValue;
360 } 403 }
361 else if (CHECK_GEOM_OPS("scale")) 404 else if (CHECK_GEOM_OPS("scale"))
362 { 405 {
363 if (h == 0) 406 if (h == 0)
364 h = 100; 407 h = windowScale;
365 if (w == 0) 408 if (w == 0)
366 w = 100; 409 w = windowScale;
367 geom_flags |= WidthValue|HeightValue; 410 geom_flags |= WidthValue|HeightValue;
368 } 411 }
369 else if (CHECK_GEOM_OPS("auto")) 412 else if (CHECK_GEOM_OPS("auto"))
370 { 413 {
414 w = h = windowScale;
415 x = y = centerAlign;
416 geom_flags |= WidthValue|HeightValue|XValue|YValue;
417 }
418 else if (CHECK_GEOM_OPS("root"))
419 {
371 w = h = 100; 420 w = h = noScale;
372 x = y = 50; 421 x = y = rootAlign;
373 geom_flags |= WidthValue|HeightValue|XValue|YValue; 422 geom_flags |= WidthValue|HeightValue|XValue|YValue;
374 } 423 }
375# undef CHECK_GEOM_OPS 424# undef CHECK_GEOM_OPS
376 while (*ops != ':' && *ops != '\0') ++ops; 425 while (*ops != ':' && *ops != '\0') ++ops;
377 } /* done parsing ops */ 426 } /* done parsing ops */
390 if (new_flags != flags) 439 if (new_flags != flags)
391 { 440 {
392 flags = new_flags; 441 flags = new_flags;
393 changed++; 442 changed++;
394 } 443 }
395//fprintf( stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n", 444//fprintf (stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n",
396// flags, h_scale, v_scale, h_align, v_align); 445// flags, h_scale, v_scale, h_align, v_align);
397 return (changed > 0); 446 return (changed > 0);
398} 447}
399 448
400# ifdef HAVE_AFTERIMAGE 449# ifdef HAVE_AFTERIMAGE
416 465
417 TIMING_TEST_START (asim); 466 TIMING_TEST_START (asim);
418 467
419 if (original_asim) 468 if (original_asim)
420 { 469 {
470 if (h_align == rootAlign || v_align == rootAlign)
471 {
472 target->get_window_origin(x, y);
473 x = -x;
474 y = -y;
475 }
476
477 if (h_align != rootAlign)
421 x = make_align_position (h_align, target_width, w > 0 ? w : (int)original_asim->width); 478 x = make_align_position (h_align, target_width, w > 0 ? w : (int)original_asim->width);
479
480 if (v_align != rootAlign)
422 y = make_align_position (v_align, target_height, h > 0 ? h : (int)original_asim->height); 481 y = make_align_position (v_align, target_height, h > 0 ? h : (int)original_asim->height);
423 } 482 }
424 483
425 if (original_asim == NULL 484 if (!original_asim
426 || x >= target_width 485 || x >= target_width
427 || y >= target_height 486 || y >= target_height
428 || (w > 0 && x + w <= 0) 487 || (w > 0 && x + w <= 0)
429 || (h > 0 && y + h <= 0)) 488 || (h > 0 && y + h <= 0))
430 { 489 {
431 if (background) 490 if (background)
432 { 491 {
433 new_pmap_width = background->width; 492 new_pmap_width = background->width;
434 new_pmap_height = background->height; 493 new_pmap_height = background->height;
435 result = background; 494 result = background;
495
436 if (background_tint != TINT_LEAVE_SAME) 496 if (background_tint != TINT_LEAVE_SAME)
437 { 497 {
438 ASImage* tmp = tile_asimage (target->asv, background, 0, 0, 498 ASImage* tmp = tile_asimage (target->asv, background, 0, 0,
439 target_width, target_height, background_tint, 499 target_width, target_height, background_tint,
440 ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT); 500 ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT);
446 new_pmap_width = new_pmap_height = 0; 506 new_pmap_width = new_pmap_height = 0;
447 } 507 }
448 else 508 else
449 { 509 {
450 result = original_asim; 510 result = original_asim;
511
451 if ((w > 0 && w != original_asim->width) 512 if ((w > 0 && w != original_asim->width)
452 || (h > 0 && h != original_asim->height)) 513 || (h > 0 && h != original_asim->height))
453 { 514 {
454 result = scale_asimage (target->asv, original_asim, 515 result = scale_asimage (target->asv, original_asim,
455 w > 0 ? w : original_asim->width, 516 w > 0 ? w : original_asim->width,
456 h > 0 ? h : original_asim->height, 517 h > 0 ? h : original_asim->height,
457 background ? ASA_ASImage : ASA_XImage, 518 background ? ASA_ASImage : ASA_XImage,
458 100, ASIMAGE_QUALITY_DEFAULT); 519 100, ASIMAGE_QUALITY_DEFAULT);
459 } 520 }
521
460 if (background == NULL) 522 if (background == NULL)
523 {
461 {/* if tiling - pixmap has to be sized exactly as the image */ 524 /* if tiling - pixmap has to be sized exactly as the image,
525 but there is no need to make it bigger than the window! */
462 if (h_scale == 0) 526 if (h_scale == 0)
463 new_pmap_width = result->width; 527 new_pmap_width = min (result->width, target_width);
464 if (v_scale == 0) 528 if (v_scale == 0)
465 new_pmap_height = result->height; 529 new_pmap_height = min (result->height, target_height);
466 /* we also need to tile our image in one or both directions */ 530 /* we also need to tile our image in one or both directions */
467 if (h_scale == 0 || v_scale == 0) 531 if (h_scale == 0 || v_scale == 0)
468 { 532 {
469 ASImage *tmp = tile_asimage (target->asv, result, 533 ASImage *tmp = tile_asimage (target->asv, result,
470 (h_scale > 0) ? 0 : (int)result->width - x, 534 (h_scale > 0) ? 0 : (int)result->width - x,
471 (v_scale > 0) ? 0 : (int)result->height - y, 535 (v_scale > 0) ? 0 : (int)result->height - y,
536 new_pmap_width,
472 result->width, result->height, 537 new_pmap_height,
473 TINT_LEAVE_SAME, ASA_XImage, 538 TINT_LEAVE_SAME, ASA_XImage,
474 100, ASIMAGE_QUALITY_DEFAULT); 539 100, ASIMAGE_QUALITY_DEFAULT);
475 if (tmp) 540 if (tmp)
476 { 541 {
477 if (result != original_asim) 542 if (result != original_asim)
478 destroy_asimage (&result); 543 destroy_asimage (&result);
544
479 result = tmp; 545 result = tmp;
480 } 546 }
481 } 547 }
482 } 548 }
483 else 549 else
550 {
484 {/* if blending background and image - pixmap has to be sized same as target window */ 551 /* if blending background and image - pixmap has to be sized same as target window */
485 ASImageLayer *layers = create_image_layers (2); 552 ASImageLayer *layers = create_image_layers (2);
486 ASImage *merged_im = NULL; 553 ASImage *merged_im = NULL;
487 554
488 layers[0].im = background; 555 layers[0].im = background;
489 layers[0].clip_width = target_width; 556 layers[0].clip_width = target_width;
490 layers[0].clip_height = target_height; 557 layers[0].clip_height = target_height;
491 layers[0].tint = background_tint; 558 layers[0].tint = background_tint;
492 layers[1].im = result; 559 layers[1].im = result;
560
493 if (w <= 0) 561 if (w <= 0)
562 {
494 {/* tile horizontally */ 563 /* tile horizontally */
495 while (x > 0) x -= (int)result->width; 564 while (x > 0) x -= (int)result->width;
496 layers[1].dst_x = x; 565 layers[1].dst_x = x;
497 layers[1].clip_width = result->width+target_width; 566 layers[1].clip_width = result->width+target_width;
498 } 567 }
499 else 568 else
569 {
500 {/* clip horizontally */ 570 /* clip horizontally */
501 layers[1].dst_x = x; 571 layers[1].dst_x = x;
502 layers[1].clip_width = result->width; 572 layers[1].clip_width = result->width;
503 } 573 }
574
504 if (h <= 0) 575 if (h <= 0)
505 { 576 {
506 while (y > 0) y -= (int)result->height; 577 while (y > 0) y -= (int)result->height;
507 layers[1].dst_y = y; 578 layers[1].dst_y = y;
508 layers[1].clip_height = result->height + target_height; 579 layers[1].clip_height = result->height + target_height;
510 else 581 else
511 { 582 {
512 layers[1].dst_y = y; 583 layers[1].dst_y = y;
513 layers[1].clip_height = result->height; 584 layers[1].clip_height = result->height;
514 } 585 }
586
515 if (target->rs[Rs_blendtype]) 587 if (target->rs[Rs_blendtype])
516 { 588 {
517 layers[1].merge_scanlines = blend_scanlines_name2func (target->rs[Rs_blendtype]); 589 layers[1].merge_scanlines = blend_scanlines_name2func (target->rs[Rs_blendtype]);
518 if (layers[1].merge_scanlines == NULL) 590 if (layers[1].merge_scanlines == NULL)
519 layers[1].merge_scanlines = alphablend_scanlines; 591 layers[1].merge_scanlines = alphablend_scanlines;
520 } 592 }
593
521 ASImage *tmp = merge_layers (target->asv, layers, 2, target_width, target_height, 594 ASImage *tmp = merge_layers (target->asv, layers, 2, target_width, target_height,
522 ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT); 595 ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT);
596
523 if (tmp) 597 if (tmp)
524 { 598 {
525 if (result != original_asim) 599 if (result != original_asim)
526 destroy_asimage (&result); 600 destroy_asimage (&result);
601
527 result = tmp; 602 result = tmp;
528 } 603 }
604
529 free (layers); 605 free (layers);
530 } 606 }
531 } 607 }
532 TIMING_TEST_PRINT_RESULT (asim); 608 TIMING_TEST_PRINT_RESULT (asim);
533 609
595bool 671bool
596bgPixmap_t::set_file (const char *file) 672bgPixmap_t::set_file (const char *file)
597{ 673{
598 char *f; 674 char *f;
599 675
600 assert (file != NULL); 676 assert (file);
601 677
602 if (*file != '\0') 678 if (*file)
603 { 679 {
604# ifdef HAVE_AFTERIMAGE 680# ifdef HAVE_AFTERIMAGE
605 if (target->asimman == NULL) 681 if (target->asimman == NULL)
606 target->asimman = create_generic_imageman (target->rs[Rs_path]); 682 target->asimman = create_generic_imageman (target->rs[Rs_path]);
683
607 if ((f = strchr (file, ';')) == NULL) 684 if ((f = strchr (file, ';')) == NULL)
608 original_asim = get_asimage (target->asimman, file, 0xFFFFFFFF, 100); 685 original_asim = get_asimage (target->asimman, file, 0xFFFFFFFF, 100);
609 else 686 else
610 { 687 {
611 size_t len = f - file; 688 size_t len = f - file;
612 f = (char *)malloc (len + 1); 689 f = (char *)malloc (len + 1);
613 strncpy (f, file, len); 690 memcpy (f, file, len);
614 f[len] = '\0'; 691 f[len] = '\0';
615 original_asim = get_asimage (target->asimman, f, 0xFFFFFFFF, 100); 692 original_asim = get_asimage (target->asimman, f, 0xFFFFFFFF, 100);
616 free (f); 693 free (f);
617 } 694 }
695
618 return (original_asim != NULL); 696 return original_asim;
619# endif 697# endif
620 } 698 }
699
621 return false; 700 return false;
622} 701}
623 702
624# endif /* BG_IMAGE_FROM_FILE */ 703# endif /* BG_IMAGE_FROM_FILE */
625 704
626# ifdef ENABLE_TRANSPARENCY 705# ifdef ENABLE_TRANSPARENCY
627bool 706bool
628bgPixmap_t::set_transparent () 707bgPixmap_t::set_transparent ()
629{ 708{
630 if (!(flags & isTransparent)) 709 if (!(flags & isTransparent))
631 { 710 {
632 flags |= isTransparent; 711 flags |= isTransparent;
633 return true; 712 return true;
634 } 713 }
714
635 return false; 715 return false;
636} 716}
637 717
638bool 718bool
639bgPixmap_t::set_blur_radius (const char *geom) 719bgPixmap_t::set_blur_radius (const char *geom)
720 unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade); 800 unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade);
721 tint = new_tint; 801 tint = new_tint;
722 flags = (flags & ~tintFlags) | new_flags | tintSet; 802 flags = (flags & ~tintFlags) | new_flags | tintSet;
723 return true; 803 return true;
724 } 804 }
805
725 return false; 806 return false;
726} 807}
727 808
728bool 809bool
729bgPixmap_t::unset_tint () 810bgPixmap_t::unset_tint ()
733 if (new_flags != (flags & tintFlags)) 814 if (new_flags != (flags & tintFlags))
734 { 815 {
735 flags = (flags&~tintFlags)|new_flags; 816 flags = (flags&~tintFlags)|new_flags;
736 return true; 817 return true;
737 } 818 }
819
738 return false; 820 return false;
739} 821}
740 822
741bool 823bool
742bgPixmap_t::set_shade (const char *shade_str) 824bgPixmap_t::set_shade (const char *shade_str)
743{ 825{
744 int new_shade = (shade_str) ? atoi (shade_str) : 0; 826 int new_shade = (shade_str) ? atoi (shade_str) : 0;
745 827
746 if (new_shade < 0 && new_shade > -100) 828 if (new_shade < 0 && new_shade > -100)
747 new_shade = 200 - (100 + new_shade); 829 new_shade = 200 - (100 + new_shade);
748 else if (new_shade == 100) 830 else if (new_shade == 100)
749 new_shade = 0; 831 new_shade = 0;
750 832
751 if (new_shade != shade) 833 if (new_shade != shade)
752 { 834 {
753 unsigned long new_flags = compute_tint_shade_flags ((flags & tintSet) ? &tint : NULL, new_shade); 835 unsigned long new_flags = compute_tint_shade_flags ((flags & tintSet) ? &tint : NULL, new_shade);
754 shade = new_shade; 836 shade = new_shade;
755 flags = (flags & (~tintFlags | tintSet)) | new_flags; 837 flags = (flags & (~tintFlags | tintSet)) | new_flags;
756 return true; 838 return true;
757 } 839 }
840
758 return false; 841 return false;
759} 842}
760 843
761/* make_transparency_pixmap() 844/* make_transparency_pixmap()
762 * Builds a pixmap sized the same as terminal window, with depth same as the root window 845 * Builds a pixmap sized the same as terminal window, with depth same as the root window
792 if (sx + window_width <= 0 || sy + window_height <= 0 875 if (sx + window_width <= 0 || sy + window_height <= 0
793 || sx >= root_width || sy >= root_height) 876 || sx >= root_width || sy >= root_height)
794 return 0; 877 return 0;
795 878
796 if (root_pixmap != None) 879 if (root_pixmap != None)
880 {
797 {/* we want to validate the pixmap and get it's size at the same time : */ 881 /* we want to validate the pixmap and get it's size at the same time : */
798 int junk; 882 int junk;
799 unsigned int ujunk; 883 unsigned int ujunk;
800 /* root pixmap may be bad - allow a error */ 884 /* root pixmap may be bad - allow a error */
801 target->allowedxerror = -1; 885 target->allowedxerror = -1;
802 886
811 895
812 if (tiled_root_pmap == None) /* something really bad happened - abort */ 896 if (tiled_root_pmap == None) /* something really bad happened - abort */
813 return 0; 897 return 0;
814 898
815 if (root_pixmap == None) 899 if (root_pixmap == None)
900 {
816 { /* use tricks to obtain the root background image :*/ 901 /* use tricks to obtain the root background image :*/
817 /* we want to create Overrideredirect window overlapping out window 902 /* we want to create Overrideredirect window overlapping out window
818 with background type of Parent Relative and then grab it */ 903 with background type of Parent Relative and then grab it */
819 XSetWindowAttributes attr; 904 XSetWindowAttributes attr;
820 Window src; 905 Window src;
821 bool success = false; 906 bool success = false;
836 XGrabServer (dpy); 921 XGrabServer (dpy);
837 XMapRaised (dpy, src); 922 XMapRaised (dpy, src);
838 XSync (dpy, False); 923 XSync (dpy, False);
839 924
840 /* XSync should get window where it's properly exposed, 925 /* 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 : */ 926 * but to be on the safe side - let's check for the actual event to arrive : */
842 while (XCheckWindowEvent (dpy, src, ExposureMask, &event)) 927 while (XCheckWindowEvent (dpy, src, ExposureMask, &event))
843 ++ev_count; 928 ++ev_count;
844 929
845 if (ev_count > 0); 930 if (ev_count > 0);
931 {
846 { /* hooray! - we can grab the image! */ 932 /* hooray! - we can grab the image! */
847 gc = XCreateGC (dpy, root, 0, NULL); 933 gc = XCreateGC (dpy, root, 0, NULL);
848 if (gc) 934 if (gc)
849 { 935 {
850 XCopyArea (dpy, src, tiled_root_pmap, gc, 0, 0, window_width, window_height, 0, 0); 936 XCopyArea (dpy, src, tiled_root_pmap, gc, 0, 0, window_width, window_height, 0, 0);
851 success = true; 937 success = true;
852 } 938 }
853 } 939 }
940
854 XDestroyWindow (dpy, src); 941 XDestroyWindow (dpy, src);
855 XUngrabServer (dpy); 942 XUngrabServer (dpy);
856 //fprintf (stderr, "%s:%d: ev_count = %d\n", __FUNCTION__, __LINE__, ev_count); 943 //fprintf (stderr, "%s:%d: ev_count = %d\n", __FUNCTION__, __LINE__, ev_count);
857 } 944 }
858 945
863 } 950 }
864 else 951 else
865 result |= transpPmapTiled; 952 result |= transpPmapTiled;
866 } 953 }
867 else 954 else
955 {
868 {/* strightforward pixmap copy */ 956 /* strightforward pixmap copy */
869 gcv.tile = root_pixmap; 957 gcv.tile = root_pixmap;
870 gcv.fill_style = FillTiled; 958 gcv.fill_style = FillTiled;
871 959
872 while (sx < 0) sx += (int)root_width; 960 while (sx < 0) sx += (int)root_width;
873 while (sy < 0) sy += (int)root_height; 961 while (sy < 0) sy += (int)root_height;
921 { 1009 {
922 c.r = (c.r * shade) / 100; 1010 c.r = (c.r * shade) / 100;
923 c.g = (c.g * shade) / 100; 1011 c.g = (c.g * shade) / 100;
924 c.b = (c.b * shade) / 100; 1012 c.b = (c.b * shade) / 100;
925 } 1013 }
926 else if( shade > 100 && shade < 200) 1014 else if (shade > 100 && shade < 200)
927 { 1015 {
928 c.r = (c.r * (200 - shade)) / 100; 1016 c.r = (c.r * (200 - shade)) / 100;
929 c.g = (c.g * (200 - shade)) / 100; 1017 c.g = (c.g * (200 - shade)) / 100;
930 c.b = (c.b * (200 - shade)) / 100; 1018 c.b = (c.b * (200 - shade)) / 100;
931 } 1019 }
977 mask_c.blue = 0xffff - c.b; 1065 mask_c.blue = 0xffff - c.b;
978 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1); 1066 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); 1067 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, window_width, window_height);
980 result |= transpPmapTinted; 1068 result |= transpPmapTinted;
981 } 1069 }
1070
982 XRenderFreePicture (dpy, mask_pic); 1071 XRenderFreePicture (dpy, mask_pic);
983 XRenderFreePicture (dpy, overlay_pic); 1072 XRenderFreePicture (dpy, overlay_pic);
984 XRenderFreePicture (dpy, back_pic); 1073 XRenderFreePicture (dpy, back_pic);
985# if DO_TIMING_TEST 1074# if DO_TIMING_TEST
986 XSync (dpy, False); 1075 XSync (dpy, False);
1008} 1097}
1009 1098
1010bool 1099bool
1011bgPixmap_t::set_root_pixmap () 1100bgPixmap_t::set_root_pixmap ()
1012{ 1101{
1013 Pixmap new_root_pixmap = None;
1014
1015 new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID); 1102 Pixmap new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID);
1016 if (new_root_pixmap == None) 1103 if (new_root_pixmap == None)
1017 new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID); 1104 new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID);
1018 1105
1019 if (new_root_pixmap != root_pixmap) 1106 if (new_root_pixmap != root_pixmap)
1020 { 1107 {
1021 root_pixmap = new_root_pixmap; 1108 root_pixmap = new_root_pixmap;
1022 return true; 1109 return true;
1023 } 1110 }
1111
1024 return false; 1112 return false;
1025} 1113}
1026# endif /* ENABLE_TRANSPARENCY */ 1114# endif /* ENABLE_TRANSPARENCY */
1027 1115
1028# ifndef HAVE_AFTERIMAGE 1116# ifndef HAVE_AFTERIMAGE
1029static void ShadeXImage(rxvt_term *term, XImage* srcImage, int shade, int rm, int gm, int bm); 1117static void ShadeXImage(rxvt_term *term, XImage* srcImage, int shade, int rm, int gm, int bm);
1030# endif 1118# endif
1031
1032 1119
1033bool 1120bool
1034bgPixmap_t::render () 1121bgPixmap_t::render ()
1035{ 1122{
1036 unsigned long background_flags = 0; 1123 unsigned long background_flags = 0;
1118 ShadeXImage (target, result, shade, c.r, c.g, c.b); 1205 ShadeXImage (target, result, shade, c.r, c.g, c.b);
1119 } 1206 }
1120 } 1207 }
1121# endif /* HAVE_AFTERIMAGE */ 1208# endif /* HAVE_AFTERIMAGE */
1122 1209
1123 if (result != NULL) 1210 if (result)
1124 { 1211 {
1125 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); 1212 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL);
1213
1126 if (gc) 1214 if (gc)
1127 { 1215 {
1128 if (/*pmap_depth != target->depth &&*/ pixmap != None) 1216 if (/*pmap_depth != target->depth &&*/ pixmap != None)
1129 { 1217 {
1130 XFreePixmap (target->dpy, pixmap); 1218 XFreePixmap (target->dpy, pixmap);
1131 pixmap = None; 1219 pixmap = None;
1132 } 1220 }
1221
1133 if (pixmap == None) 1222 if (pixmap == None)
1134 { 1223 {
1135 pixmap = XCreatePixmap (target->dpy, target->vt, result->width, result->height, target->depth); 1224 pixmap = XCreatePixmap (target->dpy, target->vt, result->width, result->height, target->depth);
1136 pmap_width = result->width; 1225 pmap_width = result->width;
1137 pmap_height = result->height; 1226 pmap_height = result->height;
1138 pmap_depth = target->depth; 1227 pmap_depth = target->depth;
1139 } 1228 }
1229
1140 if (pmap_depth != result->depth) 1230 if (pmap_depth != result->depth)
1231 {
1141 { /* Bad Match error will ensue ! stupid X !!!! */ 1232 /* Bad Match error will ensue ! stupid X !!!! */
1142 if( result->depth == 24 && pmap_depth == 32) 1233 if (result->depth == 24 && pmap_depth == 32)
1143 result->depth = 32; 1234 result->depth = 32;
1144 else if( result->depth == 32 && pmap_depth == 24) 1235 else if (result->depth == 32 && pmap_depth == 24)
1145 result->depth = 24; 1236 result->depth = 24;
1146 else 1237 else
1147 { 1238 {
1148 /* TODO: implement image recoding */ 1239 /* TODO: implement image recoding */
1149 } 1240 }
1150 } 1241 }
1242
1151 if (pmap_depth == result->depth) 1243 if (pmap_depth == result->depth)
1152 XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height); 1244 XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height);
1245
1153 XFreeGC (target->dpy, gc); 1246 XFreeGC (target->dpy, gc);
1154 flags = flags & ~isInvalid; 1247 flags = flags & ~isInvalid;
1155 } 1248 }
1249
1156 XDestroyImage (result); 1250 XDestroyImage (result);
1157 } 1251 }
1158 1252
1159 if (flags & isInvalid) 1253 if (flags & isInvalid)
1160 { 1254 {
1164 pixmap = None; 1258 pixmap = None;
1165 } 1259 }
1166 } 1260 }
1167 1261
1168 apply (); 1262 apply ();
1263
1264 XSync (target->dpy, False);
1265 valid_since = ev::now ();
1169 1266
1170 TIMING_TEST_PRINT_RESULT (tp); 1267 TIMING_TEST_PRINT_RESULT (tp);
1171 1268
1172 return true; 1269 return true;
1173} 1270}
1186 } 1283 }
1187 return false; 1284 return false;
1188} 1285}
1189 1286
1190void 1287void
1191bgPixmap_t::apply() 1288bgPixmap_t::apply ()
1192{ 1289{
1193 if (target) 1290 if (target)
1194 { 1291 {
1195 flags &= ~isVtOrigin; 1292 flags &= ~isVtOrigin;
1196 if (pixmap != None) 1293 if (pixmap != None)
1294 {
1197 { /* set target's background to pixmap */ 1295 /* set target's background to pixmap */
1198# ifdef ENABLE_TRANSPARENCY 1296# ifdef ENABLE_TRANSPARENCY
1199 if (flags & isTransparent) 1297 if (flags & isTransparent)
1200 { 1298 {
1201 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap); 1299 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap);
1202 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative); 1300 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative);
1218 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); 1316 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1219# endif 1317# endif
1220 } 1318 }
1221 } 1319 }
1222 else 1320 else
1321 {
1223 { /* set target background to a pixel */ 1322 /* set target background to a pixel */
1224 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); 1323 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
1225 XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); 1324 XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]);
1226 /* do we also need to set scrollbar's background here ? */ 1325 /* do we also need to set scrollbar's background here ? */
1227# if HAVE_SCROLLBARS 1326# if HAVE_SCROLLBARS
1228 if (target->scrollBar.win) 1327 if (target->scrollBar.win)
1244 target->want_refresh = 1; 1343 target->want_refresh = 1;
1245 flags |= hasChanged; 1344 flags |= hasChanged;
1246 } 1345 }
1247} 1346}
1248 1347
1249#endif /* HAVE_BG_PIXMAP */ 1348#endif /* HAVE_BG_PIXMAP */
1250 1349
1251#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) && !XFT 1350#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) && !XFT
1252/* taken from aterm-0.4.2 */ 1351/* taken from aterm-0.4.2 */
1253 1352
1254typedef uint32_t RUINT32T; 1353typedef uint32_t RUINT32T;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines