… | |
… | |
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++) |
64 | for (vector<rxvt_image>::iterator bg_image = image_vec.begin (); bg_image < image_vec.end (); bg_image++) |
65 | bg_image->destroy (); |
65 | bg_image->destroy (); |
66 | # endif |
66 | # endif |
67 | |
67 | |
68 | if (bg_pixmap) |
68 | if (bg_pixmap) |
… | |
… | |
84 | } |
84 | } |
85 | |
85 | |
86 | bool |
86 | bool |
87 | rxvt_term::bg_window_size_sensitive () |
87 | rxvt_term::bg_window_size_sensitive () |
88 | { |
88 | { |
89 | # ifdef ENABLE_TRANSPARENCY |
89 | # if ENABLE_TRANSPARENCY |
90 | if (bg_flags & BG_IS_TRANSPARENT) |
90 | if (bg_flags & BG_IS_TRANSPARENT) |
91 | return true; |
91 | return true; |
92 | # endif |
92 | # endif |
93 | |
93 | |
94 | # ifdef BG_IMAGE_FROM_FILE |
94 | # if BG_IMAGE_FROM_FILE |
95 | for (vector<rxvt_image>::iterator bg_image = image_vec.begin (); bg_image < image_vec.end (); bg_image++) |
95 | for (vector<rxvt_image>::iterator bg_image = image_vec.begin (); bg_image < image_vec.end (); bg_image++) |
96 | { |
96 | { |
97 | if ((bg_image->flags & IM_IS_SIZE_SENSITIVE) |
97 | if ((bg_image->flags & IM_IS_SIZE_SENSITIVE) |
98 | || bg_image->width () > szHint.width |
98 | || bg_image->width () > szHint.width |
99 | || bg_image->height () > szHint.height) |
99 | || bg_image->height () > szHint.height) |
… | |
… | |
105 | } |
105 | } |
106 | |
106 | |
107 | bool |
107 | bool |
108 | rxvt_term::bg_window_position_sensitive () |
108 | rxvt_term::bg_window_position_sensitive () |
109 | { |
109 | { |
110 | # ifdef ENABLE_TRANSPARENCY |
110 | # if ENABLE_TRANSPARENCY |
111 | if (bg_flags & BG_IS_TRANSPARENT) |
111 | if (bg_flags & BG_IS_TRANSPARENT) |
112 | return true; |
112 | return true; |
113 | # endif |
113 | # endif |
114 | |
114 | |
115 | # ifdef BG_IMAGE_FROM_FILE |
115 | # if BG_IMAGE_FROM_FILE |
116 | for (vector<rxvt_image>::iterator bg_image = image_vec.begin (); bg_image < image_vec.end (); bg_image++) |
116 | for (vector<rxvt_image>::iterator bg_image = image_vec.begin (); bg_image < image_vec.end (); bg_image++) |
117 | { |
117 | { |
118 | if (bg_image->flags & IM_ROOT_ALIGN) |
118 | if (bg_image->flags & IM_ROOT_ALIGN) |
119 | return true; |
119 | return true; |
120 | } |
120 | } |
121 | # endif |
121 | # endif |
122 | |
122 | |
123 | return false; |
123 | return false; |
124 | } |
124 | } |
125 | |
125 | |
126 | # ifdef BG_IMAGE_FROM_FILE |
126 | # if BG_IMAGE_FROM_FILE |
127 | static inline int |
127 | static inline int |
128 | make_align_position (int align, int window_size, int image_size) |
128 | make_align_position (int align, int window_size, int image_size) |
129 | { |
129 | { |
130 | if (align >= 0 && align <= 100) |
130 | if (align >= 0 && align <= 100) |
131 | return lerp (0, window_size - image_size, align); |
131 | return lerp (0, window_size - image_size, align); |
… | |
… | |
347 | x = make_align_position (image.h_align, target_width, w); |
347 | x = make_align_position (image.h_align, target_width, w); |
348 | y = make_align_position (image.v_align, target_height, h); |
348 | y = make_align_position (image.v_align, target_height, h); |
349 | } |
349 | } |
350 | } |
350 | } |
351 | |
351 | |
352 | # ifdef HAVE_PIXBUF |
352 | # if HAVE_PIXBUF |
353 | bool |
353 | bool |
354 | rxvt_term::pixbuf_to_pixmap (GdkPixbuf *pixbuf, Pixmap pixmap, GC gc, |
354 | rxvt_term::pixbuf_to_pixmap (GdkPixbuf *pixbuf, Pixmap pixmap, GC gc, |
355 | int src_x, int src_y, int dst_x, int dst_y, |
355 | int src_x, int src_y, int dst_x, int dst_y, |
356 | unsigned int width, unsigned int height, bool argb) |
356 | unsigned int width, unsigned int height, bool argb) |
357 | { |
357 | { |
… | |
… | |
484 | return false; |
484 | return false; |
485 | |
485 | |
486 | bool need_blend = bg_flags & BG_IS_VALID; |
486 | bool need_blend = bg_flags & BG_IS_VALID; |
487 | |
487 | |
488 | if (need_blend |
488 | if (need_blend |
489 | && !(bg_flags & BG_HAS_RENDER)) |
489 | && !(display->flags & DISPLAY_HAS_RENDER)) |
490 | return false; |
490 | return false; |
491 | |
491 | |
492 | GdkPixbuf *result; |
492 | GdkPixbuf *result; |
493 | |
493 | |
494 | int image_width = gdk_pixbuf_get_width (pixbuf); |
494 | int image_width = gdk_pixbuf_get_width (pixbuf); |
… | |
… | |
673 | if (id >= 1) |
673 | if (id >= 1) |
674 | GET_R->parse_image (id, XrmQuarkToString (quarks[size-1]), (char *)value->addr); |
674 | GET_R->parse_image (id, XrmQuarkToString (quarks[size-1]), (char *)value->addr); |
675 | } |
675 | } |
676 | return False; |
676 | return False; |
677 | } |
677 | } |
|
|
678 | # endif |
678 | |
679 | |
679 | void |
680 | void |
680 | rxvt_term::parse_image (int id, const char *type, const char *arg) |
681 | rxvt_term::parse_image (int id, const char *type, const char *arg) |
681 | { |
682 | { |
682 | if (image_vec.size () < id + 1) |
683 | if (image_vec.size () < id + 1) |
683 | image_vec.resize (id + 1); |
684 | image_vec.resize (id + 1); |
684 | |
685 | |
685 | rxvt_image *image = &image_vec[id]; |
686 | rxvt_image *image = &image_vec[id]; |
686 | } |
687 | } |
687 | # endif |
|
|
688 | |
688 | |
689 | rxvt_image::rxvt_image () |
689 | rxvt_image::rxvt_image () |
690 | { |
690 | { |
691 | alpha = 0xffff; |
691 | alpha = 0xffff; |
692 | flags = 0; |
692 | flags = 0; |
693 | h_scale = |
693 | h_scale = |
694 | v_scale = defaultScale; |
694 | v_scale = defaultScale; |
695 | h_align = |
695 | h_align = |
696 | v_align = defaultAlign; |
696 | v_align = defaultAlign; |
697 | |
697 | |
698 | # ifdef HAVE_PIXBUF |
698 | # if HAVE_PIXBUF |
699 | pixbuf = 0; |
699 | pixbuf = 0; |
700 | # endif |
700 | # endif |
701 | } |
701 | } |
702 | |
702 | |
703 | bool |
703 | bool |
… | |
… | |
727 | bool |
727 | bool |
728 | rxvt_image::set_file (const char *file) |
728 | rxvt_image::set_file (const char *file) |
729 | { |
729 | { |
730 | bool ret = false; |
730 | bool ret = false; |
731 | |
731 | |
732 | # ifdef HAVE_PIXBUF |
732 | # if HAVE_PIXBUF |
733 | GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); |
733 | GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); |
734 | if (image) |
734 | if (image) |
735 | { |
735 | { |
736 | if (pixbuf) |
736 | if (pixbuf) |
737 | g_object_unref (pixbuf); |
737 | g_object_unref (pixbuf); |
… | |
… | |
837 | bool |
837 | bool |
838 | rxvt_term::blur_pixmap (Pixmap pixmap, int width, int height, bool argb, int h_blurRadius, int v_blurRadius) |
838 | rxvt_term::blur_pixmap (Pixmap pixmap, int width, int height, bool argb, int h_blurRadius, int v_blurRadius) |
839 | { |
839 | { |
840 | bool ret = false; |
840 | bool ret = false; |
841 | #if XRENDER |
841 | #if XRENDER |
842 | if (!(bg_flags & BG_HAS_RENDER_CONV)) |
842 | if (!(display->flags & DISPLAY_HAS_RENDER_CONV)) |
843 | return false; |
843 | return false; |
844 | |
844 | |
845 | int size = max (h_blurRadius, v_blurRadius) * 2 + 1; |
845 | int size = max (h_blurRadius, v_blurRadius) * 2 + 1; |
846 | double *kernel = (double *)malloc (size * sizeof (double)); |
846 | double *kernel = (double *)malloc (size * sizeof (double)); |
847 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
847 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
… | |
… | |
931 | ret = true; |
931 | ret = true; |
932 | XFreeGC (dpy, gc); |
932 | XFreeGC (dpy, gc); |
933 | } |
933 | } |
934 | } |
934 | } |
935 | # if XRENDER |
935 | # if XRENDER |
936 | else if (bg_flags & BG_HAS_RENDER) |
936 | else if (display->flags & DISPLAY_HAS_RENDER) |
937 | { |
937 | { |
938 | if (shade <= 100) |
938 | if (shade <= 100) |
939 | { |
939 | { |
940 | c.r = c.r * shade / 100; |
940 | c.r = c.r * shade / 100; |
941 | c.g = c.g * shade / 100; |
941 | c.g = c.g * shade / 100; |
… | |
… | |
993 | # endif |
993 | # endif |
994 | |
994 | |
995 | return ret; |
995 | return ret; |
996 | } |
996 | } |
997 | |
997 | |
998 | # ifdef ENABLE_TRANSPARENCY |
998 | # if ENABLE_TRANSPARENCY |
999 | /* |
999 | /* |
1000 | * 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 |
1001 | * 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 |
1002 | * our window. |
1002 | * our window. |
1003 | */ |
1003 | */ |
1004 | bool |
1004 | bool |
1005 | rxvt_term::make_transparency_pixmap () |
1005 | rxvt_term::render_root_image () |
1006 | { |
1006 | { |
1007 | bool ret = false; |
1007 | bool ret = false; |
1008 | |
1008 | |
1009 | /* 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 |
1010 | * be always up-to-date, so let's use it : |
1010 | * be always up-to-date, so let's use it : |
… | |
… | |
1046 | Pixmap recoded_root_pmap = root_pixmap; |
1046 | Pixmap recoded_root_pmap = root_pixmap; |
1047 | |
1047 | |
1048 | if (root_pixmap != None && root_depth != depth) |
1048 | if (root_pixmap != None && root_depth != depth) |
1049 | { |
1049 | { |
1050 | #if XRENDER |
1050 | #if XRENDER |
1051 | if (bg_flags & BG_HAS_RENDER) |
1051 | if (display->flags & DISPLAY_HAS_RENDER) |
1052 | { |
1052 | { |
1053 | 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); |
1054 | |
1054 | |
1055 | XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen)); |
1055 | XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen)); |
1056 | Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, 0); |
1056 | Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, 0); |
… | |
… | |
1097 | XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height); |
1097 | XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height); |
1098 | ret = true; |
1098 | ret = true; |
1099 | bool need_blur = root_effects.need_blur (); |
1099 | bool need_blur = root_effects.need_blur (); |
1100 | bool need_tint = root_effects.need_tint (); |
1100 | bool need_tint = root_effects.need_tint (); |
1101 | |
1101 | |
1102 | if (!(bg_flags & BG_CLIENT_RENDER)) |
|
|
1103 | { |
|
|
1104 | 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) |
1105 | { |
1118 | { |
1106 | if (blur_pixmap (bg_pixmap, window_width, window_height, false, |
1119 | /* our own client-side tinting */ |
1107 | root_effects.h_blurRadius, root_effects.v_blurRadius)) |
1120 | tint_ximage (ximage, root_effects.tint, root_effects.tint_set, root_effects.shade); |
1108 | need_blur = false; |
1121 | |
|
|
1122 | XPutImage (dpy, bg_pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height); |
|
|
1123 | XDestroyImage (ximage); |
1109 | } |
1124 | } |
1110 | if (need_tint) |
|
|
1111 | { |
|
|
1112 | if (tint_pixmap (bg_pixmap, window_width, window_height, false, |
|
|
1113 | root_effects.tint, root_effects.tint_set, root_effects.shade)) |
|
|
1114 | need_tint = false; |
|
|
1115 | } |
1125 | } |
1116 | if (need_tint) |
|
|
1117 | { |
|
|
1118 | XImage *ximage = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap); |
|
|
1119 | if (ximage) |
|
|
1120 | { |
|
|
1121 | /* our own client-side tinting */ |
|
|
1122 | tint_ximage (ximage, root_effects.tint, root_effects.tint_set, root_effects.shade); |
|
|
1123 | |
|
|
1124 | XPutImage (dpy, bg_pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height); |
|
|
1125 | XDestroyImage (ximage); |
|
|
1126 | } |
|
|
1127 | } |
|
|
1128 | } /* server side rendering completed */ |
|
|
1129 | |
1126 | |
1130 | XFreeGC (dpy, gc); |
1127 | XFreeGC (dpy, gc); |
1131 | } |
1128 | } |
1132 | |
1129 | |
1133 | if (recoded_root_pmap != root_pixmap) |
1130 | if (recoded_root_pmap != root_pixmap) |
… | |
… | |
1137 | } |
1134 | } |
1138 | |
1135 | |
1139 | void |
1136 | void |
1140 | rxvt_term::bg_set_root_pixmap () |
1137 | rxvt_term::bg_set_root_pixmap () |
1141 | { |
1138 | { |
1142 | Pixmap new_root_pixmap = get_pixmap_property (xa[XA_XROOTPMAP_ID]); |
1139 | Pixmap new_root_pixmap = display->get_pixmap_property (xa[XA_XROOTPMAP_ID]); |
1143 | if (new_root_pixmap == None) |
1140 | if (new_root_pixmap == None) |
1144 | new_root_pixmap = get_pixmap_property (xa[XA_ESETROOT_PMAP_ID]); |
1141 | new_root_pixmap = display->get_pixmap_property (xa[XA_ESETROOT_PMAP_ID]); |
1145 | |
1142 | |
1146 | root_pixmap = new_root_pixmap; |
1143 | root_pixmap = new_root_pixmap; |
1147 | } |
1144 | } |
1148 | # endif /* ENABLE_TRANSPARENCY */ |
1145 | # endif /* ENABLE_TRANSPARENCY */ |
1149 | |
1146 | |
1150 | bool |
1147 | bool |
1151 | rxvt_term::bg_render () |
1148 | rxvt_term::bg_render () |
1152 | { |
1149 | { |
1153 | bg_invalidate (); |
1150 | bg_invalidate (); |
1154 | # ifdef ENABLE_TRANSPARENCY |
1151 | # if ENABLE_TRANSPARENCY |
1155 | if (bg_flags & BG_IS_TRANSPARENT) |
1152 | if (bg_flags & BG_IS_TRANSPARENT) |
1156 | { |
1153 | { |
1157 | /* we need to re-generate transparency pixmap in that case ! */ |
1154 | /* we need to re-generate transparency pixmap in that case ! */ |
1158 | if (make_transparency_pixmap ()) |
1155 | if (render_root_image ()) |
1159 | bg_flags |= BG_IS_VALID; |
1156 | bg_flags |= BG_IS_VALID; |
1160 | } |
1157 | } |
1161 | # endif |
1158 | # endif |
1162 | |
1159 | |
1163 | # ifdef BG_IMAGE_FROM_FILE |
1160 | # if BG_IMAGE_FROM_FILE |
1164 | for (vector<rxvt_image>::iterator bg_image = image_vec.begin (); bg_image < image_vec.end (); bg_image++) |
1161 | for (vector<rxvt_image>::iterator bg_image = image_vec.begin (); bg_image < image_vec.end (); bg_image++) |
1165 | { |
1162 | { |
1166 | if (render_image (*bg_image)) |
1163 | if (render_image (*bg_image)) |
1167 | bg_flags |= BG_IS_VALID; |
1164 | bg_flags |= BG_IS_VALID; |
1168 | } |
1165 | } |
… | |
… | |
1186 | } |
1183 | } |
1187 | |
1184 | |
1188 | void |
1185 | void |
1189 | rxvt_term::bg_init () |
1186 | rxvt_term::bg_init () |
1190 | { |
1187 | { |
1191 | bg_flags &= ~(BG_HAS_RENDER | BG_HAS_RENDER_CONV); |
|
|
1192 | #if XRENDER |
|
|
1193 | int major, minor; |
|
|
1194 | if (XRenderQueryVersion (dpy, &major, &minor)) |
|
|
1195 | bg_flags |= BG_HAS_RENDER; |
|
|
1196 | XFilters *filters = XRenderQueryFilters (dpy, vt); |
|
|
1197 | if (filters) |
|
|
1198 | { |
|
|
1199 | for (int i = 0; i < filters->nfilter; i++) |
|
|
1200 | if (!strcmp (filters->filter[i], FilterConvolution)) |
|
|
1201 | bg_flags |= BG_HAS_RENDER_CONV; |
|
|
1202 | |
|
|
1203 | XFree (filters); |
|
|
1204 | } |
|
|
1205 | #endif |
|
|
1206 | |
|
|
1207 | #ifdef BG_IMAGE_FROM_FILE |
1188 | #if BG_IMAGE_FROM_FILE |
1208 | if (rs[Rs_backgroundPixmap]) |
1189 | if (rs[Rs_backgroundPixmap]) |
1209 | { |
1190 | { |
1210 | rxvt_image *image = new_image (); |
1191 | rxvt_image *image = new_image (); |
1211 | if (!image->set_file_geometry (rs[Rs_backgroundPixmap])) |
1192 | if (!image->set_file_geometry (rs[Rs_backgroundPixmap])) |
1212 | image_vec.pop_back (); |
1193 | image_vec.pop_back (); |
1213 | } |
1194 | } |
1214 | |
1195 | |
1215 | # ifndef NO_RESOURCES |
1196 | # ifndef NO_RESOURCES |
1216 | find_resources ("image", "Image", XrmEnumAllLevels, rxvt_define_image); |
1197 | find_resources ("image", "Image", XrmEnumAllLevels, rxvt_define_image); |
|
|
1198 | # endif |
|
|
1199 | |
1217 | vector<rxvt_image>::iterator bg_image = image_vec.begin (); |
1200 | vector<rxvt_image>::iterator bg_image = image_vec.begin (); |
1218 | while (bg_image != image_vec.end ()) |
1201 | while (bg_image != image_vec.end ()) |
1219 | { |
1202 | { |
1220 | if (!(bg_image->flags & IM_IS_SET)) |
1203 | if (!(bg_image->flags & IM_IS_SET)) |
1221 | bg_image = image_vec.erase (bg_image); |
1204 | bg_image = image_vec.erase (bg_image); |
… | |
… | |
1225 | bg_image->flags |= IM_IS_SIZE_SENSITIVE; |
1208 | bg_image->flags |= IM_IS_SIZE_SENSITIVE; |
1226 | |
1209 | |
1227 | bg_image++; |
1210 | bg_image++; |
1228 | } |
1211 | } |
1229 | } |
1212 | } |
1230 | # endif |
|
|
1231 | |
1213 | |
1232 | if (image_vec.size () > 0 |
1214 | if (image_vec.size () > 0 |
1233 | && !bg_window_position_sensitive ()) |
1215 | && !bg_window_position_sensitive ()) |
1234 | update_background (); |
1216 | update_background (); |
1235 | #endif |
1217 | #endif |