… | |
… | |
303 | h_align = x; |
303 | h_align = x; |
304 | v_align = y; |
304 | v_align = y; |
305 | changed = true; |
305 | changed = true; |
306 | } |
306 | } |
307 | |
307 | |
308 | if (!(flags & IM_TILE) |
308 | if (is_size_sensitive ()) |
309 | || h_scale || v_scale |
|
|
310 | || (!(flags & IM_ROOT_ALIGN) && (h_align || v_align))) |
|
|
311 | flags |= IM_IS_SIZE_SENSITIVE; |
309 | flags |= IM_IS_SIZE_SENSITIVE; |
312 | else |
310 | else |
313 | flags &= ~IM_IS_SIZE_SENSITIVE; |
311 | flags &= ~IM_IS_SIZE_SENSITIVE; |
314 | |
312 | |
315 | return changed; |
313 | return changed; |
… | |
… | |
605 | src_x, src_y, |
603 | src_x, src_y, |
606 | dst_x, dst_y, |
604 | dst_x, dst_y, |
607 | dst_width, dst_height, need_blend); |
605 | dst_width, dst_height, need_blend); |
608 | } |
606 | } |
609 | |
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 | |
610 | #if XRENDER |
613 | #if XRENDER |
611 | if (need_blend) |
614 | if (need_blend) |
612 | { |
615 | { |
613 | XRenderPictFormat *argb_format = XRenderFindStandardFormat (dpy, PictStandardARGB32); |
616 | XRenderPictFormat *argb_format = XRenderFindStandardFormat (dpy, PictStandardARGB32); |
614 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
617 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
… | |
… | |
619 | |
622 | |
620 | Picture mask = create_xrender_mask (dpy, vt, False, False); |
623 | Picture mask = create_xrender_mask (dpy, vt, False, False); |
621 | |
624 | |
622 | XRenderColor mask_c; |
625 | XRenderColor mask_c; |
623 | |
626 | |
624 | mask_c.alpha = gdk_pixbuf_get_has_alpha (image.pixbuf) ? 0xffff : image.alpha; |
627 | mask_c.alpha = image.alpha; |
625 | mask_c.red = |
628 | mask_c.red = |
626 | mask_c.green = |
629 | mask_c.green = |
627 | mask_c.blue = 0; |
630 | mask_c.blue = 0; |
628 | XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); |
631 | XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); |
629 | |
632 | |
… | |
… | |
674 | } |
677 | } |
675 | |
678 | |
676 | void |
679 | void |
677 | rxvt_term::parse_image (int id, const char *type, const char *arg) |
680 | rxvt_term::parse_image (int id, const char *type, const char *arg) |
678 | { |
681 | { |
679 | rxvt_image *image; |
682 | if (image_vec.size () < id + 1) |
|
|
683 | image_vec.resize (id + 1); |
680 | |
684 | |
681 | for (image = image_vec.begin (); image < image_vec.end (); image++) |
685 | rxvt_image *image = &image_vec[id]; |
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 | } |
686 | } |
691 | # endif |
687 | # endif |
692 | |
688 | |
693 | rxvt_image::rxvt_image () |
689 | rxvt_image::rxvt_image () |
694 | { |
690 | { |
695 | id = |
691 | alpha = 0xffff; |
696 | alpha = |
|
|
697 | flags = |
692 | flags = 0; |
698 | h_scale = |
693 | h_scale = |
699 | v_scale = |
694 | v_scale = defaultScale; |
700 | h_align = |
695 | h_align = |
701 | v_align = 0; |
696 | v_align = defaultAlign; |
702 | |
697 | |
703 | # ifdef HAVE_PIXBUF |
698 | # ifdef HAVE_PIXBUF |
704 | pixbuf = 0; |
699 | pixbuf = 0; |
705 | # endif |
700 | # endif |
706 | } |
701 | } |
… | |
… | |
722 | file = f; |
717 | file = f; |
723 | } |
718 | } |
724 | |
719 | |
725 | bool ret = set_file (file); |
720 | bool ret = set_file (file); |
726 | alpha = 0x8000; |
721 | alpha = 0x8000; |
727 | if (ret && p) |
722 | if (ret) |
728 | set_geometry (p + 1); |
723 | set_geometry (p ? p + 1 : ""); |
729 | return ret; |
724 | return ret; |
730 | } |
725 | } |
731 | |
726 | |
732 | bool |
727 | bool |
733 | rxvt_image::set_file (const char *file) |
728 | rxvt_image::set_file (const char *file) |
… | |
… | |
744 | ret = true; |
739 | ret = true; |
745 | } |
740 | } |
746 | # endif |
741 | # endif |
747 | |
742 | |
748 | if (ret) |
743 | if (ret) |
749 | { |
744 | 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 | |
745 | |
756 | return ret; |
746 | return ret; |
757 | } |
747 | } |
758 | |
748 | |
759 | # endif /* BG_IMAGE_FROM_FILE */ |
749 | # endif /* BG_IMAGE_FROM_FILE */ |
760 | |
750 | |
761 | # ifdef ENABLE_TRANSPARENCY |
|
|
762 | bool |
751 | bool |
763 | rxvt_term::bg_set_blur (const char *geom) |
752 | image_effects::set_blur (const char *geom) |
764 | { |
753 | { |
765 | bool changed = false; |
754 | bool changed = false; |
766 | unsigned int hr, vr; |
755 | unsigned int hr, vr; |
767 | int junk; |
756 | int junk; |
768 | int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); |
757 | int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); |
… | |
… | |
789 | |
778 | |
790 | return changed; |
779 | return changed; |
791 | } |
780 | } |
792 | |
781 | |
793 | bool |
782 | bool |
794 | rxvt_term::bg_set_tint (rxvt_color &new_tint) |
783 | image_effects::set_tint (const rxvt_color &new_tint) |
795 | { |
784 | { |
796 | if (!(bg_flags & BG_TINT_SET) || tint != new_tint) |
785 | if (!tint_set || tint != new_tint) |
797 | { |
786 | { |
798 | tint = new_tint; |
787 | tint = new_tint; |
799 | bg_flags |= BG_TINT_SET; |
788 | 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 | |
789 | |
810 | return true; |
790 | return true; |
811 | } |
791 | } |
812 | |
792 | |
813 | return false; |
793 | return false; |
814 | } |
794 | } |
815 | |
795 | |
816 | bool |
796 | bool |
817 | rxvt_term::bg_set_shade (const char *shade_str) |
797 | image_effects::set_shade (const char *shade_str) |
818 | { |
798 | { |
819 | int new_shade = atoi (shade_str); |
799 | int new_shade = atoi (shade_str); |
820 | |
800 | |
821 | clamp_it (new_shade, -100, 200); |
801 | clamp_it (new_shade, -100, 200); |
822 | if (new_shade < 0) |
802 | if (new_shade < 0) |
… | |
… | |
853 | params[i+2] = XDoubleToFixed (kernel[i] / sum); |
833 | params[i+2] = XDoubleToFixed (kernel[i] / sum); |
854 | } |
834 | } |
855 | #endif |
835 | #endif |
856 | |
836 | |
857 | bool |
837 | bool |
858 | 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) |
859 | { |
839 | { |
860 | bool ret = false; |
840 | bool ret = false; |
861 | #if XRENDER |
841 | #if XRENDER |
862 | if (!(bg_flags & BG_HAS_RENDER_CONV)) |
842 | if (!(bg_flags & BG_HAS_RENDER_CONV)) |
863 | return false; |
843 | return false; |
… | |
… | |
865 | int size = max (h_blurRadius, v_blurRadius) * 2 + 1; |
845 | int size = max (h_blurRadius, v_blurRadius) * 2 + 1; |
866 | double *kernel = (double *)malloc (size * sizeof (double)); |
846 | double *kernel = (double *)malloc (size * sizeof (double)); |
867 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
847 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
868 | |
848 | |
869 | XRenderPictureAttributes pa; |
849 | XRenderPictureAttributes pa; |
870 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
850 | XRenderPictFormat *format = argb ? XRenderFindStandardFormat (dpy, PictStandardARGB32) |
|
|
851 | : XRenderFindVisualFormat (dpy, visual); |
871 | |
852 | |
872 | pa.repeat = RepeatPad; |
853 | pa.repeat = RepeatPad; |
873 | Picture src = XRenderCreatePicture (dpy, pixmap, format, CPRepeat, &pa); |
854 | Picture src = XRenderCreatePicture (dpy, pixmap, format, CPRepeat, &pa); |
874 | Pixmap tmp = XCreatePixmap (dpy, pixmap, width, height, depth); |
855 | Pixmap tmp = XCreatePixmap (dpy, pixmap, width, height, depth); |
875 | Picture dst = XRenderCreatePicture (dpy, tmp, format, CPRepeat, &pa); |
856 | Picture dst = XRenderCreatePicture (dpy, tmp, format, CPRepeat, &pa); |
… | |
… | |
918 | #endif |
899 | #endif |
919 | return ret; |
900 | return ret; |
920 | } |
901 | } |
921 | |
902 | |
922 | bool |
903 | bool |
923 | 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) |
924 | { |
905 | { |
925 | bool ret = false; |
906 | bool ret = false; |
926 | |
907 | |
927 | 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)) |
928 | { |
917 | { |
929 | XGCValues gcv; |
918 | XGCValues gcv; |
930 | GC gc; |
919 | GC gc; |
931 | |
920 | |
932 | /* In this case we can tint image server-side getting significant |
921 | /* In this case we can tint image server-side getting significant |
… | |
… | |
944 | } |
933 | } |
945 | } |
934 | } |
946 | # if XRENDER |
935 | # if XRENDER |
947 | else if (bg_flags & BG_HAS_RENDER) |
936 | else if (bg_flags & BG_HAS_RENDER) |
948 | { |
937 | { |
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) |
938 | if (shade <= 100) |
955 | { |
939 | { |
956 | c.r = c.r * shade / 100; |
940 | c.r = c.r * shade / 100; |
957 | c.g = c.g * shade / 100; |
941 | c.g = c.g * shade / 100; |
958 | c.b = c.b * shade / 100; |
942 | c.b = c.b * shade / 100; |
… | |
… | |
962 | c.r = c.r * (200 - shade) / 100; |
946 | c.r = c.r * (200 - shade) / 100; |
963 | c.g = c.g * (200 - shade) / 100; |
947 | c.g = c.g * (200 - shade) / 100; |
964 | c.b = c.b * (200 - shade) / 100; |
948 | c.b = c.b * (200 - shade) / 100; |
965 | } |
949 | } |
966 | |
950 | |
967 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
951 | XRenderPictFormat *format = argb ? XRenderFindStandardFormat (dpy, PictStandardARGB32) |
|
|
952 | : XRenderFindVisualFormat (dpy, visual); |
968 | |
953 | |
969 | Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, 0); |
954 | Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, 0); |
970 | |
955 | |
971 | Picture overlay_pic = create_xrender_mask (dpy, pixmap, True, False); |
956 | Picture overlay_pic = create_xrender_mask (dpy, pixmap, True, False); |
972 | |
957 | |
… | |
… | |
1008 | # endif |
993 | # endif |
1009 | |
994 | |
1010 | return ret; |
995 | return ret; |
1011 | } |
996 | } |
1012 | |
997 | |
|
|
998 | # ifdef ENABLE_TRANSPARENCY |
1013 | /* |
999 | /* |
1014 | * 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 |
1015 | * 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 |
1016 | * our window. |
1002 | * our window. |
1017 | */ |
1003 | */ |
… | |
… | |
1108 | |
1094 | |
1109 | if (gc) |
1095 | if (gc) |
1110 | { |
1096 | { |
1111 | XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height); |
1097 | XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height); |
1112 | ret = true; |
1098 | ret = true; |
1113 | bool need_blur = h_blurRadius && v_blurRadius; |
1099 | bool need_blur = root_effects.need_blur (); |
1114 | bool need_tint = shade != 100 || (bg_flags & BG_TINT_SET); |
1100 | bool need_tint = root_effects.need_tint (); |
1115 | |
1101 | |
1116 | if (!(bg_flags & BG_CLIENT_RENDER)) |
1102 | if (!(bg_flags & BG_CLIENT_RENDER)) |
1117 | { |
1103 | { |
1118 | if (need_blur) |
1104 | if (need_blur) |
1119 | { |
1105 | { |
1120 | if (blur_pixmap (bg_pixmap, window_width, window_height)) |
1106 | if (blur_pixmap (bg_pixmap, window_width, window_height, false, |
|
|
1107 | root_effects.h_blurRadius, root_effects.v_blurRadius)) |
1121 | need_blur = false; |
1108 | need_blur = false; |
1122 | } |
1109 | } |
1123 | if (need_tint) |
1110 | if (need_tint) |
1124 | { |
1111 | { |
1125 | if (tint_pixmap (bg_pixmap, window_width, window_height)) |
1112 | if (tint_pixmap (bg_pixmap, window_width, window_height, false, |
|
|
1113 | root_effects.tint, root_effects.tint_set, root_effects.shade)) |
1126 | need_tint = false; |
1114 | need_tint = false; |
1127 | } |
1115 | } |
1128 | if (need_tint) |
1116 | if (need_tint) |
1129 | { |
1117 | { |
1130 | XImage *ximage = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap); |
1118 | XImage *ximage = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap); |
1131 | if (ximage) |
1119 | if (ximage) |
1132 | { |
1120 | { |
1133 | /* our own client-side tinting */ |
1121 | /* our own client-side tinting */ |
1134 | tint_ximage (ximage); |
1122 | tint_ximage (ximage, root_effects.tint, root_effects.tint_set, root_effects.shade); |
1135 | |
1123 | |
1136 | XPutImage (dpy, bg_pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height); |
1124 | XPutImage (dpy, bg_pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height); |
1137 | XDestroyImage (ximage); |
1125 | XDestroyImage (ximage); |
1138 | } |
1126 | } |
1139 | } |
1127 | } |
… | |
… | |
1198 | } |
1186 | } |
1199 | |
1187 | |
1200 | void |
1188 | void |
1201 | rxvt_term::bg_init () |
1189 | rxvt_term::bg_init () |
1202 | { |
1190 | { |
1203 | #ifdef ENABLE_TRANSPARENCY |
|
|
1204 | shade = 100; |
|
|
1205 | #endif |
|
|
1206 | |
|
|
1207 | bg_flags &= ~(BG_HAS_RENDER | BG_HAS_RENDER_CONV); |
1191 | bg_flags &= ~(BG_HAS_RENDER | BG_HAS_RENDER_CONV); |
1208 | #if XRENDER |
1192 | #if XRENDER |
1209 | int major, minor; |
1193 | int major, minor; |
1210 | if (XRenderQueryVersion (dpy, &major, &minor)) |
1194 | if (XRenderQueryVersion (dpy, &major, &minor)) |
1211 | bg_flags |= BG_HAS_RENDER; |
1195 | bg_flags |= BG_HAS_RENDER; |
… | |
… | |
1234 | while (bg_image != image_vec.end ()) |
1218 | while (bg_image != image_vec.end ()) |
1235 | { |
1219 | { |
1236 | if (!(bg_image->flags & IM_IS_SET)) |
1220 | if (!(bg_image->flags & IM_IS_SET)) |
1237 | bg_image = image_vec.erase (bg_image); |
1221 | bg_image = image_vec.erase (bg_image); |
1238 | else |
1222 | else |
|
|
1223 | { |
|
|
1224 | if (bg_image->is_size_sensitive ()) |
|
|
1225 | bg_image->flags |= IM_IS_SIZE_SENSITIVE; |
|
|
1226 | |
1239 | bg_image++; |
1227 | bg_image++; |
|
|
1228 | } |
1240 | } |
1229 | } |
1241 | # endif |
1230 | # endif |
1242 | |
1231 | |
1243 | if (image_vec.size () > 0 |
1232 | if (image_vec.size () > 0 |
1244 | && !bg_window_position_sensitive ()) |
1233 | && !bg_window_position_sensitive ()) |
1245 | update_background (); |
1234 | update_background (); |
1246 | #endif |
1235 | #endif |
1247 | } |
1236 | } |
1248 | |
1237 | |
1249 | #endif /* HAVE_BG_PIXMAP */ |
|
|
1250 | |
|
|
1251 | #ifdef ENABLE_TRANSPARENCY |
|
|
1252 | /* based on code from aterm-0.4.2 */ |
1238 | /* based on code from aterm-0.4.2 */ |
1253 | |
1239 | |
1254 | static inline void |
1240 | static inline void |
1255 | fill_lut (uint32_t *lookup, uint32_t mask, int sh, unsigned short low, unsigned short high) |
1241 | fill_lut (uint32_t *lookup, uint32_t mask, int sh, unsigned short low, unsigned short high) |
1256 | { |
1242 | { |
… | |
… | |
1262 | lookup[i] = (tmp / 0xffff) << sh; |
1248 | lookup[i] = (tmp / 0xffff) << sh; |
1263 | } |
1249 | } |
1264 | } |
1250 | } |
1265 | |
1251 | |
1266 | void |
1252 | void |
1267 | rxvt_term::tint_ximage (XImage *ximage) |
1253 | rxvt_term::tint_ximage (XImage *ximage, rxvt_color &tint, bool tint_set, int shade) |
1268 | { |
1254 | { |
1269 | unsigned int size_r, size_g, size_b; |
1255 | unsigned int size_r, size_g, size_b; |
1270 | int sh_r, sh_g, sh_b; |
1256 | int sh_r, sh_g, sh_b; |
1271 | uint32_t mask_r, mask_g, mask_b; |
1257 | uint32_t mask_r, mask_g, mask_b; |
1272 | uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; |
1258 | uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; |
… | |
… | |
1297 | lookup_g = lookup + size_r; |
1283 | lookup_g = lookup + size_r; |
1298 | lookup_b = lookup + size_r + size_g; |
1284 | lookup_b = lookup + size_r + size_g; |
1299 | |
1285 | |
1300 | rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); |
1286 | rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); |
1301 | |
1287 | |
1302 | if (bg_flags & BG_TINT_SET) |
1288 | if (tint_set) |
1303 | tint.get (c); |
1289 | tint.get (c); |
1304 | |
1290 | |
1305 | /* prepare limits for color transformation (each channel is handled separately) */ |
1291 | /* prepare limits for color transformation (each channel is handled separately) */ |
1306 | if (shade > 100) |
1292 | if (shade > 100) |
1307 | { |
1293 | { |
… | |
… | |
1357 | } |
1343 | } |
1358 | } |
1344 | } |
1359 | |
1345 | |
1360 | free (lookup); |
1346 | free (lookup); |
1361 | } |
1347 | } |
1362 | #endif /* ENABLE_TRANSPARENCY */ |
1348 | |
|
|
1349 | #endif /* HAVE_BG_PIXMAP */ |