… | |
… | |
58 | # endif |
58 | # endif |
59 | |
59 | |
60 | void |
60 | void |
61 | rxvt_term::bg_destroy () |
61 | rxvt_term::bg_destroy () |
62 | { |
62 | { |
63 | # ifdef BG_IMAGE_FROM_FILE |
63 | # if BG_IMAGE_FROM_FILE |
64 | for (vector<rxvt_image>::iterator bg_image = image_vec.begin (); bg_image < image_vec.end (); bg_image++) |
|
|
65 | bg_image->destroy (); |
64 | fimage.destroy (); |
66 | # endif |
65 | # endif |
67 | |
66 | |
68 | if (bg_pixmap) |
67 | if (bg_pixmap) |
69 | XFreePixmap (dpy, bg_pixmap); |
68 | XFreePixmap (dpy, bg_pixmap); |
70 | } |
69 | } |
… | |
… | |
84 | } |
83 | } |
85 | |
84 | |
86 | bool |
85 | bool |
87 | rxvt_term::bg_window_size_sensitive () |
86 | rxvt_term::bg_window_size_sensitive () |
88 | { |
87 | { |
89 | # ifdef ENABLE_TRANSPARENCY |
88 | # if ENABLE_TRANSPARENCY |
90 | if (bg_flags & BG_IS_TRANSPARENT) |
89 | if (bg_flags & BG_IS_TRANSPARENT) |
91 | return true; |
90 | return true; |
92 | # endif |
91 | # endif |
93 | |
92 | |
94 | # ifdef BG_IMAGE_FROM_FILE |
93 | # if BG_IMAGE_FROM_FILE |
95 | for (vector<rxvt_image>::iterator bg_image = image_vec.begin (); bg_image < image_vec.end (); bg_image++) |
94 | if (fimage.flags & IM_IS_SET) |
96 | { |
95 | { |
97 | if ((bg_image->flags & IM_IS_SIZE_SENSITIVE) |
96 | if ((fimage.flags & IM_IS_SIZE_SENSITIVE) |
98 | || bg_image->width () > szHint.width |
97 | || fimage.width () > szHint.width |
99 | || bg_image->height () > szHint.height) |
98 | || fimage.height () > szHint.height) |
100 | return true; |
99 | return true; |
101 | } |
100 | } |
102 | # endif |
101 | # endif |
103 | |
102 | |
104 | return false; |
103 | return false; |
105 | } |
104 | } |
106 | |
105 | |
107 | bool |
106 | bool |
108 | rxvt_term::bg_window_position_sensitive () |
107 | rxvt_term::bg_window_position_sensitive () |
109 | { |
108 | { |
110 | # ifdef ENABLE_TRANSPARENCY |
109 | # if ENABLE_TRANSPARENCY |
111 | if (bg_flags & BG_IS_TRANSPARENT) |
110 | if (bg_flags & BG_IS_TRANSPARENT) |
112 | return true; |
111 | return true; |
113 | # endif |
112 | # endif |
114 | |
113 | |
115 | # ifdef BG_IMAGE_FROM_FILE |
114 | # if BG_IMAGE_FROM_FILE |
116 | for (vector<rxvt_image>::iterator bg_image = image_vec.begin (); bg_image < image_vec.end (); bg_image++) |
115 | if (fimage.flags & IM_IS_SET) |
117 | { |
116 | { |
118 | if (bg_image->flags & IM_ROOT_ALIGN) |
117 | if (fimage.flags & IM_ROOT_ALIGN) |
119 | return true; |
118 | return true; |
120 | } |
119 | } |
121 | # endif |
120 | # endif |
122 | |
121 | |
123 | return false; |
122 | return false; |
124 | } |
123 | } |
125 | |
124 | |
126 | # ifdef BG_IMAGE_FROM_FILE |
125 | # if BG_IMAGE_FROM_FILE |
127 | static inline int |
126 | static inline int |
128 | make_align_position (int align, int window_size, int image_size) |
127 | make_align_position (int align, int window_size, int image_size) |
129 | { |
128 | { |
130 | if (align >= 0 && align <= 100) |
129 | if (align >= 0 && align <= 100) |
131 | return lerp (0, window_size - image_size, align); |
130 | return lerp (0, window_size - image_size, align); |
… | |
… | |
303 | h_align = x; |
302 | h_align = x; |
304 | v_align = y; |
303 | v_align = y; |
305 | changed = true; |
304 | changed = true; |
306 | } |
305 | } |
307 | |
306 | |
308 | if (!(flags & IM_TILE) |
307 | if (is_size_sensitive ()) |
309 | || h_scale || v_scale |
|
|
310 | || (!(flags & IM_ROOT_ALIGN) && (h_align || v_align))) |
|
|
311 | flags |= IM_IS_SIZE_SENSITIVE; |
308 | flags |= IM_IS_SIZE_SENSITIVE; |
312 | else |
309 | else |
313 | flags &= ~IM_IS_SIZE_SENSITIVE; |
310 | flags &= ~IM_IS_SIZE_SENSITIVE; |
314 | |
311 | |
315 | return changed; |
312 | return changed; |
… | |
… | |
349 | x = make_align_position (image.h_align, target_width, w); |
346 | x = make_align_position (image.h_align, target_width, w); |
350 | y = make_align_position (image.v_align, target_height, h); |
347 | y = make_align_position (image.v_align, target_height, h); |
351 | } |
348 | } |
352 | } |
349 | } |
353 | |
350 | |
354 | # ifdef HAVE_PIXBUF |
351 | # if HAVE_PIXBUF |
355 | bool |
352 | bool |
356 | rxvt_term::pixbuf_to_pixmap (GdkPixbuf *pixbuf, Pixmap pixmap, GC gc, |
353 | rxvt_term::pixbuf_to_pixmap (GdkPixbuf *pixbuf, Pixmap pixmap, GC gc, |
357 | int src_x, int src_y, int dst_x, int dst_y, |
354 | int src_x, int src_y, int dst_x, int dst_y, |
358 | unsigned int width, unsigned int height, bool argb) |
355 | unsigned int width, unsigned int height, bool argb) |
359 | { |
356 | { |
… | |
… | |
486 | return false; |
483 | return false; |
487 | |
484 | |
488 | bool need_blend = bg_flags & BG_IS_VALID; |
485 | bool need_blend = bg_flags & BG_IS_VALID; |
489 | |
486 | |
490 | if (need_blend |
487 | if (need_blend |
491 | && !(bg_flags & BG_HAS_RENDER)) |
488 | && !(display->flags & DISPLAY_HAS_RENDER)) |
492 | return false; |
489 | return false; |
493 | |
490 | |
494 | GdkPixbuf *result; |
491 | GdkPixbuf *result; |
495 | |
492 | |
496 | int image_width = gdk_pixbuf_get_width (pixbuf); |
493 | int image_width = gdk_pixbuf_get_width (pixbuf); |
… | |
… | |
539 | |
536 | |
540 | if (need_blend) |
537 | if (need_blend) |
541 | tmp_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, 32); |
538 | tmp_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, 32); |
542 | else |
539 | else |
543 | { |
540 | { |
544 | // optimise bg pixmap size when tiling, but only if there are no |
|
|
545 | // other pixbufs to render. Otherwise, the bg pixmap size must |
|
|
546 | // be equal to the window size. |
|
|
547 | if ((image.flags & IM_TILE) |
541 | if (image.flags & IM_TILE) |
548 | && image_vec.size () == 1) |
|
|
549 | { |
542 | { |
550 | new_pmap_width = min (image_width, target_width); |
543 | new_pmap_width = min (image_width, target_width); |
551 | new_pmap_height = min (image_height, target_height); |
544 | new_pmap_height = min (image_height, target_height); |
552 | } |
545 | } |
553 | |
546 | |
… | |
… | |
605 | src_x, src_y, |
598 | src_x, src_y, |
606 | dst_x, dst_y, |
599 | dst_x, dst_y, |
607 | dst_width, dst_height, need_blend); |
600 | dst_width, dst_height, need_blend); |
608 | } |
601 | } |
609 | |
602 | |
|
|
603 | if (image.need_blur ()) |
|
|
604 | blur_pixmap (tmp_pixmap, new_pmap_width, new_pmap_height, need_blend, image.h_blurRadius, image.v_blurRadius); |
|
|
605 | if (image.need_tint ()) |
|
|
606 | tint_pixmap (tmp_pixmap, new_pmap_width, new_pmap_height, need_blend, image.tint, image.tint_set, image.shade); |
|
|
607 | |
610 | #if XRENDER |
608 | #if XRENDER |
611 | if (need_blend) |
609 | if (need_blend) |
612 | { |
610 | { |
613 | XRenderPictFormat *argb_format = XRenderFindStandardFormat (dpy, PictStandardARGB32); |
611 | XRenderPictFormat *argb_format = XRenderFindStandardFormat (dpy, PictStandardARGB32); |
614 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
612 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
… | |
… | |
619 | |
617 | |
620 | Picture mask = create_xrender_mask (dpy, vt, False, False); |
618 | Picture mask = create_xrender_mask (dpy, vt, False, False); |
621 | |
619 | |
622 | XRenderColor mask_c; |
620 | XRenderColor mask_c; |
623 | |
621 | |
624 | mask_c.alpha = gdk_pixbuf_get_has_alpha (image.pixbuf) ? 0xffff : image.alpha; |
622 | mask_c.alpha = image.alpha; |
625 | mask_c.red = |
623 | mask_c.red = |
626 | mask_c.green = |
624 | mask_c.green = |
627 | mask_c.blue = 0; |
625 | mask_c.blue = 0; |
628 | XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); |
626 | XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); |
629 | |
627 | |
… | |
… | |
648 | |
646 | |
649 | return ret; |
647 | return ret; |
650 | } |
648 | } |
651 | # endif /* HAVE_PIXBUF */ |
649 | # endif /* HAVE_PIXBUF */ |
652 | |
650 | |
653 | # ifndef NO_RESOURCES |
|
|
654 | static int |
|
|
655 | rxvt_define_image (XrmDatabase *database ecb_unused, |
|
|
656 | XrmBindingList bindings ecb_unused, |
|
|
657 | XrmQuarkList quarks, |
|
|
658 | XrmRepresentation *type ecb_unused, |
|
|
659 | XrmValue *value, |
|
|
660 | XPointer closure ecb_unused) |
|
|
661 | { |
|
|
662 | int size; |
|
|
663 | |
|
|
664 | for (size = 0; quarks[size] != NULLQUARK; size++) |
|
|
665 | ; |
|
|
666 | |
|
|
667 | if (size >= 2) |
|
|
668 | { |
|
|
669 | int id = strtol (XrmQuarkToString (quarks[size-2]), 0, 0); |
|
|
670 | if (id >= 1) |
|
|
671 | GET_R->parse_image (id, XrmQuarkToString (quarks[size-1]), (char *)value->addr); |
|
|
672 | } |
|
|
673 | return False; |
|
|
674 | } |
|
|
675 | |
|
|
676 | void |
|
|
677 | rxvt_term::parse_image (int id, const char *type, const char *arg) |
|
|
678 | { |
|
|
679 | rxvt_image *image; |
|
|
680 | |
|
|
681 | for (image = image_vec.begin (); image < image_vec.end (); image++) |
|
|
682 | if (image->id == id) |
|
|
683 | break; |
|
|
684 | |
|
|
685 | if (image == image_vec.end ()) |
|
|
686 | { |
|
|
687 | image = new_image (); |
|
|
688 | image->id = id; |
|
|
689 | } |
|
|
690 | } |
|
|
691 | # endif |
|
|
692 | |
|
|
693 | rxvt_image::rxvt_image () |
651 | rxvt_image::rxvt_image () |
694 | { |
652 | { |
695 | id = |
653 | alpha = 0xffff; |
696 | alpha = |
|
|
697 | flags = |
654 | flags = 0; |
698 | h_scale = |
655 | h_scale = |
699 | v_scale = |
656 | v_scale = defaultScale; |
700 | h_align = |
657 | h_align = |
701 | v_align = 0; |
658 | v_align = defaultAlign; |
702 | |
659 | |
703 | # ifdef HAVE_PIXBUF |
660 | # if HAVE_PIXBUF |
704 | pixbuf = 0; |
661 | pixbuf = 0; |
705 | # endif |
662 | # endif |
706 | } |
663 | } |
707 | |
664 | |
708 | bool |
665 | bool |
… | |
… | |
722 | file = f; |
679 | file = f; |
723 | } |
680 | } |
724 | |
681 | |
725 | bool ret = set_file (file); |
682 | bool ret = set_file (file); |
726 | alpha = 0x8000; |
683 | alpha = 0x8000; |
727 | if (ret && p) |
684 | if (ret) |
728 | set_geometry (p + 1); |
685 | set_geometry (p ? p + 1 : ""); |
729 | return ret; |
686 | return ret; |
730 | } |
687 | } |
731 | |
688 | |
732 | bool |
689 | bool |
733 | rxvt_image::set_file (const char *file) |
690 | rxvt_image::set_file (const char *file) |
734 | { |
691 | { |
735 | bool ret = false; |
692 | bool ret = false; |
736 | |
693 | |
737 | # ifdef HAVE_PIXBUF |
694 | # if HAVE_PIXBUF |
738 | GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); |
695 | GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); |
739 | if (image) |
696 | if (image) |
740 | { |
697 | { |
741 | if (pixbuf) |
698 | if (pixbuf) |
742 | g_object_unref (pixbuf); |
699 | g_object_unref (pixbuf); |
… | |
… | |
744 | ret = true; |
701 | ret = true; |
745 | } |
702 | } |
746 | # endif |
703 | # endif |
747 | |
704 | |
748 | if (ret) |
705 | if (ret) |
749 | { |
706 | flags |= IM_IS_SET; |
750 | alpha = 0xffff; |
|
|
751 | flags = IM_IS_SET | IM_IS_SIZE_SENSITIVE; |
|
|
752 | h_scale = v_scale = defaultScale; |
|
|
753 | h_align = v_align = defaultAlign; |
|
|
754 | } |
|
|
755 | |
707 | |
756 | return ret; |
708 | return ret; |
757 | } |
709 | } |
758 | |
710 | |
759 | # endif /* BG_IMAGE_FROM_FILE */ |
711 | # endif /* BG_IMAGE_FROM_FILE */ |
760 | |
712 | |
761 | # ifdef ENABLE_TRANSPARENCY |
|
|
762 | bool |
713 | bool |
763 | rxvt_term::bg_set_blur (const char *geom) |
714 | image_effects::set_blur (const char *geom) |
764 | { |
715 | { |
765 | bool changed = false; |
716 | bool changed = false; |
766 | unsigned int hr, vr; |
717 | unsigned int hr, vr; |
767 | int junk; |
718 | int junk; |
768 | int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); |
719 | int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); |
… | |
… | |
789 | |
740 | |
790 | return changed; |
741 | return changed; |
791 | } |
742 | } |
792 | |
743 | |
793 | bool |
744 | bool |
794 | rxvt_term::bg_set_tint (rxvt_color &new_tint) |
745 | image_effects::set_tint (const rxvt_color &new_tint) |
795 | { |
746 | { |
796 | if (!(bg_flags & BG_TINT_SET) || tint != new_tint) |
747 | if (!tint_set || tint != new_tint) |
797 | { |
748 | { |
798 | tint = new_tint; |
749 | tint = new_tint; |
799 | bg_flags |= BG_TINT_SET; |
750 | tint_set = true; |
800 | |
|
|
801 | rgba c; |
|
|
802 | tint.get (c); |
|
|
803 | if ((c.r <= 0x00ff || c.r >= 0xff00) |
|
|
804 | && (c.g <= 0x00ff || c.g >= 0xff00) |
|
|
805 | && (c.b <= 0x00ff || c.b >= 0xff00)) |
|
|
806 | bg_flags |= BG_TINT_BITAND; |
|
|
807 | else |
|
|
808 | bg_flags &= ~BG_TINT_BITAND; |
|
|
809 | |
751 | |
810 | return true; |
752 | return true; |
811 | } |
753 | } |
812 | |
754 | |
813 | return false; |
755 | return false; |
814 | } |
756 | } |
815 | |
757 | |
816 | bool |
758 | bool |
817 | rxvt_term::bg_set_shade (const char *shade_str) |
759 | image_effects::set_shade (const char *shade_str) |
818 | { |
760 | { |
819 | int new_shade = atoi (shade_str); |
761 | int new_shade = atoi (shade_str); |
820 | |
762 | |
821 | clamp_it (new_shade, -100, 200); |
763 | clamp_it (new_shade, -100, 200); |
822 | if (new_shade < 0) |
764 | if (new_shade < 0) |
… | |
… | |
853 | params[i+2] = XDoubleToFixed (kernel[i] / sum); |
795 | params[i+2] = XDoubleToFixed (kernel[i] / sum); |
854 | } |
796 | } |
855 | #endif |
797 | #endif |
856 | |
798 | |
857 | bool |
799 | bool |
858 | rxvt_term::blur_pixmap (Pixmap pixmap, int width, int height) |
800 | rxvt_term::blur_pixmap (Pixmap pixmap, int width, int height, bool argb, int h_blurRadius, int v_blurRadius) |
859 | { |
801 | { |
860 | bool ret = false; |
802 | bool ret = false; |
861 | #if XRENDER |
803 | #if XRENDER |
862 | if (!(bg_flags & BG_HAS_RENDER_CONV)) |
804 | if (!(display->flags & DISPLAY_HAS_RENDER_CONV)) |
863 | return false; |
805 | return false; |
864 | |
806 | |
865 | int size = max (h_blurRadius, v_blurRadius) * 2 + 1; |
807 | int size = max (h_blurRadius, v_blurRadius) * 2 + 1; |
866 | double *kernel = (double *)malloc (size * sizeof (double)); |
808 | double *kernel = (double *)malloc (size * sizeof (double)); |
867 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
809 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
868 | |
810 | |
869 | XRenderPictureAttributes pa; |
811 | XRenderPictureAttributes pa; |
870 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
812 | XRenderPictFormat *format = argb ? XRenderFindStandardFormat (dpy, PictStandardARGB32) |
|
|
813 | : XRenderFindVisualFormat (dpy, visual); |
871 | |
814 | |
872 | pa.repeat = RepeatPad; |
815 | pa.repeat = RepeatPad; |
873 | Picture src = XRenderCreatePicture (dpy, pixmap, format, CPRepeat, &pa); |
816 | Picture src = XRenderCreatePicture (dpy, pixmap, format, CPRepeat, &pa); |
874 | Pixmap tmp = XCreatePixmap (dpy, pixmap, width, height, depth); |
817 | Pixmap tmp = XCreatePixmap (dpy, pixmap, width, height, depth); |
875 | Picture dst = XRenderCreatePicture (dpy, tmp, format, CPRepeat, &pa); |
818 | Picture dst = XRenderCreatePicture (dpy, tmp, format, CPRepeat, &pa); |
… | |
… | |
918 | #endif |
861 | #endif |
919 | return ret; |
862 | return ret; |
920 | } |
863 | } |
921 | |
864 | |
922 | bool |
865 | bool |
923 | rxvt_term::tint_pixmap (Pixmap pixmap, int width, int height) |
866 | rxvt_term::tint_pixmap (Pixmap pixmap, int width, int height, bool argb, rxvt_color &tint, bool tint_set, int shade) |
924 | { |
867 | { |
925 | bool ret = false; |
868 | bool ret = false; |
926 | |
869 | |
927 | if (shade == 100 && (bg_flags & BG_TINT_BITAND)) |
870 | rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); |
|
|
871 | |
|
|
872 | if (tint_set) |
|
|
873 | tint.get (c); |
|
|
874 | |
|
|
875 | if (shade == 100 |
|
|
876 | && (c.r <= 0x00ff || c.r >= 0xff00) |
|
|
877 | && (c.g <= 0x00ff || c.g >= 0xff00) |
|
|
878 | && (c.b <= 0x00ff || c.b >= 0xff00)) |
928 | { |
879 | { |
929 | XGCValues gcv; |
880 | XGCValues gcv; |
930 | GC gc; |
881 | GC gc; |
931 | |
882 | |
932 | /* In this case we can tint image server-side getting significant |
883 | /* In this case we can tint image server-side getting significant |
… | |
… | |
942 | ret = true; |
893 | ret = true; |
943 | XFreeGC (dpy, gc); |
894 | XFreeGC (dpy, gc); |
944 | } |
895 | } |
945 | } |
896 | } |
946 | # if XRENDER |
897 | # if XRENDER |
947 | else if (bg_flags & BG_HAS_RENDER) |
898 | else if (display->flags & DISPLAY_HAS_RENDER) |
948 | { |
899 | { |
949 | rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); |
|
|
950 | |
|
|
951 | if (bg_flags & BG_TINT_SET) |
|
|
952 | tint.get (c); |
|
|
953 | |
|
|
954 | if (shade <= 100) |
900 | if (shade <= 100) |
955 | { |
901 | { |
956 | c.r = c.r * shade / 100; |
902 | c.r = c.r * shade / 100; |
957 | c.g = c.g * shade / 100; |
903 | c.g = c.g * shade / 100; |
958 | c.b = c.b * shade / 100; |
904 | c.b = c.b * shade / 100; |
… | |
… | |
962 | c.r = c.r * (200 - shade) / 100; |
908 | c.r = c.r * (200 - shade) / 100; |
963 | c.g = c.g * (200 - shade) / 100; |
909 | c.g = c.g * (200 - shade) / 100; |
964 | c.b = c.b * (200 - shade) / 100; |
910 | c.b = c.b * (200 - shade) / 100; |
965 | } |
911 | } |
966 | |
912 | |
967 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
913 | XRenderPictFormat *format = argb ? XRenderFindStandardFormat (dpy, PictStandardARGB32) |
|
|
914 | : XRenderFindVisualFormat (dpy, visual); |
968 | |
915 | |
969 | Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, 0); |
916 | Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, 0); |
970 | |
917 | |
971 | Picture overlay_pic = create_xrender_mask (dpy, pixmap, True, False); |
918 | Picture overlay_pic = create_xrender_mask (dpy, pixmap, True, False); |
972 | |
919 | |
… | |
… | |
1008 | # endif |
955 | # endif |
1009 | |
956 | |
1010 | return ret; |
957 | return ret; |
1011 | } |
958 | } |
1012 | |
959 | |
|
|
960 | # if ENABLE_TRANSPARENCY |
1013 | /* |
961 | /* |
1014 | * Builds a pixmap of the same size as the terminal window that contains |
962 | * Builds a pixmap of the same size as the terminal window that contains |
1015 | * the tiled portion of the root pixmap that is supposed to be covered by |
963 | * the tiled portion of the root pixmap that is supposed to be covered by |
1016 | * our window. |
964 | * our window. |
1017 | */ |
965 | */ |
1018 | bool |
966 | bool |
1019 | rxvt_term::make_transparency_pixmap () |
967 | rxvt_term::render_root_image () |
1020 | { |
968 | { |
1021 | bool ret = false; |
969 | bool ret = false; |
1022 | |
970 | |
1023 | /* root dimensions may change from call to call - but Display structure should |
971 | /* root dimensions may change from call to call - but Display structure should |
1024 | * be always up-to-date, so let's use it : |
972 | * be always up-to-date, so let's use it : |
… | |
… | |
1060 | Pixmap recoded_root_pmap = root_pixmap; |
1008 | Pixmap recoded_root_pmap = root_pixmap; |
1061 | |
1009 | |
1062 | if (root_pixmap != None && root_depth != depth) |
1010 | if (root_pixmap != None && root_depth != depth) |
1063 | { |
1011 | { |
1064 | #if XRENDER |
1012 | #if XRENDER |
1065 | if (bg_flags & BG_HAS_RENDER) |
1013 | if (display->flags & DISPLAY_HAS_RENDER) |
1066 | { |
1014 | { |
1067 | recoded_root_pmap = XCreatePixmap (dpy, vt, root_pmap_width, root_pmap_height, depth); |
1015 | recoded_root_pmap = XCreatePixmap (dpy, vt, root_pmap_width, root_pmap_height, depth); |
1068 | |
1016 | |
1069 | XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen)); |
1017 | XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen)); |
1070 | Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, 0); |
1018 | Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, 0); |
… | |
… | |
1108 | |
1056 | |
1109 | if (gc) |
1057 | if (gc) |
1110 | { |
1058 | { |
1111 | XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height); |
1059 | XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height); |
1112 | ret = true; |
1060 | ret = true; |
1113 | bool need_blur = h_blurRadius && v_blurRadius; |
1061 | bool need_blur = root_effects.need_blur (); |
1114 | bool need_tint = shade != 100 || (bg_flags & BG_TINT_SET); |
1062 | bool need_tint = root_effects.need_tint (); |
1115 | |
1063 | |
1116 | if (!(bg_flags & BG_CLIENT_RENDER)) |
|
|
1117 | { |
|
|
1118 | if (need_blur) |
1064 | if (need_blur) |
|
|
1065 | { |
|
|
1066 | if (blur_pixmap (bg_pixmap, window_width, window_height, false, |
|
|
1067 | root_effects.h_blurRadius, root_effects.v_blurRadius)) |
|
|
1068 | need_blur = false; |
|
|
1069 | } |
|
|
1070 | if (need_tint) |
|
|
1071 | { |
|
|
1072 | if (tint_pixmap (bg_pixmap, window_width, window_height, false, |
|
|
1073 | root_effects.tint, root_effects.tint_set, root_effects.shade)) |
|
|
1074 | need_tint = false; |
|
|
1075 | } |
|
|
1076 | if (need_tint) |
|
|
1077 | { |
|
|
1078 | XImage *ximage = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap); |
|
|
1079 | if (ximage) |
1119 | { |
1080 | { |
1120 | if (blur_pixmap (bg_pixmap, window_width, window_height)) |
1081 | /* our own client-side tinting */ |
1121 | need_blur = false; |
1082 | tint_ximage (ximage, root_effects.tint, root_effects.tint_set, root_effects.shade); |
|
|
1083 | |
|
|
1084 | XPutImage (dpy, bg_pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height); |
|
|
1085 | XDestroyImage (ximage); |
1122 | } |
1086 | } |
1123 | if (need_tint) |
|
|
1124 | { |
|
|
1125 | if (tint_pixmap (bg_pixmap, window_width, window_height)) |
|
|
1126 | need_tint = false; |
|
|
1127 | } |
1087 | } |
1128 | if (need_tint) |
|
|
1129 | { |
|
|
1130 | XImage *ximage = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap); |
|
|
1131 | if (ximage) |
|
|
1132 | { |
|
|
1133 | /* our own client-side tinting */ |
|
|
1134 | tint_ximage (ximage); |
|
|
1135 | |
|
|
1136 | XPutImage (dpy, bg_pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height); |
|
|
1137 | XDestroyImage (ximage); |
|
|
1138 | } |
|
|
1139 | } |
|
|
1140 | } /* server side rendering completed */ |
|
|
1141 | |
1088 | |
1142 | XFreeGC (dpy, gc); |
1089 | XFreeGC (dpy, gc); |
1143 | } |
1090 | } |
1144 | |
1091 | |
1145 | if (recoded_root_pmap != root_pixmap) |
1092 | if (recoded_root_pmap != root_pixmap) |
… | |
… | |
1149 | } |
1096 | } |
1150 | |
1097 | |
1151 | void |
1098 | void |
1152 | rxvt_term::bg_set_root_pixmap () |
1099 | rxvt_term::bg_set_root_pixmap () |
1153 | { |
1100 | { |
1154 | Pixmap new_root_pixmap = get_pixmap_property (xa[XA_XROOTPMAP_ID]); |
1101 | Pixmap new_root_pixmap = display->get_pixmap_property (xa[XA_XROOTPMAP_ID]); |
1155 | if (new_root_pixmap == None) |
1102 | if (new_root_pixmap == None) |
1156 | new_root_pixmap = get_pixmap_property (xa[XA_ESETROOT_PMAP_ID]); |
1103 | new_root_pixmap = display->get_pixmap_property (xa[XA_ESETROOT_PMAP_ID]); |
1157 | |
1104 | |
1158 | root_pixmap = new_root_pixmap; |
1105 | root_pixmap = new_root_pixmap; |
1159 | } |
1106 | } |
1160 | # endif /* ENABLE_TRANSPARENCY */ |
1107 | # endif /* ENABLE_TRANSPARENCY */ |
1161 | |
1108 | |
1162 | bool |
1109 | void |
1163 | rxvt_term::bg_render () |
1110 | rxvt_term::bg_render () |
1164 | { |
1111 | { |
|
|
1112 | if (bg_flags & BG_INHIBIT_RENDER) |
|
|
1113 | return; |
|
|
1114 | |
1165 | bg_invalidate (); |
1115 | bg_invalidate (); |
1166 | # ifdef ENABLE_TRANSPARENCY |
1116 | # if ENABLE_TRANSPARENCY |
1167 | if (bg_flags & BG_IS_TRANSPARENT) |
1117 | if (bg_flags & BG_IS_TRANSPARENT) |
1168 | { |
1118 | { |
1169 | /* we need to re-generate transparency pixmap in that case ! */ |
1119 | /* we need to re-generate transparency pixmap in that case ! */ |
1170 | if (make_transparency_pixmap ()) |
1120 | if (render_root_image ()) |
1171 | bg_flags |= BG_IS_VALID; |
1121 | bg_flags |= BG_IS_VALID; |
1172 | } |
1122 | } |
1173 | # endif |
1123 | # endif |
1174 | |
1124 | |
1175 | # ifdef BG_IMAGE_FROM_FILE |
1125 | # if BG_IMAGE_FROM_FILE |
1176 | for (vector<rxvt_image>::iterator bg_image = image_vec.begin (); bg_image < image_vec.end (); bg_image++) |
1126 | if (fimage.flags & IM_IS_SET) |
1177 | { |
1127 | { |
1178 | if (render_image (*bg_image)) |
1128 | if (render_image (fimage)) |
1179 | bg_flags |= BG_IS_VALID; |
1129 | bg_flags |= BG_IS_VALID; |
1180 | } |
1130 | } |
1181 | # endif |
1131 | # endif |
1182 | |
1132 | |
1183 | if (!(bg_flags & BG_IS_VALID)) |
1133 | if (!(bg_flags & BG_IS_VALID)) |
… | |
… | |
1191 | |
1141 | |
1192 | scr_recolour (false); |
1142 | scr_recolour (false); |
1193 | bg_flags |= BG_NEEDS_REFRESH; |
1143 | bg_flags |= BG_NEEDS_REFRESH; |
1194 | |
1144 | |
1195 | bg_valid_since = ev::now (); |
1145 | bg_valid_since = ev::now (); |
1196 | |
|
|
1197 | return true; |
|
|
1198 | } |
1146 | } |
1199 | |
1147 | |
1200 | void |
1148 | void |
1201 | rxvt_term::bg_init () |
1149 | rxvt_term::bg_init () |
1202 | { |
1150 | { |
1203 | #ifdef ENABLE_TRANSPARENCY |
1151 | #if BG_IMAGE_FROM_FILE |
1204 | shade = 100; |
1152 | if (rs[Rs_backgroundPixmap]) |
|
|
1153 | { |
|
|
1154 | if (fimage.set_file_geometry (rs[Rs_backgroundPixmap]) |
|
|
1155 | && !bg_window_position_sensitive ()) |
|
|
1156 | update_background (); |
|
|
1157 | } |
1205 | #endif |
1158 | #endif |
1206 | |
|
|
1207 | bg_flags &= ~(BG_HAS_RENDER | BG_HAS_RENDER_CONV); |
|
|
1208 | #if XRENDER |
|
|
1209 | int major, minor; |
|
|
1210 | if (XRenderQueryVersion (dpy, &major, &minor)) |
|
|
1211 | bg_flags |= BG_HAS_RENDER; |
|
|
1212 | XFilters *filters = XRenderQueryFilters (dpy, vt); |
|
|
1213 | if (filters) |
|
|
1214 | { |
|
|
1215 | for (int i = 0; i < filters->nfilter; i++) |
|
|
1216 | if (!strcmp (filters->filter[i], FilterConvolution)) |
|
|
1217 | bg_flags |= BG_HAS_RENDER_CONV; |
|
|
1218 | |
|
|
1219 | XFree (filters); |
|
|
1220 | } |
|
|
1221 | #endif |
|
|
1222 | |
|
|
1223 | #ifdef BG_IMAGE_FROM_FILE |
|
|
1224 | if (rs[Rs_backgroundPixmap]) |
|
|
1225 | { |
|
|
1226 | rxvt_image *image = new_image (); |
|
|
1227 | if (!image->set_file_geometry (rs[Rs_backgroundPixmap])) |
|
|
1228 | image_vec.pop_back (); |
|
|
1229 | } |
|
|
1230 | |
|
|
1231 | # ifndef NO_RESOURCES |
|
|
1232 | find_resources ("image", "Image", XrmEnumAllLevels, rxvt_define_image); |
|
|
1233 | vector<rxvt_image>::iterator bg_image = image_vec.begin (); |
|
|
1234 | while (bg_image != image_vec.end ()) |
|
|
1235 | { |
|
|
1236 | if (!(bg_image->flags & IM_IS_SET)) |
|
|
1237 | bg_image = image_vec.erase (bg_image); |
|
|
1238 | else |
|
|
1239 | bg_image++; |
|
|
1240 | } |
|
|
1241 | # endif |
|
|
1242 | |
|
|
1243 | if (image_vec.size () > 0 |
|
|
1244 | && !bg_window_position_sensitive ()) |
|
|
1245 | update_background (); |
|
|
1246 | #endif |
|
|
1247 | } |
1159 | } |
1248 | |
1160 | |
1249 | #endif /* HAVE_BG_PIXMAP */ |
|
|
1250 | |
|
|
1251 | #ifdef ENABLE_TRANSPARENCY |
|
|
1252 | /* based on code from aterm-0.4.2 */ |
1161 | /* based on code from aterm-0.4.2 */ |
1253 | |
1162 | |
1254 | static inline void |
1163 | static inline void |
1255 | fill_lut (uint32_t *lookup, uint32_t mask, int sh, unsigned short low, unsigned short high) |
1164 | fill_lut (uint32_t *lookup, uint32_t mask, int sh, unsigned short low, unsigned short high) |
1256 | { |
1165 | { |
… | |
… | |
1262 | lookup[i] = (tmp / 0xffff) << sh; |
1171 | lookup[i] = (tmp / 0xffff) << sh; |
1263 | } |
1172 | } |
1264 | } |
1173 | } |
1265 | |
1174 | |
1266 | void |
1175 | void |
1267 | rxvt_term::tint_ximage (XImage *ximage) |
1176 | rxvt_term::tint_ximage (XImage *ximage, rxvt_color &tint, bool tint_set, int shade) |
1268 | { |
1177 | { |
1269 | unsigned int size_r, size_g, size_b; |
1178 | unsigned int size_r, size_g, size_b; |
1270 | int sh_r, sh_g, sh_b; |
1179 | int sh_r, sh_g, sh_b; |
1271 | uint32_t mask_r, mask_g, mask_b; |
1180 | uint32_t mask_r, mask_g, mask_b; |
1272 | uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; |
1181 | uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; |
… | |
… | |
1297 | lookup_g = lookup + size_r; |
1206 | lookup_g = lookup + size_r; |
1298 | lookup_b = lookup + size_r + size_g; |
1207 | lookup_b = lookup + size_r + size_g; |
1299 | |
1208 | |
1300 | rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); |
1209 | rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); |
1301 | |
1210 | |
1302 | if (bg_flags & BG_TINT_SET) |
1211 | if (tint_set) |
1303 | tint.get (c); |
1212 | tint.get (c); |
1304 | |
1213 | |
1305 | /* prepare limits for color transformation (each channel is handled separately) */ |
1214 | /* prepare limits for color transformation (each channel is handled separately) */ |
1306 | if (shade > 100) |
1215 | if (shade > 100) |
1307 | { |
1216 | { |
… | |
… | |
1357 | } |
1266 | } |
1358 | } |
1267 | } |
1359 | |
1268 | |
1360 | free (lookup); |
1269 | free (lookup); |
1361 | } |
1270 | } |
1362 | #endif /* ENABLE_TRANSPARENCY */ |
1271 | |
|
|
1272 | #endif /* HAVE_BG_PIXMAP */ |