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) 2005-2006 Marc Lehmann <pcg@goof.com> |
6 | * Copyright (c) 2005-2008 Marc Lehmann <pcg@goof.com> |
7 | * Copyright (c) 2007 Sasha Vasko <sasha@aftercode.net> |
7 | * Copyright (c) 2007 Sasha Vasko <sasha@aftercode.net> |
8 | * |
8 | * |
9 | * 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 |
10 | * 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 |
11 | * the Free Software Foundation; either version 2 of the License, or |
11 | * the Free Software Foundation; either version 2 of the License, or |
… | |
… | |
27 | #define DO_TIMING_TEST 0 |
27 | #define DO_TIMING_TEST 0 |
28 | |
28 | |
29 | #if DO_TIMING_TEST |
29 | #if DO_TIMING_TEST |
30 | # include <sys/time.h> |
30 | # include <sys/time.h> |
31 | #define TIMING_TEST_START(id) \ |
31 | #define TIMING_TEST_START(id) \ |
32 | struct timeval timing_test_##id##_stv;\ |
32 | struct timeval timing_test_##id##_stv; \ |
33 | gettimeofday (&timing_test_##id##_stv, NULL); |
33 | gettimeofday (&timing_test_##id##_stv, NULL); |
34 | |
34 | |
35 | #define TIMING_TEST_PRINT_RESULT(id) \ |
35 | #define TIMING_TEST_PRINT_RESULT(id) \ |
36 | do{ struct timeval tv;gettimeofday (&tv, NULL); tv.tv_sec -= (timing_test_##id##_stv).tv_sec;\ |
36 | do { \ |
|
|
37 | struct timeval tv; \ |
|
|
38 | gettimeofday (&tv, NULL); \ |
|
|
39 | tv.tv_sec -= (timing_test_##id##_stv).tv_sec; \ |
37 | fprintf (stderr, "%s: %s: %d: elapsed %ld usec\n", #id, __FILE__, __LINE__,\ |
40 | fprintf (stderr, "%s: %s: %d: elapsed %ld usec\n", #id, __FILE__, __LINE__, \ |
38 | tv.tv_sec * 1000000 + tv.tv_usec - (timing_test_##id##_stv).tv_usec);}while (0) |
41 | tv.tv_sec * 1000000 + tv.tv_usec - (timing_test_##id##_stv).tv_usec); \ |
|
|
42 | } while (0) |
39 | |
43 | |
40 | #else |
44 | #else |
41 | #define TIMING_TEST_START(id) do{}while (0) |
45 | #define TIMING_TEST_START(id) do {} while (0) |
42 | #define TIMING_TEST_PRINT_RESULT(id) do{}while (0) |
46 | #define TIMING_TEST_PRINT_RESULT(id) do {} while (0) |
43 | #endif |
47 | #endif |
44 | |
48 | |
45 | /* |
49 | /* |
46 | * Pixmap geometry string interpretation : |
50 | * Pixmap geometry string interpretation : |
47 | * Each geometry string contains zero or one scale/position |
51 | * Each geometry string contains zero or one scale/position |
48 | * adjustment and may optionally be followed by a colon and one or more |
52 | * adjustment and may optionally be followed by a colon and one or more |
49 | * colon-delimited pixmap operations. |
53 | * colon-delimited pixmap operations. |
50 | * The following table shows the valid geometry strings and their |
54 | * The following table shows the valid geometry strings and their |
51 | * affects on the background image : |
55 | * effects on the background image : |
52 | * |
56 | * |
53 | * WxH+X+Y Set scaling to W% by H%, and position to X% by Y%. |
57 | * WxH+X+Y Set scaling to W% by H%, and position to X% by Y%. |
54 | * W and H are percentages of the terminal window size. |
58 | * W and H are percentages of the terminal window size. |
55 | * X and Y are also percentages; e.g., +50+50 centers |
59 | * X and Y are also percentages; e.g., +50+50 centers |
56 | * the image in the window. |
60 | * the image in the window. |
… | |
… | |
93 | // zero_initialised-derived structs |
97 | // zero_initialised-derived structs |
94 | #ifdef HAVE_AFTERIMAGE |
98 | #ifdef HAVE_AFTERIMAGE |
95 | original_asim = NULL; |
99 | original_asim = NULL; |
96 | #endif |
100 | #endif |
97 | #ifdef BG_IMAGE_FROM_FILE |
101 | #ifdef BG_IMAGE_FROM_FILE |
|
|
102 | have_image = false; |
98 | h_scale = v_scale = 0; |
103 | h_scale = v_scale = 0; |
99 | h_align = v_align = 0; |
104 | h_align = v_align = 0; |
100 | #endif |
105 | #endif |
101 | flags = 0; |
106 | flags = 0; |
102 | pixmap = None; |
107 | pixmap = None; |
… | |
… | |
123 | if (flags & isTransparent) |
128 | if (flags & isTransparent) |
124 | return true; |
129 | return true; |
125 | # endif |
130 | # endif |
126 | |
131 | |
127 | # ifdef BG_IMAGE_FROM_FILE |
132 | # ifdef BG_IMAGE_FROM_FILE |
128 | # ifdef HAVE_AFTERIMAGE |
133 | if (have_image) |
129 | if (original_asim) |
|
|
130 | # endif |
|
|
131 | { |
134 | { |
132 | if (h_scale != 0 || v_scale != 0 |
135 | if (h_scale != 0 || v_scale != 0 |
133 | || h_align != 0 || v_align != 0) |
136 | || h_align != 0 || v_align != 0) |
134 | return true; |
137 | return true; |
135 | } |
138 | } |
136 | # endif |
139 | # endif |
137 | |
140 | |
138 | return false; |
141 | return false; |
139 | } |
142 | } |
140 | |
143 | |
141 | bool |
144 | bool |
142 | bgPixmap_t::window_position_sensitive () |
145 | bgPixmap_t::window_position_sensitive () |
143 | { |
146 | { |
144 | # ifdef ENABLE_TRANSPARENCY |
147 | # ifdef ENABLE_TRANSPARENCY |
145 | if (flags & isTransparent) |
148 | if (flags & isTransparent) |
146 | return true; |
149 | return true; |
147 | # endif |
150 | # endif |
148 | |
151 | |
149 | # ifdef BG_IMAGE_FROM_FILE |
152 | # ifdef BG_IMAGE_FROM_FILE |
150 | # ifdef HAVE_AFTERIMAGE |
153 | if (have_image) |
151 | if (original_asim) |
|
|
152 | # endif |
|
|
153 | { |
154 | { |
154 | if (h_align == rootAlign || v_align == rootAlign) |
155 | if (h_align == rootAlign || v_align == rootAlign) |
155 | return true; |
156 | return true; |
156 | } |
157 | } |
157 | # endif |
158 | # endif |
… | |
… | |
259 | int geom_flags = 0, changed = 0; |
260 | int geom_flags = 0, changed = 0; |
260 | int x = 0, y = 0; |
261 | int x = 0, y = 0; |
261 | unsigned int w = 0, h = 0; |
262 | unsigned int w = 0, h = 0; |
262 | unsigned int n; |
263 | unsigned int n; |
263 | unsigned long new_flags = (flags & (~geometryFlags)); |
264 | unsigned long new_flags = (flags & (~geometryFlags)); |
264 | char *p; |
265 | const char *p; |
265 | # define MAXLEN_GEOM 256 /* could be longer than regular geometry string */ |
266 | # define MAXLEN_GEOM 256 /* could be longer than regular geometry string */ |
266 | |
267 | |
267 | if (geom == NULL) |
268 | if (geom == NULL) |
268 | return false; |
269 | return false; |
269 | |
270 | |
… | |
… | |
437 | { |
438 | { |
438 | flags = new_flags; |
439 | flags = new_flags; |
439 | changed++; |
440 | changed++; |
440 | } |
441 | } |
441 | |
442 | |
442 | //fprintf (stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n", |
443 | //fprintf (stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n", |
443 | // flags, h_scale, v_scale, h_align, v_align); |
444 | // flags, h_scale, v_scale, h_align, v_align); |
444 | return (changed > 0); |
445 | return (changed > 0); |
445 | } |
446 | } |
446 | |
447 | |
447 | # ifdef HAVE_AFTERIMAGE |
448 | # ifdef HAVE_AFTERIMAGE |
448 | bool |
449 | bool |
449 | bgPixmap_t::render_asim (ASImage *background, ARGB32 background_tint) |
450 | bgPixmap_t::render_image (unsigned long background_flags) |
450 | { |
451 | { |
451 | if (target == NULL) |
452 | if (target == NULL) |
452 | return false; |
453 | return false; |
453 | |
454 | |
|
|
455 | target->init_asv (); |
|
|
456 | |
|
|
457 | ASImage *background = NULL; |
|
|
458 | ARGB32 background_tint = TINT_LEAVE_SAME; |
|
|
459 | |
|
|
460 | # ifdef ENABLE_TRANSPARENCY |
|
|
461 | if (background_flags) |
|
|
462 | background = pixmap2ximage (target->asv, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, 100); |
|
|
463 | |
|
|
464 | if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) |
|
|
465 | { |
|
|
466 | ShadingInfo as_shade; |
|
|
467 | as_shade.shading = (shade == 0) ? 100 : shade; |
|
|
468 | |
|
|
469 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
|
|
470 | if (flags & tintSet) |
|
|
471 | tint.get (c); |
|
|
472 | as_shade.tintColor.red = c.r; |
|
|
473 | as_shade.tintColor.green = c.g; |
|
|
474 | as_shade.tintColor.blue = c.b; |
|
|
475 | |
|
|
476 | background_tint = shading2tint32 (&as_shade); |
|
|
477 | } |
|
|
478 | |
|
|
479 | if (!(background_flags & transpPmapBlured) && (flags & blurNeeded) && background != NULL) |
|
|
480 | { |
|
|
481 | ASImage *tmp = blur_asimage_gauss (target->asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF, |
|
|
482 | (original_asim == NULL || tint == TINT_LEAVE_SAME) ? ASA_XImage : ASA_ASImage, |
|
|
483 | 100, ASIMAGE_QUALITY_DEFAULT); |
|
|
484 | if (tmp) |
|
|
485 | { |
|
|
486 | destroy_asimage (&background); |
|
|
487 | background = tmp; |
|
|
488 | } |
|
|
489 | } |
|
|
490 | # endif |
|
|
491 | |
|
|
492 | ASImage *result = 0; |
|
|
493 | |
454 | int target_width = (int)target->szHint.width; |
494 | int target_width = target->szHint.width; |
455 | int target_height = (int)target->szHint.height; |
495 | int target_height = target->szHint.height; |
456 | int new_pmap_width = target_width, new_pmap_height = target_height; |
496 | int new_pmap_width = target_width; |
457 | ASImage *result = NULL; |
497 | int new_pmap_height = target_height; |
458 | |
498 | |
459 | int x = 0; |
499 | int x = 0; |
460 | int y = 0; |
500 | int y = 0; |
461 | int w = h_scale * target_width / 100; |
501 | int w = h_scale * target_width / 100; |
462 | int h = v_scale * target_height / 100; |
502 | int h = v_scale * target_height / 100; |
… | |
… | |
465 | |
505 | |
466 | if (original_asim) |
506 | if (original_asim) |
467 | { |
507 | { |
468 | if (h_align == rootAlign || v_align == rootAlign) |
508 | if (h_align == rootAlign || v_align == rootAlign) |
469 | { |
509 | { |
470 | target->get_window_origin(x, y); |
510 | target->get_window_origin (x, y); |
471 | x = -x; |
511 | x = -x; |
472 | y = -y; |
512 | y = -y; |
473 | } |
513 | } |
474 | |
514 | |
475 | if (h_align != rootAlign) |
515 | if (h_align != rootAlign) |
… | |
… | |
491 | new_pmap_height = background->height; |
531 | new_pmap_height = background->height; |
492 | result = background; |
532 | result = background; |
493 | |
533 | |
494 | if (background_tint != TINT_LEAVE_SAME) |
534 | if (background_tint != TINT_LEAVE_SAME) |
495 | { |
535 | { |
496 | ASImage* tmp = tile_asimage (target->asv, background, 0, 0, |
536 | ASImage *tmp = tile_asimage (target->asv, background, 0, 0, |
497 | target_width, target_height, background_tint, |
537 | target_width, target_height, background_tint, |
498 | ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT); |
538 | ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT); |
499 | if (tmp) |
539 | if (tmp) |
500 | result = tmp; |
540 | result = tmp; |
501 | } |
541 | } |
… | |
… | |
529 | if (h_scale == 0 || v_scale == 0) |
569 | if (h_scale == 0 || v_scale == 0) |
530 | { |
570 | { |
531 | ASImage *tmp = tile_asimage (target->asv, result, |
571 | ASImage *tmp = tile_asimage (target->asv, result, |
532 | (h_scale > 0) ? 0 : (int)result->width - x, |
572 | (h_scale > 0) ? 0 : (int)result->width - x, |
533 | (v_scale > 0) ? 0 : (int)result->height - y, |
573 | (v_scale > 0) ? 0 : (int)result->height - y, |
534 | new_pmap_width, |
574 | new_pmap_width, |
535 | new_pmap_height, |
575 | new_pmap_height, |
536 | TINT_LEAVE_SAME, ASA_XImage, |
576 | TINT_LEAVE_SAME, ASA_XImage, |
537 | 100, ASIMAGE_QUALITY_DEFAULT); |
577 | 100, ASIMAGE_QUALITY_DEFAULT); |
538 | if (tmp) |
578 | if (tmp) |
539 | { |
579 | { |
… | |
… | |
546 | } |
586 | } |
547 | else |
587 | else |
548 | { |
588 | { |
549 | /* if blending background and image - pixmap has to be sized same as target window */ |
589 | /* if blending background and image - pixmap has to be sized same as target window */ |
550 | ASImageLayer *layers = create_image_layers (2); |
590 | ASImageLayer *layers = create_image_layers (2); |
551 | ASImage *merged_im = NULL; |
|
|
552 | |
591 | |
553 | layers[0].im = background; |
592 | layers[0].im = background; |
554 | layers[0].clip_width = target_width; |
593 | layers[0].clip_width = target_width; |
555 | layers[0].clip_height = target_height; |
594 | layers[0].clip_height = target_height; |
556 | layers[0].tint = background_tint; |
595 | layers[0].tint = background_tint; |
… | |
… | |
603 | free (layers); |
642 | free (layers); |
604 | } |
643 | } |
605 | } |
644 | } |
606 | TIMING_TEST_PRINT_RESULT (asim); |
645 | TIMING_TEST_PRINT_RESULT (asim); |
607 | |
646 | |
608 | if (pixmap) |
647 | bool ret = false; |
609 | { |
|
|
610 | if (result == NULL |
|
|
611 | || pmap_width != new_pmap_width |
|
|
612 | || pmap_height != new_pmap_height |
|
|
613 | || pmap_depth != target->depth) |
|
|
614 | { |
|
|
615 | XFreePixmap (target->dpy, pixmap); |
|
|
616 | pixmap = None; |
|
|
617 | } |
|
|
618 | } |
|
|
619 | |
648 | |
620 | if (result) |
649 | if (result) |
621 | { |
650 | { |
622 | XGCValues gcv; |
651 | XGCValues gcv; |
623 | GC gc; |
652 | GC gc; |
|
|
653 | |
|
|
654 | if (pixmap) |
|
|
655 | { |
|
|
656 | if (pmap_width != new_pmap_width |
|
|
657 | || pmap_height != new_pmap_height |
|
|
658 | || pmap_depth != target->depth) |
|
|
659 | { |
|
|
660 | XFreePixmap (target->dpy, pixmap); |
|
|
661 | pixmap = None; |
|
|
662 | } |
|
|
663 | } |
624 | |
664 | |
625 | /* create Pixmap */ |
665 | /* create Pixmap */ |
626 | if (pixmap == None) |
666 | if (pixmap == None) |
627 | { |
667 | { |
628 | pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); |
668 | pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); |
629 | pmap_width = new_pmap_width; |
669 | pmap_width = new_pmap_width; |
630 | pmap_height = new_pmap_height; |
670 | pmap_height = new_pmap_height; |
631 | pmap_depth = target->depth; |
671 | pmap_depth = target->depth; |
632 | } |
672 | } |
633 | /* fill with background color ( if result's not completely overlapping it)*/ |
673 | /* fill with background color (if result's not completely overlapping it) */ |
634 | gcv.foreground = target->pix_colors[Color_bg]; |
674 | gcv.foreground = target->pix_colors[Color_bg]; |
635 | gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv); |
675 | gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv); |
636 | |
676 | |
637 | int src_x = 0, src_y = 0, dst_x = 0, dst_y = 0; |
677 | int src_x = 0, src_y = 0, dst_x = 0, dst_y = 0; |
638 | int dst_width = result->width, dst_height = result->height; |
678 | int dst_width = result->width, dst_height = result->height; |
… | |
… | |
654 | if (result != background && result != original_asim) |
694 | if (result != background && result != original_asim) |
655 | destroy_asimage (&result); |
695 | destroy_asimage (&result); |
656 | |
696 | |
657 | XFreeGC (target->dpy, gc); |
697 | XFreeGC (target->dpy, gc); |
658 | TIMING_TEST_PRINT_RESULT (asim); |
698 | TIMING_TEST_PRINT_RESULT (asim); |
659 | } |
|
|
660 | |
699 | |
|
|
700 | ret = true; |
|
|
701 | } |
|
|
702 | |
|
|
703 | if (background) |
|
|
704 | destroy_asimage (&background); |
|
|
705 | |
661 | return true; |
706 | return ret; |
662 | } |
707 | } |
663 | # endif /* HAVE_AFTERIMAGE */ |
708 | # endif /* HAVE_AFTERIMAGE */ |
664 | |
709 | |
665 | bool |
710 | bool |
666 | bgPixmap_t::set_file (const char *file) |
711 | bgPixmap_t::set_file (const char *file) |
667 | { |
712 | { |
668 | char *f; |
|
|
669 | |
|
|
670 | assert (file); |
713 | assert (file); |
671 | |
714 | |
672 | if (*file) |
715 | if (*file) |
673 | { |
716 | { |
674 | # ifdef HAVE_AFTERIMAGE |
717 | if (const char *p = strchr (file, ';')) |
675 | if (target->asimman == NULL) |
|
|
676 | target->asimman = create_generic_imageman (target->rs[Rs_path]); |
|
|
677 | |
|
|
678 | if ((f = strchr (file, ';')) == NULL) |
|
|
679 | original_asim = get_asimage (target->asimman, file, 0xFFFFFFFF, 100); |
|
|
680 | else |
|
|
681 | { |
718 | { |
682 | size_t len = f - file; |
719 | size_t len = p - file; |
683 | f = (char *)malloc (len + 1); |
720 | char *f = rxvt_temp_buf<char> (len + 1); |
684 | memcpy (f, file, len); |
721 | memcpy (f, file, len); |
685 | f[len] = '\0'; |
722 | f[len] = '\0'; |
|
|
723 | file = f; |
|
|
724 | } |
|
|
725 | |
|
|
726 | # ifdef HAVE_AFTERIMAGE |
|
|
727 | if (!target->asimman) |
|
|
728 | target->asimman = create_generic_imageman (target->rs[Rs_path]); |
686 | original_asim = get_asimage (target->asimman, f, 0xFFFFFFFF, 100); |
729 | original_asim = get_asimage (target->asimman, file, 0xFFFFFFFF, 100); |
687 | free (f); |
730 | if (original_asim) |
688 | } |
731 | have_image = true; |
689 | |
732 | return have_image; |
690 | return original_asim; |
|
|
691 | # endif |
733 | # endif |
692 | } |
734 | } |
693 | |
735 | |
694 | return false; |
736 | return false; |
695 | } |
737 | } |
… | |
… | |
764 | flags |= bgPixmap_t::tintNeeded; |
806 | flags |= bgPixmap_t::tintNeeded; |
765 | else if (tint) |
807 | else if (tint) |
766 | { |
808 | { |
767 | if ((c.r > 0x000700 || c.g > 0x000700 || c.b > 0x000700) |
809 | if ((c.r > 0x000700 || c.g > 0x000700 || c.b > 0x000700) |
768 | && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700)) |
810 | && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700)) |
769 | { |
811 | { |
770 | flags |= bgPixmap_t::tintNeeded; |
812 | flags |= bgPixmap_t::tintNeeded; |
771 | } |
813 | } |
772 | } |
814 | } |
773 | |
815 | |
774 | if (flags & bgPixmap_t::tintNeeded) |
816 | if (flags & bgPixmap_t::tintNeeded) |
775 | { |
817 | { |
776 | if (flags & bgPixmap_t::tintWholesome) |
818 | if (flags & bgPixmap_t::tintWholesome) |
… | |
… | |
805 | { |
847 | { |
806 | unsigned long new_flags = compute_tint_shade_flags (NULL, shade); |
848 | unsigned long new_flags = compute_tint_shade_flags (NULL, shade); |
807 | |
849 | |
808 | if (new_flags != (flags & tintFlags)) |
850 | if (new_flags != (flags & tintFlags)) |
809 | { |
851 | { |
810 | flags = (flags&~tintFlags)|new_flags; |
852 | flags = (flags&~tintFlags)|new_flags; |
811 | return true; |
853 | return true; |
812 | } |
854 | } |
813 | |
855 | |
814 | return false; |
856 | return false; |
815 | } |
857 | } |
816 | |
858 | |
… | |
… | |
846 | unsigned long result = 0; |
888 | unsigned long result = 0; |
847 | |
889 | |
848 | if (target == NULL) |
890 | if (target == NULL) |
849 | return 0; |
891 | return 0; |
850 | |
892 | |
851 | /* root dimentions may change from call to call - but Display structure should |
893 | /* root dimensions may change from call to call - but Display structure should |
852 | * be always up-to-date, so let's use it : |
894 | * be always up-to-date, so let's use it : |
853 | */ |
895 | */ |
854 | Window root = target->display->root; |
896 | Window root = target->display->root; |
855 | int screen = target->display->screen; |
897 | int screen = target->display->screen; |
856 | Display *dpy = target->dpy; |
898 | Display *dpy = target->dpy; |
… | |
… | |
901 | |
943 | |
902 | attr.background_pixmap = ParentRelative; |
944 | attr.background_pixmap = ParentRelative; |
903 | attr.backing_store = Always; |
945 | attr.backing_store = Always; |
904 | attr.event_mask = ExposureMask; |
946 | attr.event_mask = ExposureMask; |
905 | attr.override_redirect = True; |
947 | attr.override_redirect = True; |
906 | src = XCreateWindow (dpy, root, sx, sy, window_width, window_height, 0, |
948 | src = XCreateWindow (dpy, root, sx, sy, window_width, window_height, 0, |
907 | CopyFromParent, CopyFromParent, CopyFromParent, |
949 | CopyFromParent, CopyFromParent, CopyFromParent, |
908 | CWBackPixmap|CWBackingStore|CWOverrideRedirect|CWEventMask, |
950 | CWBackPixmap|CWBackingStore|CWOverrideRedirect|CWEventMask, |
909 | &attr); |
951 | &attr); |
910 | |
952 | |
911 | if (src != None) |
953 | if (src != None) |
… | |
… | |
935 | XDestroyWindow (dpy, src); |
977 | XDestroyWindow (dpy, src); |
936 | XUngrabServer (dpy); |
978 | XUngrabServer (dpy); |
937 | //fprintf (stderr, "%s:%d: ev_count = %d\n", __FUNCTION__, __LINE__, ev_count); |
979 | //fprintf (stderr, "%s:%d: ev_count = %d\n", __FUNCTION__, __LINE__, ev_count); |
938 | } |
980 | } |
939 | |
981 | |
940 | if (!success) |
982 | if (!success) |
941 | { |
983 | { |
942 | XFreePixmap (dpy, tiled_root_pmap); |
984 | XFreePixmap (dpy, tiled_root_pmap); |
943 | tiled_root_pmap = None; |
985 | tiled_root_pmap = None; |
944 | } |
986 | } |
945 | else |
987 | else |
946 | result |= transpPmapTiled; |
988 | result |= transpPmapTiled; |
947 | } |
989 | } |
948 | else |
990 | else |
949 | { |
991 | { |
950 | /* strightforward pixmap copy */ |
992 | /* straightforward pixmap copy */ |
951 | gcv.tile = root_pixmap; |
993 | gcv.tile = root_pixmap; |
952 | gcv.fill_style = FillTiled; |
994 | gcv.fill_style = FillTiled; |
953 | |
995 | |
954 | while (sx < 0) sx += (int)root_width; |
996 | while (sx < 0) sx += (int)root_width; |
955 | while (sy < 0) sy += (int)root_height; |
997 | while (sy < 0) sy += (int)root_height; |
… | |
… | |
1068 | # if DO_TIMING_TEST |
1110 | # if DO_TIMING_TEST |
1069 | XSync (dpy, False); |
1111 | XSync (dpy, False); |
1070 | # endif |
1112 | # endif |
1071 | # endif |
1113 | # endif |
1072 | } |
1114 | } |
1073 | } |
1115 | } |
1074 | } /* server side rendering completed */ |
1116 | } /* server side rendering completed */ |
1075 | |
1117 | |
1076 | if (pixmap) |
1118 | if (pixmap) |
1077 | XFreePixmap (dpy, pixmap); |
1119 | XFreePixmap (dpy, pixmap); |
1078 | |
1120 | |
… | |
… | |
1106 | return false; |
1148 | return false; |
1107 | } |
1149 | } |
1108 | # endif /* ENABLE_TRANSPARENCY */ |
1150 | # endif /* ENABLE_TRANSPARENCY */ |
1109 | |
1151 | |
1110 | # ifndef HAVE_AFTERIMAGE |
1152 | # ifndef HAVE_AFTERIMAGE |
1111 | static void ShadeXImage(rxvt_term *term, XImage* srcImage, int shade, int rm, int gm, int bm); |
1153 | static void ShadeXImage(rxvt_term *term, XImage *srcImage, int shade, int rm, int gm, int bm); |
1112 | # endif |
1154 | # endif |
1113 | |
1155 | |
1114 | bool |
1156 | bool |
1115 | bgPixmap_t::render () |
1157 | bgPixmap_t::render () |
1116 | { |
1158 | { |
… | |
… | |
1119 | if (target == NULL) |
1161 | if (target == NULL) |
1120 | return false; |
1162 | return false; |
1121 | |
1163 | |
1122 | TIMING_TEST_START (tp); |
1164 | TIMING_TEST_START (tp); |
1123 | |
1165 | |
1124 | invalidate(); |
1166 | invalidate (); |
1125 | # ifdef ENABLE_TRANSPARENCY |
1167 | # ifdef ENABLE_TRANSPARENCY |
1126 | if (flags & isTransparent) |
1168 | if (flags & isTransparent) |
1127 | { |
1169 | { |
1128 | /* we need to re-generate transparency pixmap in that case ! */ |
1170 | /* we need to re-generate transparency pixmap in that case ! */ |
1129 | background_flags = make_transparency_pixmap (); |
1171 | background_flags = make_transparency_pixmap (); |
1130 | if (background_flags == 0) |
1172 | if (background_flags == 0) |
1131 | return false; |
1173 | return false; |
1132 | else if ((background_flags & transpTransformations) == (flags & transpTransformations) |
1174 | else if ((background_flags & transpTransformations) == (flags & transpTransformations) |
1133 | && pmap_depth == target->depth) |
1175 | && pmap_depth == target->depth) |
1134 | flags = flags & ~isInvalid; |
1176 | flags = flags & ~isInvalid; |
1135 | } |
1177 | } |
1136 | # endif |
1178 | # endif |
1137 | |
1179 | |
|
|
1180 | # ifdef BG_IMAGE_FROM_FILE |
|
|
1181 | if (have_image |
|
|
1182 | || (background_flags & transpTransformations) != (flags & transpTransformations)) |
|
|
1183 | { |
|
|
1184 | if (render_image (background_flags)) |
|
|
1185 | flags = flags & ~isInvalid; |
|
|
1186 | } |
|
|
1187 | # endif |
|
|
1188 | |
1138 | XImage *result = NULL; |
1189 | XImage *result = NULL; |
1139 | # ifdef HAVE_AFTERIMAGE |
|
|
1140 | if (original_asim |
|
|
1141 | || (background_flags & transpTransformations) != (flags & transpTransformations)) |
|
|
1142 | { |
|
|
1143 | ASImage *background = NULL; |
|
|
1144 | ARGB32 as_tint = TINT_LEAVE_SAME; |
|
|
1145 | if (background_flags) |
|
|
1146 | background = pixmap2ximage (target->asv, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, 100); |
|
|
1147 | |
1190 | |
1148 | # ifdef ENABLE_TRANSPARENCY |
1191 | if (background_flags && (flags & isInvalid)) |
1149 | if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) |
|
|
1150 | { |
|
|
1151 | ShadingInfo as_shade; |
|
|
1152 | as_shade.shading = (shade == 0) ? 100 : shade; |
|
|
1153 | |
|
|
1154 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
|
|
1155 | if (flags & tintSet) |
|
|
1156 | tint.get (c); |
|
|
1157 | as_shade.tintColor.red = c.r; |
|
|
1158 | as_shade.tintColor.green = c.g; |
|
|
1159 | as_shade.tintColor.blue = c.b; |
|
|
1160 | |
|
|
1161 | as_tint = shading2tint32 (&as_shade); |
|
|
1162 | } |
|
|
1163 | if (!(background_flags & transpPmapBlured) && (flags & blurNeeded) && background != NULL) |
|
|
1164 | { |
|
|
1165 | ASImage* tmp = blur_asimage_gauss (target->asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF, |
|
|
1166 | (original_asim == NULL || tint == TINT_LEAVE_SAME)?ASA_XImage:ASA_ASImage, |
|
|
1167 | 100, ASIMAGE_QUALITY_DEFAULT); |
|
|
1168 | if (tmp) |
|
|
1169 | { |
|
|
1170 | destroy_asimage (&background); |
|
|
1171 | background = tmp; |
|
|
1172 | } |
|
|
1173 | } |
|
|
1174 | # endif |
|
|
1175 | |
|
|
1176 | if (render_asim (background, as_tint)) |
|
|
1177 | flags = flags & ~isInvalid; |
|
|
1178 | if (background) |
|
|
1179 | destroy_asimage (&background); |
|
|
1180 | } |
|
|
1181 | else if (background_flags && pmap_depth != target->depth) |
|
|
1182 | { |
1192 | { |
1183 | result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); |
1193 | result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); |
1184 | } |
|
|
1185 | |
1194 | |
|
|
1195 | # if !defined(HAVE_AFTERIMAGE) && !XFT |
1186 | # elif !XFT /* our own client-side tinting */ |
1196 | /* our own client-side tinting */ |
1187 | |
|
|
1188 | /* ATTENTION: We ASSUME that XFT will let us do all the tinting neccessary server-side. |
1197 | /* ATTENTION: We ASSUME that XFT will let us do all the tinting necessary server-side. |
1189 | This may need to be changed in need_client_side_rendering() logic is altered !!! */ |
1198 | This may need to be changed in need_client_side_rendering() logic is altered !!! */ |
1190 | |
|
|
1191 | if (background_flags && (flags & isInvalid)) |
|
|
1192 | { |
|
|
1193 | result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); |
|
|
1194 | if (result != NULL && !(background_flags & transpPmapTinted) && (flags & tintNeeded)) |
1199 | if (result != NULL && !(background_flags & transpPmapTinted) && (flags & tintNeeded)) |
1195 | { |
1200 | { |
1196 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
1201 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
1197 | if (flags & tintSet) |
1202 | if (flags & tintSet) |
1198 | tint.get (c); |
1203 | tint.get (c); |
1199 | ShadeXImage (target, result, shade, c.r, c.g, c.b); |
1204 | ShadeXImage (target, result, shade, c.r, c.g, c.b); |
1200 | } |
1205 | } |
|
|
1206 | # endif |
1201 | } |
1207 | } |
1202 | # endif /* HAVE_AFTERIMAGE */ |
|
|
1203 | |
1208 | |
1204 | if (result) |
1209 | if (result) |
1205 | { |
1210 | { |
1206 | GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); |
1211 | GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); |
1207 | |
1212 | |
… | |
… | |
1239 | |
1244 | |
1240 | XFreeGC (target->dpy, gc); |
1245 | XFreeGC (target->dpy, gc); |
1241 | flags = flags & ~isInvalid; |
1246 | flags = flags & ~isInvalid; |
1242 | } |
1247 | } |
1243 | |
1248 | |
1244 | XDestroyImage (result); |
1249 | XDestroyImage (result); |
1245 | } |
1250 | } |
1246 | |
1251 | |
1247 | if (flags & isInvalid) |
1252 | if (flags & isInvalid) |
1248 | { |
1253 | { |
1249 | if (pixmap != None) |
1254 | if (pixmap != None) |
… | |
… | |
1273 | # ifdef ENABLE_TRANSPARENCY |
1278 | # ifdef ENABLE_TRANSPARENCY |
1274 | root_depth = DefaultDepthOfScreen (ScreenOfDisplay (target->dpy, target->display->screen)); |
1279 | root_depth = DefaultDepthOfScreen (ScreenOfDisplay (target->dpy, target->display->screen)); |
1275 | # endif |
1280 | # endif |
1276 | return true; |
1281 | return true; |
1277 | } |
1282 | } |
|
|
1283 | |
1278 | return false; |
1284 | return false; |
1279 | } |
1285 | } |
1280 | |
1286 | |
1281 | void |
1287 | void |
1282 | bgPixmap_t::apply () |
1288 | bgPixmap_t::apply () |
1283 | { |
1289 | { |
1284 | if (target) |
1290 | if (target) |
1285 | { |
1291 | { |
1286 | flags &= ~isVtOrigin; |
1292 | flags &= ~isVtOrigin; |
|
|
1293 | |
1287 | if (pixmap != None) |
1294 | if (pixmap != None) |
1288 | { |
1295 | { |
1289 | /* set target's background to pixmap */ |
1296 | /* set target's background to pixmap */ |
1290 | # ifdef ENABLE_TRANSPARENCY |
1297 | # ifdef ENABLE_TRANSPARENCY |
1291 | if (flags & isTransparent) |
1298 | if (flags & isTransparent) |
1292 | { |
1299 | { |
1293 | XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap); |
1300 | XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap); |
1294 | XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative); |
1301 | XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative); |
|
|
1302 | |
1295 | if (target->scrollBar.win) |
1303 | if (target->scrollBar.win) |
1296 | XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative); |
1304 | XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative); |
1297 | } |
1305 | } |
1298 | else |
1306 | else |
1299 | # endif |
1307 | # endif |
… | |
… | |
1301 | flags |= isVtOrigin; |
1309 | flags |= isVtOrigin; |
1302 | /* force old pixmap dereference in case it was transparent before :*/ |
1310 | /* force old pixmap dereference in case it was transparent before :*/ |
1303 | XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); |
1311 | XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); |
1304 | XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap); |
1312 | XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap); |
1305 | /* do we also need to set scrollbar's background here ? */ |
1313 | /* do we also need to set scrollbar's background here ? */ |
|
|
1314 | |
1306 | if (target->scrollBar.win) |
1315 | if (target->scrollBar.win) |
1307 | XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); |
1316 | XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); |
1308 | } |
1317 | } |
1309 | } |
1318 | } |
1310 | else |
1319 | else |
1311 | { |
1320 | { |
1312 | /* set target background to a pixel */ |
1321 | /* set target background to a pixel */ |
1313 | XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); |
1322 | XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); |
1314 | XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); |
1323 | XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); |
1315 | /* do we also need to set scrollbar's background here ? */ |
1324 | /* do we also need to set scrollbar's background here ? */ |
1316 | if (target->scrollBar.win) |
1325 | if (target->scrollBar.win) |
1317 | XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); |
1326 | XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); |
1318 | } |
1327 | } |
|
|
1328 | |
1319 | /* don't want Expose on the parent or vt. It is better to use |
1329 | /* don't want Expose on the parent or vt. It is better to use |
1320 | scr_touch or we get a great deal of flicker otherwise: */ |
1330 | scr_touch or we get a great deal of flicker otherwise: */ |
1321 | XClearWindow (target->dpy, target->parent[0]); |
1331 | XClearWindow (target->dpy, target->parent[0]); |
1322 | |
1332 | |
1323 | if (target->scrollBar.win) |
1333 | if (target->scrollBar.state && target->scrollBar.win) |
1324 | { |
1334 | { |
1325 | target->scrollBar.setIdle (); |
1335 | target->scrollBar.state = STATE_IDLE; |
1326 | target->scrollbar_show (0); |
1336 | target->scrollBar.show (0); |
1327 | } |
1337 | } |
1328 | |
1338 | |
1329 | target->want_refresh = 1; |
1339 | target->want_refresh = 1; |
1330 | flags |= hasChanged; |
1340 | flags |= hasChanged; |
1331 | } |
1341 | } |
… | |
… | |
1337 | /* taken from aterm-0.4.2 */ |
1347 | /* taken from aterm-0.4.2 */ |
1338 | |
1348 | |
1339 | typedef uint32_t RUINT32T; |
1349 | typedef uint32_t RUINT32T; |
1340 | |
1350 | |
1341 | static void |
1351 | static void |
1342 | ShadeXImage(rxvt_term *term, XImage* srcImage, int shade, int rm, int gm, int bm) |
1352 | ShadeXImage(rxvt_term *term, XImage *srcImage, int shade, int rm, int gm, int bm) |
1343 | { |
1353 | { |
1344 | int sh_r, sh_g, sh_b; |
1354 | int sh_r, sh_g, sh_b; |
1345 | RUINT32T mask_r, mask_g, mask_b; |
1355 | RUINT32T mask_r, mask_g, mask_b; |
1346 | RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b; |
1356 | RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b; |
1347 | unsigned int lower_lim_r, lower_lim_g, lower_lim_b; |
1357 | unsigned int lower_lim_r, lower_lim_g, lower_lim_b; |