… | |
… | |
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 |
|
|
64 | for (vector<rxvt_image>::iterator bg_image = image_vec.begin (); bg_image < image_vec.end (); bg_image++) |
|
|
65 | bg_image->destroy (); |
|
|
66 | # endif |
|
|
67 | |
63 | if (bg_pixmap) |
68 | if (bg_pixmap) |
64 | XFreePixmap (dpy, bg_pixmap); |
69 | XFreePixmap (dpy, bg_pixmap); |
65 | } |
70 | } |
66 | |
71 | |
67 | bool |
72 | bool |
… | |
… | |
85 | if (bg_flags & BG_IS_TRANSPARENT) |
90 | if (bg_flags & BG_IS_TRANSPARENT) |
86 | return true; |
91 | return true; |
87 | # endif |
92 | # endif |
88 | |
93 | |
89 | # ifdef BG_IMAGE_FROM_FILE |
94 | # ifdef BG_IMAGE_FROM_FILE |
90 | if (bg_image.flags & IM_IS_SET) |
95 | for (vector<rxvt_image>::iterator bg_image = image_vec.begin (); bg_image < image_vec.end (); bg_image++) |
91 | { |
96 | { |
92 | if ((bg_image.flags & IM_IS_SIZE_SENSITIVE) |
97 | if ((bg_image->flags & IM_IS_SIZE_SENSITIVE) |
93 | || bg_image.width () > szHint.width |
98 | || bg_image->width () > szHint.width |
94 | || bg_image.height () > szHint.height) |
99 | || bg_image->height () > szHint.height) |
95 | return true; |
100 | return true; |
96 | } |
101 | } |
97 | # endif |
102 | # endif |
98 | |
103 | |
99 | return false; |
104 | return false; |
… | |
… | |
106 | if (bg_flags & BG_IS_TRANSPARENT) |
111 | if (bg_flags & BG_IS_TRANSPARENT) |
107 | return true; |
112 | return true; |
108 | # endif |
113 | # endif |
109 | |
114 | |
110 | # ifdef BG_IMAGE_FROM_FILE |
115 | # ifdef BG_IMAGE_FROM_FILE |
111 | if (bg_image.flags & IM_IS_SET) |
116 | for (vector<rxvt_image>::iterator bg_image = image_vec.begin (); bg_image < image_vec.end (); bg_image++) |
112 | { |
117 | { |
113 | if (bg_image.flags & IM_ROOT_ALIGN) |
118 | if (bg_image->flags & IM_ROOT_ALIGN) |
114 | return true; |
119 | return true; |
115 | } |
120 | } |
116 | # endif |
121 | # endif |
117 | |
122 | |
118 | return false; |
123 | return false; |
… | |
… | |
145 | |
150 | |
146 | min_it (dst_size, target_size - dst_pos); |
151 | min_it (dst_size, target_size - dst_pos); |
147 | return src_pos; |
152 | return src_pos; |
148 | } |
153 | } |
149 | |
154 | |
|
|
155 | static void |
|
|
156 | parse_style (const char *style, int &x, int &y, unsigned int &w, unsigned int &h, uint8_t &flags) |
|
|
157 | { |
|
|
158 | if (!strcasecmp (style, "tiled")) |
|
|
159 | { |
|
|
160 | flags = IM_TILE; |
|
|
161 | w = h = noScale; |
|
|
162 | x = y = 0; |
|
|
163 | } |
|
|
164 | else if (!strcasecmp (style, "aspect-stretched")) |
|
|
165 | { |
|
|
166 | flags = IM_KEEP_ASPECT; |
|
|
167 | w = h = windowScale; |
|
|
168 | x = y = centerAlign; |
|
|
169 | } |
|
|
170 | else if (!strcasecmp (style, "stretched")) |
|
|
171 | { |
|
|
172 | flags = 0; |
|
|
173 | w = h = windowScale; |
|
|
174 | x = y = centerAlign; |
|
|
175 | } |
|
|
176 | else if (!strcasecmp (style, "centered")) |
|
|
177 | { |
|
|
178 | flags = 0; |
|
|
179 | w = h = noScale; |
|
|
180 | x = y = centerAlign; |
|
|
181 | } |
|
|
182 | else if (!strcasecmp (style, "root-tiled")) |
|
|
183 | { |
|
|
184 | flags = IM_TILE|IM_ROOT_ALIGN; |
|
|
185 | w = h = noScale; |
|
|
186 | x = y = 0; |
|
|
187 | } |
|
|
188 | } |
|
|
189 | |
150 | bool |
190 | bool |
151 | rxvt_image::set_geometry (const char *geom, bool update) |
191 | rxvt_image::set_geometry (const char *geom, bool update) |
152 | { |
192 | { |
153 | bool changed = false; |
193 | bool changed = false; |
154 | int geom_flags = 0; |
194 | int geom_flags = 0; |
155 | int x = h_align; |
195 | int x = h_align; |
156 | int y = v_align; |
196 | int y = v_align; |
157 | unsigned int w = h_scale; |
197 | unsigned int w = h_scale; |
158 | unsigned int h = v_scale; |
198 | unsigned int h = v_scale; |
159 | unsigned long new_flags = 0; |
199 | uint8_t new_flags = 0; |
160 | |
200 | |
161 | if (geom == NULL) |
201 | if (geom == NULL) |
162 | return false; |
202 | return false; |
163 | |
203 | |
164 | if (geom[0]) |
204 | if (geom[0]) |
165 | { |
205 | { |
166 | char **arr = rxvt_strsplit (':', geom); |
206 | char **arr = rxvt_strsplit (':', geom); |
167 | |
207 | |
168 | for (int i = 0; arr[i]; i++) |
208 | for (int i = 0; arr[i]; i++) |
169 | { |
209 | { |
170 | if (!strcasecmp (arr[i], "style=tiled")) |
210 | if (!strncasecmp (arr[i], "style=", 6)) |
171 | { |
211 | { |
172 | new_flags = IM_TILE; |
212 | parse_style (arr[i] + 6, x, y, w, h, new_flags); |
173 | w = h = noScale; |
|
|
174 | x = y = 0; |
|
|
175 | geom_flags = WidthValue|HeightValue|XValue|YValue; |
213 | geom_flags = WidthValue|HeightValue|XValue|YValue; |
176 | } |
|
|
177 | else if (!strcasecmp (arr[i], "style=aspect-stretched")) |
|
|
178 | { |
|
|
179 | new_flags = IM_KEEP_ASPECT; |
|
|
180 | w = h = windowScale; |
|
|
181 | x = y = centerAlign; |
|
|
182 | geom_flags = WidthValue|HeightValue|XValue|YValue; |
|
|
183 | } |
|
|
184 | else if (!strcasecmp (arr[i], "style=stretched")) |
|
|
185 | { |
|
|
186 | new_flags = 0; |
|
|
187 | w = h = windowScale; |
|
|
188 | geom_flags = WidthValue|HeightValue; |
|
|
189 | } |
|
|
190 | else if (!strcasecmp (arr[i], "style=centered")) |
|
|
191 | { |
|
|
192 | new_flags = 0; |
|
|
193 | w = h = noScale; |
|
|
194 | x = y = centerAlign; |
|
|
195 | geom_flags = WidthValue|HeightValue|XValue|YValue; |
|
|
196 | } |
|
|
197 | else if (!strcasecmp (arr[i], "style=root-tiled")) |
|
|
198 | { |
|
|
199 | new_flags = IM_TILE|IM_ROOT_ALIGN; |
|
|
200 | w = h = noScale; |
|
|
201 | geom_flags = WidthValue|HeightValue; |
|
|
202 | } |
214 | } |
203 | else if (!strcasecmp (arr[i], "op=tile")) |
215 | else if (!strcasecmp (arr[i], "op=tile")) |
204 | new_flags |= IM_TILE; |
216 | new_flags |= IM_TILE; |
205 | else if (!strcasecmp (arr[i], "op=keep-aspect")) |
217 | else if (!strcasecmp (arr[i], "op=keep-aspect")) |
206 | new_flags |= IM_KEEP_ASPECT; |
218 | new_flags |= IM_KEEP_ASPECT; |
… | |
… | |
291 | h_align = x; |
303 | h_align = x; |
292 | v_align = y; |
304 | v_align = y; |
293 | changed = true; |
305 | changed = true; |
294 | } |
306 | } |
295 | |
307 | |
296 | if (!(flags & IM_TILE) |
308 | if (is_size_sensitive ()) |
297 | || h_scale || v_scale |
|
|
298 | || (!(flags & IM_ROOT_ALIGN) && (h_align || v_align))) |
|
|
299 | flags |= IM_IS_SIZE_SENSITIVE; |
309 | flags |= IM_IS_SIZE_SENSITIVE; |
300 | else |
310 | else |
301 | flags &= ~IM_IS_SIZE_SENSITIVE; |
311 | flags &= ~IM_IS_SIZE_SENSITIVE; |
302 | |
312 | |
303 | return changed; |
313 | return changed; |
… | |
… | |
474 | return false; |
484 | return false; |
475 | |
485 | |
476 | bool need_blend = bg_flags & BG_IS_VALID; |
486 | bool need_blend = bg_flags & BG_IS_VALID; |
477 | |
487 | |
478 | if (need_blend |
488 | if (need_blend |
479 | && !(bg_flags & BG_HAS_RENDER)) |
489 | && !(display->flags & DISPLAY_HAS_RENDER)) |
480 | return false; |
490 | return false; |
481 | |
491 | |
482 | GdkPixbuf *result; |
492 | GdkPixbuf *result; |
483 | |
493 | |
484 | int image_width = gdk_pixbuf_get_width (pixbuf); |
494 | int image_width = gdk_pixbuf_get_width (pixbuf); |
… | |
… | |
527 | |
537 | |
528 | if (need_blend) |
538 | if (need_blend) |
529 | tmp_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, 32); |
539 | tmp_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, 32); |
530 | else |
540 | else |
531 | { |
541 | { |
|
|
542 | // optimise bg pixmap size when tiling, but only if there are no |
|
|
543 | // other pixbufs to render. Otherwise, the bg pixmap size must |
|
|
544 | // be equal to the window size. |
532 | if (image.flags & IM_TILE) |
545 | if ((image.flags & IM_TILE) |
|
|
546 | && image_vec.size () == 1) |
533 | { |
547 | { |
534 | new_pmap_width = min (image_width, target_width); |
548 | new_pmap_width = min (image_width, target_width); |
535 | new_pmap_height = min (image_height, target_height); |
549 | new_pmap_height = min (image_height, target_height); |
536 | } |
550 | } |
537 | |
551 | |
… | |
… | |
589 | src_x, src_y, |
603 | src_x, src_y, |
590 | dst_x, dst_y, |
604 | dst_x, dst_y, |
591 | dst_width, dst_height, need_blend); |
605 | dst_width, dst_height, need_blend); |
592 | } |
606 | } |
593 | |
607 | |
|
|
608 | if (image.need_blur ()) |
|
|
609 | blur_pixmap (tmp_pixmap, new_pmap_width, new_pmap_height, need_blend, image.h_blurRadius, image.v_blurRadius); |
|
|
610 | if (image.need_tint ()) |
|
|
611 | tint_pixmap (tmp_pixmap, new_pmap_width, new_pmap_height, need_blend, image.tint, image.tint_set, image.shade); |
|
|
612 | |
594 | #if XRENDER |
613 | #if XRENDER |
595 | if (need_blend) |
614 | if (need_blend) |
596 | { |
615 | { |
597 | XRenderPictFormat *argb_format = XRenderFindStandardFormat (dpy, PictStandardARGB32); |
616 | XRenderPictFormat *argb_format = XRenderFindStandardFormat (dpy, PictStandardARGB32); |
598 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
617 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
… | |
… | |
603 | |
622 | |
604 | Picture mask = create_xrender_mask (dpy, vt, False, False); |
623 | Picture mask = create_xrender_mask (dpy, vt, False, False); |
605 | |
624 | |
606 | XRenderColor mask_c; |
625 | XRenderColor mask_c; |
607 | |
626 | |
608 | mask_c.alpha = 0x8000; |
627 | mask_c.alpha = image.alpha; |
609 | mask_c.red = |
628 | mask_c.red = |
610 | mask_c.green = |
629 | mask_c.green = |
611 | mask_c.blue = 0; |
630 | mask_c.blue = 0; |
612 | XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); |
631 | XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); |
613 | |
632 | |
… | |
… | |
632 | |
651 | |
633 | return ret; |
652 | return ret; |
634 | } |
653 | } |
635 | # endif /* HAVE_PIXBUF */ |
654 | # endif /* HAVE_PIXBUF */ |
636 | |
655 | |
|
|
656 | # ifndef NO_RESOURCES |
|
|
657 | static int |
|
|
658 | rxvt_define_image (XrmDatabase *database ecb_unused, |
|
|
659 | XrmBindingList bindings ecb_unused, |
|
|
660 | XrmQuarkList quarks, |
|
|
661 | XrmRepresentation *type ecb_unused, |
|
|
662 | XrmValue *value, |
|
|
663 | XPointer closure ecb_unused) |
|
|
664 | { |
|
|
665 | int size; |
|
|
666 | |
|
|
667 | for (size = 0; quarks[size] != NULLQUARK; size++) |
|
|
668 | ; |
|
|
669 | |
|
|
670 | if (size >= 2) |
|
|
671 | { |
|
|
672 | int id = strtol (XrmQuarkToString (quarks[size-2]), 0, 0); |
|
|
673 | if (id >= 1) |
|
|
674 | GET_R->parse_image (id, XrmQuarkToString (quarks[size-1]), (char *)value->addr); |
|
|
675 | } |
|
|
676 | return False; |
|
|
677 | } |
|
|
678 | # endif |
|
|
679 | |
|
|
680 | void |
|
|
681 | rxvt_term::parse_image (int id, const char *type, const char *arg) |
|
|
682 | { |
|
|
683 | if (image_vec.size () < id + 1) |
|
|
684 | image_vec.resize (id + 1); |
|
|
685 | |
|
|
686 | rxvt_image *image = &image_vec[id]; |
|
|
687 | } |
|
|
688 | |
|
|
689 | rxvt_image::rxvt_image () |
|
|
690 | { |
|
|
691 | alpha = 0xffff; |
|
|
692 | flags = 0; |
|
|
693 | h_scale = |
|
|
694 | v_scale = defaultScale; |
|
|
695 | h_align = |
|
|
696 | v_align = defaultAlign; |
|
|
697 | |
|
|
698 | # ifdef HAVE_PIXBUF |
|
|
699 | pixbuf = 0; |
|
|
700 | # endif |
|
|
701 | } |
|
|
702 | |
637 | bool |
703 | bool |
638 | rxvt_image::set_file (const char *file) |
704 | rxvt_image::set_file_geometry (const char *file) |
639 | { |
705 | { |
640 | if (!file || !*file) |
706 | if (!file || !*file) |
641 | return false; |
707 | return false; |
642 | |
708 | |
643 | bool ret = false; |
|
|
644 | const char *p = strchr (file, ';'); |
709 | const char *p = strchr (file, ';'); |
645 | |
710 | |
646 | if (p) |
711 | if (p) |
647 | { |
712 | { |
648 | size_t len = p - file; |
713 | size_t len = p - file; |
… | |
… | |
650 | memcpy (f, file, len); |
715 | memcpy (f, file, len); |
651 | f[len] = '\0'; |
716 | f[len] = '\0'; |
652 | file = f; |
717 | file = f; |
653 | } |
718 | } |
654 | |
719 | |
|
|
720 | bool ret = set_file (file); |
|
|
721 | alpha = 0x8000; |
|
|
722 | if (ret) |
|
|
723 | set_geometry (p ? p + 1 : ""); |
|
|
724 | return ret; |
|
|
725 | } |
|
|
726 | |
|
|
727 | bool |
|
|
728 | rxvt_image::set_file (const char *file) |
|
|
729 | { |
|
|
730 | bool ret = false; |
|
|
731 | |
655 | # ifdef HAVE_PIXBUF |
732 | # ifdef HAVE_PIXBUF |
656 | GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); |
733 | GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); |
657 | if (image) |
734 | if (image) |
658 | { |
735 | { |
659 | if (pixbuf) |
736 | if (pixbuf) |
… | |
… | |
662 | ret = true; |
739 | ret = true; |
663 | } |
740 | } |
664 | # endif |
741 | # endif |
665 | |
742 | |
666 | if (ret) |
743 | if (ret) |
667 | { |
744 | flags |= IM_IS_SET; |
668 | flags = IM_IS_SET | IM_IS_SIZE_SENSITIVE; |
|
|
669 | h_scale = v_scale = defaultScale; |
|
|
670 | h_align = v_align = defaultAlign; |
|
|
671 | |
|
|
672 | if (p) |
|
|
673 | set_geometry (p + 1); |
|
|
674 | } |
|
|
675 | |
745 | |
676 | return ret; |
746 | return ret; |
677 | } |
747 | } |
678 | |
748 | |
679 | # endif /* BG_IMAGE_FROM_FILE */ |
749 | # endif /* BG_IMAGE_FROM_FILE */ |
680 | |
750 | |
681 | # ifdef ENABLE_TRANSPARENCY |
|
|
682 | bool |
751 | bool |
683 | rxvt_term::bg_set_blur (const char *geom) |
752 | image_effects::set_blur (const char *geom) |
684 | { |
753 | { |
685 | bool changed = false; |
754 | bool changed = false; |
686 | unsigned int hr, vr; |
755 | unsigned int hr, vr; |
687 | int junk; |
756 | int junk; |
688 | int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); |
757 | int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); |
… | |
… | |
709 | |
778 | |
710 | return changed; |
779 | return changed; |
711 | } |
780 | } |
712 | |
781 | |
713 | bool |
782 | bool |
714 | rxvt_term::bg_set_tint (rxvt_color &new_tint) |
783 | image_effects::set_tint (const rxvt_color &new_tint) |
715 | { |
784 | { |
716 | if (!(bg_flags & BG_TINT_SET) || tint != new_tint) |
785 | if (!tint_set || tint != new_tint) |
717 | { |
786 | { |
718 | tint = new_tint; |
787 | tint = new_tint; |
719 | bg_flags |= BG_TINT_SET; |
788 | tint_set = true; |
720 | |
|
|
721 | rgba c; |
|
|
722 | tint.get (c); |
|
|
723 | if ((c.r <= 0x00ff || c.r >= 0xff00) |
|
|
724 | && (c.g <= 0x00ff || c.g >= 0xff00) |
|
|
725 | && (c.b <= 0x00ff || c.b >= 0xff00)) |
|
|
726 | bg_flags |= BG_TINT_BITAND; |
|
|
727 | else |
|
|
728 | bg_flags &= ~BG_TINT_BITAND; |
|
|
729 | |
789 | |
730 | return true; |
790 | return true; |
731 | } |
791 | } |
732 | |
792 | |
733 | return false; |
793 | return false; |
734 | } |
794 | } |
735 | |
795 | |
736 | bool |
796 | bool |
737 | rxvt_term::bg_set_shade (const char *shade_str) |
797 | image_effects::set_shade (const char *shade_str) |
738 | { |
798 | { |
739 | int new_shade = atoi (shade_str); |
799 | int new_shade = atoi (shade_str); |
740 | |
800 | |
741 | clamp_it (new_shade, -100, 200); |
801 | clamp_it (new_shade, -100, 200); |
742 | if (new_shade < 0) |
802 | if (new_shade < 0) |
… | |
… | |
773 | params[i+2] = XDoubleToFixed (kernel[i] / sum); |
833 | params[i+2] = XDoubleToFixed (kernel[i] / sum); |
774 | } |
834 | } |
775 | #endif |
835 | #endif |
776 | |
836 | |
777 | bool |
837 | bool |
778 | rxvt_term::blur_pixmap (Pixmap pixmap, int width, int height) |
838 | rxvt_term::blur_pixmap (Pixmap pixmap, int width, int height, bool argb, int h_blurRadius, int v_blurRadius) |
779 | { |
839 | { |
780 | bool ret = false; |
840 | bool ret = false; |
781 | #if XRENDER |
841 | #if XRENDER |
782 | if (!(bg_flags & BG_HAS_RENDER_CONV)) |
842 | if (!(display->flags & DISPLAY_HAS_RENDER_CONV)) |
783 | return false; |
843 | return false; |
784 | |
844 | |
785 | int size = max (h_blurRadius, v_blurRadius) * 2 + 1; |
845 | int size = max (h_blurRadius, v_blurRadius) * 2 + 1; |
786 | double *kernel = (double *)malloc (size * sizeof (double)); |
846 | double *kernel = (double *)malloc (size * sizeof (double)); |
787 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
847 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
788 | |
848 | |
789 | XRenderPictureAttributes pa; |
849 | XRenderPictureAttributes pa; |
790 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
850 | XRenderPictFormat *format = argb ? XRenderFindStandardFormat (dpy, PictStandardARGB32) |
|
|
851 | : XRenderFindVisualFormat (dpy, visual); |
791 | |
852 | |
792 | pa.repeat = RepeatPad; |
853 | pa.repeat = RepeatPad; |
793 | Picture src = XRenderCreatePicture (dpy, pixmap, format, CPRepeat, &pa); |
854 | Picture src = XRenderCreatePicture (dpy, pixmap, format, CPRepeat, &pa); |
794 | Pixmap tmp = XCreatePixmap (dpy, pixmap, width, height, depth); |
855 | Pixmap tmp = XCreatePixmap (dpy, pixmap, width, height, depth); |
795 | Picture dst = XRenderCreatePicture (dpy, tmp, format, CPRepeat, &pa); |
856 | Picture dst = XRenderCreatePicture (dpy, tmp, format, CPRepeat, &pa); |
… | |
… | |
838 | #endif |
899 | #endif |
839 | return ret; |
900 | return ret; |
840 | } |
901 | } |
841 | |
902 | |
842 | bool |
903 | bool |
843 | rxvt_term::tint_pixmap (Pixmap pixmap, int width, int height) |
904 | rxvt_term::tint_pixmap (Pixmap pixmap, int width, int height, bool argb, rxvt_color &tint, bool tint_set, int shade) |
844 | { |
905 | { |
845 | bool ret = false; |
906 | bool ret = false; |
846 | |
907 | |
847 | if (shade == 100 && (bg_flags & BG_TINT_BITAND)) |
908 | rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); |
|
|
909 | |
|
|
910 | if (tint_set) |
|
|
911 | tint.get (c); |
|
|
912 | |
|
|
913 | if (shade == 100 |
|
|
914 | && (c.r <= 0x00ff || c.r >= 0xff00) |
|
|
915 | && (c.g <= 0x00ff || c.g >= 0xff00) |
|
|
916 | && (c.b <= 0x00ff || c.b >= 0xff00)) |
848 | { |
917 | { |
849 | XGCValues gcv; |
918 | XGCValues gcv; |
850 | GC gc; |
919 | GC gc; |
851 | |
920 | |
852 | /* In this case we can tint image server-side getting significant |
921 | /* In this case we can tint image server-side getting significant |
… | |
… | |
862 | ret = true; |
931 | ret = true; |
863 | XFreeGC (dpy, gc); |
932 | XFreeGC (dpy, gc); |
864 | } |
933 | } |
865 | } |
934 | } |
866 | # if XRENDER |
935 | # if XRENDER |
867 | else if (bg_flags & BG_HAS_RENDER) |
936 | else if (display->flags & DISPLAY_HAS_RENDER) |
868 | { |
937 | { |
869 | rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); |
|
|
870 | |
|
|
871 | if (bg_flags & BG_TINT_SET) |
|
|
872 | tint.get (c); |
|
|
873 | |
|
|
874 | if (shade <= 100) |
938 | if (shade <= 100) |
875 | { |
939 | { |
876 | c.r = c.r * shade / 100; |
940 | c.r = c.r * shade / 100; |
877 | c.g = c.g * shade / 100; |
941 | c.g = c.g * shade / 100; |
878 | c.b = c.b * shade / 100; |
942 | c.b = c.b * shade / 100; |
… | |
… | |
882 | c.r = c.r * (200 - shade) / 100; |
946 | c.r = c.r * (200 - shade) / 100; |
883 | c.g = c.g * (200 - shade) / 100; |
947 | c.g = c.g * (200 - shade) / 100; |
884 | c.b = c.b * (200 - shade) / 100; |
948 | c.b = c.b * (200 - shade) / 100; |
885 | } |
949 | } |
886 | |
950 | |
887 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
951 | XRenderPictFormat *format = argb ? XRenderFindStandardFormat (dpy, PictStandardARGB32) |
|
|
952 | : XRenderFindVisualFormat (dpy, visual); |
888 | |
953 | |
889 | Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, 0); |
954 | Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, 0); |
890 | |
955 | |
891 | Picture overlay_pic = create_xrender_mask (dpy, pixmap, True, False); |
956 | Picture overlay_pic = create_xrender_mask (dpy, pixmap, True, False); |
892 | |
957 | |
… | |
… | |
928 | # endif |
993 | # endif |
929 | |
994 | |
930 | return ret; |
995 | return ret; |
931 | } |
996 | } |
932 | |
997 | |
|
|
998 | # ifdef ENABLE_TRANSPARENCY |
933 | /* |
999 | /* |
934 | * Builds a pixmap of the same size as the terminal window that contains |
1000 | * Builds a pixmap of the same size as the terminal window that contains |
935 | * the tiled portion of the root pixmap that is supposed to be covered by |
1001 | * the tiled portion of the root pixmap that is supposed to be covered by |
936 | * our window. |
1002 | * our window. |
937 | */ |
1003 | */ |
938 | bool |
1004 | bool |
939 | rxvt_term::make_transparency_pixmap () |
1005 | rxvt_term::render_root_image () |
940 | { |
1006 | { |
941 | bool ret = false; |
1007 | bool ret = false; |
942 | |
1008 | |
943 | /* root dimensions may change from call to call - but Display structure should |
1009 | /* root dimensions may change from call to call - but Display structure should |
944 | * be always up-to-date, so let's use it : |
1010 | * be always up-to-date, so let's use it : |
… | |
… | |
980 | Pixmap recoded_root_pmap = root_pixmap; |
1046 | Pixmap recoded_root_pmap = root_pixmap; |
981 | |
1047 | |
982 | if (root_pixmap != None && root_depth != depth) |
1048 | if (root_pixmap != None && root_depth != depth) |
983 | { |
1049 | { |
984 | #if XRENDER |
1050 | #if XRENDER |
985 | if (bg_flags & BG_HAS_RENDER) |
1051 | if (display->flags & DISPLAY_HAS_RENDER) |
986 | { |
1052 | { |
987 | recoded_root_pmap = XCreatePixmap (dpy, vt, root_pmap_width, root_pmap_height, depth); |
1053 | recoded_root_pmap = XCreatePixmap (dpy, vt, root_pmap_width, root_pmap_height, depth); |
988 | |
1054 | |
989 | XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen)); |
1055 | XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen)); |
990 | Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, 0); |
1056 | Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, 0); |
… | |
… | |
1028 | |
1094 | |
1029 | if (gc) |
1095 | if (gc) |
1030 | { |
1096 | { |
1031 | XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height); |
1097 | XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height); |
1032 | ret = true; |
1098 | ret = true; |
1033 | bool need_blur = h_blurRadius && v_blurRadius; |
1099 | bool need_blur = root_effects.need_blur (); |
1034 | bool need_tint = shade != 100 || (bg_flags & BG_TINT_SET); |
1100 | bool need_tint = root_effects.need_tint (); |
1035 | |
1101 | |
1036 | if (!(bg_flags & BG_CLIENT_RENDER)) |
|
|
1037 | { |
|
|
1038 | if (need_blur) |
1102 | if (need_blur) |
|
|
1103 | { |
|
|
1104 | if (blur_pixmap (bg_pixmap, window_width, window_height, false, |
|
|
1105 | root_effects.h_blurRadius, root_effects.v_blurRadius)) |
|
|
1106 | need_blur = false; |
|
|
1107 | } |
|
|
1108 | if (need_tint) |
|
|
1109 | { |
|
|
1110 | if (tint_pixmap (bg_pixmap, window_width, window_height, false, |
|
|
1111 | root_effects.tint, root_effects.tint_set, root_effects.shade)) |
|
|
1112 | need_tint = false; |
|
|
1113 | } |
|
|
1114 | if (need_tint) |
|
|
1115 | { |
|
|
1116 | XImage *ximage = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap); |
|
|
1117 | if (ximage) |
1039 | { |
1118 | { |
1040 | if (blur_pixmap (bg_pixmap, window_width, window_height)) |
1119 | /* our own client-side tinting */ |
1041 | need_blur = false; |
1120 | tint_ximage (ximage, root_effects.tint, root_effects.tint_set, root_effects.shade); |
|
|
1121 | |
|
|
1122 | XPutImage (dpy, bg_pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height); |
|
|
1123 | XDestroyImage (ximage); |
1042 | } |
1124 | } |
1043 | if (need_tint) |
|
|
1044 | { |
|
|
1045 | if (tint_pixmap (bg_pixmap, window_width, window_height)) |
|
|
1046 | need_tint = false; |
|
|
1047 | } |
1125 | } |
1048 | if (need_tint) |
|
|
1049 | { |
|
|
1050 | XImage *ximage = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap); |
|
|
1051 | if (ximage) |
|
|
1052 | { |
|
|
1053 | /* our own client-side tinting */ |
|
|
1054 | tint_ximage (ximage); |
|
|
1055 | |
|
|
1056 | XPutImage (dpy, bg_pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height); |
|
|
1057 | XDestroyImage (ximage); |
|
|
1058 | } |
|
|
1059 | } |
|
|
1060 | } /* server side rendering completed */ |
|
|
1061 | |
1126 | |
1062 | XFreeGC (dpy, gc); |
1127 | XFreeGC (dpy, gc); |
1063 | } |
1128 | } |
1064 | |
1129 | |
1065 | if (recoded_root_pmap != root_pixmap) |
1130 | if (recoded_root_pmap != root_pixmap) |
… | |
… | |
1085 | bg_invalidate (); |
1150 | bg_invalidate (); |
1086 | # ifdef ENABLE_TRANSPARENCY |
1151 | # ifdef ENABLE_TRANSPARENCY |
1087 | if (bg_flags & BG_IS_TRANSPARENT) |
1152 | if (bg_flags & BG_IS_TRANSPARENT) |
1088 | { |
1153 | { |
1089 | /* we need to re-generate transparency pixmap in that case ! */ |
1154 | /* we need to re-generate transparency pixmap in that case ! */ |
1090 | if (make_transparency_pixmap ()) |
1155 | if (render_root_image ()) |
1091 | bg_flags |= BG_IS_VALID; |
1156 | bg_flags |= BG_IS_VALID; |
1092 | } |
1157 | } |
1093 | # endif |
1158 | # endif |
1094 | |
1159 | |
1095 | # ifdef BG_IMAGE_FROM_FILE |
1160 | # ifdef BG_IMAGE_FROM_FILE |
1096 | if (bg_image.flags & IM_IS_SET) |
1161 | for (vector<rxvt_image>::iterator bg_image = image_vec.begin (); bg_image < image_vec.end (); bg_image++) |
1097 | { |
1162 | { |
1098 | if (render_image (bg_image)) |
1163 | if (render_image (*bg_image)) |
1099 | bg_flags |= BG_IS_VALID; |
1164 | bg_flags |= BG_IS_VALID; |
1100 | } |
1165 | } |
1101 | # endif |
1166 | # endif |
1102 | |
1167 | |
1103 | if (!(bg_flags & BG_IS_VALID)) |
1168 | if (!(bg_flags & BG_IS_VALID)) |
… | |
… | |
1118 | } |
1183 | } |
1119 | |
1184 | |
1120 | void |
1185 | void |
1121 | rxvt_term::bg_init () |
1186 | rxvt_term::bg_init () |
1122 | { |
1187 | { |
1123 | #ifdef ENABLE_TRANSPARENCY |
1188 | #ifdef BG_IMAGE_FROM_FILE |
1124 | shade = 100; |
1189 | if (rs[Rs_backgroundPixmap]) |
|
|
1190 | { |
|
|
1191 | rxvt_image *image = new_image (); |
|
|
1192 | if (!image->set_file_geometry (rs[Rs_backgroundPixmap])) |
|
|
1193 | image_vec.pop_back (); |
|
|
1194 | } |
|
|
1195 | |
|
|
1196 | # ifndef NO_RESOURCES |
|
|
1197 | find_resources ("image", "Image", XrmEnumAllLevels, rxvt_define_image); |
|
|
1198 | # endif |
|
|
1199 | |
|
|
1200 | vector<rxvt_image>::iterator bg_image = image_vec.begin (); |
|
|
1201 | while (bg_image != image_vec.end ()) |
|
|
1202 | { |
|
|
1203 | if (!(bg_image->flags & IM_IS_SET)) |
|
|
1204 | bg_image = image_vec.erase (bg_image); |
|
|
1205 | else |
|
|
1206 | { |
|
|
1207 | if (bg_image->is_size_sensitive ()) |
|
|
1208 | bg_image->flags |= IM_IS_SIZE_SENSITIVE; |
|
|
1209 | |
|
|
1210 | bg_image++; |
|
|
1211 | } |
|
|
1212 | } |
|
|
1213 | |
|
|
1214 | if (image_vec.size () > 0 |
|
|
1215 | && !bg_window_position_sensitive ()) |
|
|
1216 | update_background (); |
1125 | #endif |
1217 | #endif |
1126 | |
|
|
1127 | bg_flags &= ~(BG_HAS_RENDER | BG_HAS_RENDER_CONV); |
|
|
1128 | #if XRENDER |
|
|
1129 | int major, minor; |
|
|
1130 | if (XRenderQueryVersion (dpy, &major, &minor)) |
|
|
1131 | bg_flags |= BG_HAS_RENDER; |
|
|
1132 | XFilters *filters = XRenderQueryFilters (dpy, vt); |
|
|
1133 | if (filters) |
|
|
1134 | { |
|
|
1135 | for (int i = 0; i < filters->nfilter; i++) |
|
|
1136 | if (!strcmp (filters->filter[i], FilterConvolution)) |
|
|
1137 | bg_flags |= BG_HAS_RENDER_CONV; |
|
|
1138 | |
|
|
1139 | XFree (filters); |
|
|
1140 | } |
|
|
1141 | #endif |
|
|
1142 | } |
1218 | } |
1143 | |
1219 | |
1144 | #endif /* HAVE_BG_PIXMAP */ |
|
|
1145 | |
|
|
1146 | #ifdef ENABLE_TRANSPARENCY |
|
|
1147 | /* based on code from aterm-0.4.2 */ |
1220 | /* based on code from aterm-0.4.2 */ |
1148 | |
1221 | |
1149 | static inline void |
1222 | static inline void |
1150 | fill_lut (uint32_t *lookup, uint32_t mask, int sh, unsigned short low, unsigned short high) |
1223 | fill_lut (uint32_t *lookup, uint32_t mask, int sh, unsigned short low, unsigned short high) |
1151 | { |
1224 | { |
… | |
… | |
1157 | lookup[i] = (tmp / 0xffff) << sh; |
1230 | lookup[i] = (tmp / 0xffff) << sh; |
1158 | } |
1231 | } |
1159 | } |
1232 | } |
1160 | |
1233 | |
1161 | void |
1234 | void |
1162 | rxvt_term::tint_ximage (XImage *ximage) |
1235 | rxvt_term::tint_ximage (XImage *ximage, rxvt_color &tint, bool tint_set, int shade) |
1163 | { |
1236 | { |
1164 | unsigned int size_r, size_g, size_b; |
1237 | unsigned int size_r, size_g, size_b; |
1165 | int sh_r, sh_g, sh_b; |
1238 | int sh_r, sh_g, sh_b; |
1166 | uint32_t mask_r, mask_g, mask_b; |
1239 | uint32_t mask_r, mask_g, mask_b; |
1167 | uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; |
1240 | uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; |
… | |
… | |
1192 | lookup_g = lookup + size_r; |
1265 | lookup_g = lookup + size_r; |
1193 | lookup_b = lookup + size_r + size_g; |
1266 | lookup_b = lookup + size_r + size_g; |
1194 | |
1267 | |
1195 | rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); |
1268 | rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); |
1196 | |
1269 | |
1197 | if (bg_flags & BG_TINT_SET) |
1270 | if (tint_set) |
1198 | tint.get (c); |
1271 | tint.get (c); |
1199 | |
1272 | |
1200 | /* prepare limits for color transformation (each channel is handled separately) */ |
1273 | /* prepare limits for color transformation (each channel is handled separately) */ |
1201 | if (shade > 100) |
1274 | if (shade > 100) |
1202 | { |
1275 | { |
… | |
… | |
1252 | } |
1325 | } |
1253 | } |
1326 | } |
1254 | |
1327 | |
1255 | free (lookup); |
1328 | free (lookup); |
1256 | } |
1329 | } |
1257 | #endif /* ENABLE_TRANSPARENCY */ |
1330 | |
|
|
1331 | #endif /* HAVE_BG_PIXMAP */ |