… | |
… | |
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; |
… | |
… | |
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 | |
… | |
… | |
603 | |
617 | |
604 | Picture mask = create_xrender_mask (dpy, vt, False, False); |
618 | Picture mask = create_xrender_mask (dpy, vt, False, False); |
605 | |
619 | |
606 | XRenderColor mask_c; |
620 | XRenderColor mask_c; |
607 | |
621 | |
608 | mask_c.alpha = 0x8000; |
622 | mask_c.alpha = image.alpha; |
609 | mask_c.red = |
623 | mask_c.red = |
610 | mask_c.green = |
624 | mask_c.green = |
611 | mask_c.blue = 0; |
625 | mask_c.blue = 0; |
612 | XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); |
626 | XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); |
613 | |
627 | |
… | |
… | |
632 | |
646 | |
633 | return ret; |
647 | return ret; |
634 | } |
648 | } |
635 | # endif /* HAVE_PIXBUF */ |
649 | # endif /* HAVE_PIXBUF */ |
636 | |
650 | |
|
|
651 | # ifndef NO_RESOURCES |
|
|
652 | static int |
|
|
653 | rxvt_define_image (XrmDatabase *database ecb_unused, |
|
|
654 | XrmBindingList bindings ecb_unused, |
|
|
655 | XrmQuarkList quarks, |
|
|
656 | XrmRepresentation *type ecb_unused, |
|
|
657 | XrmValue *value, |
|
|
658 | XPointer closure ecb_unused) |
|
|
659 | { |
|
|
660 | int size; |
|
|
661 | |
|
|
662 | for (size = 0; quarks[size] != NULLQUARK; size++) |
|
|
663 | ; |
|
|
664 | |
|
|
665 | if (size >= 2) |
|
|
666 | { |
|
|
667 | int id = strtol (XrmQuarkToString (quarks[size-2]), 0, 0); |
|
|
668 | if (id >= 1) |
|
|
669 | GET_R->parse_image (id, XrmQuarkToString (quarks[size-1]), (char *)value->addr); |
|
|
670 | } |
|
|
671 | return False; |
|
|
672 | } |
|
|
673 | |
|
|
674 | void |
|
|
675 | rxvt_term::parse_image (int id, const char *type, const char *arg) |
|
|
676 | { |
|
|
677 | if (image_vec.size () < id + 1) |
|
|
678 | image_vec.resize (id + 1); |
|
|
679 | |
|
|
680 | rxvt_image *image = &image_vec[id]; |
|
|
681 | } |
|
|
682 | # endif |
|
|
683 | |
|
|
684 | rxvt_image::rxvt_image () |
|
|
685 | { |
|
|
686 | alpha = 0xffff; |
|
|
687 | flags = 0; |
|
|
688 | h_scale = |
|
|
689 | v_scale = defaultScale; |
|
|
690 | h_align = |
|
|
691 | v_align = defaultAlign; |
|
|
692 | |
|
|
693 | # ifdef HAVE_PIXBUF |
|
|
694 | pixbuf = 0; |
|
|
695 | # endif |
|
|
696 | } |
|
|
697 | |
637 | bool |
698 | bool |
638 | rxvt_image::set_file (const char *file) |
699 | rxvt_image::set_file_geometry (const char *file) |
639 | { |
700 | { |
640 | if (!file || !*file) |
701 | if (!file || !*file) |
641 | return false; |
702 | return false; |
642 | |
703 | |
643 | bool ret = false; |
|
|
644 | const char *p = strchr (file, ';'); |
704 | const char *p = strchr (file, ';'); |
645 | |
705 | |
646 | if (p) |
706 | if (p) |
647 | { |
707 | { |
648 | size_t len = p - file; |
708 | size_t len = p - file; |
… | |
… | |
650 | memcpy (f, file, len); |
710 | memcpy (f, file, len); |
651 | f[len] = '\0'; |
711 | f[len] = '\0'; |
652 | file = f; |
712 | file = f; |
653 | } |
713 | } |
654 | |
714 | |
|
|
715 | bool ret = set_file (file); |
|
|
716 | alpha = 0x8000; |
|
|
717 | if (ret) |
|
|
718 | set_geometry (p ? p + 1 : ""); |
|
|
719 | return ret; |
|
|
720 | } |
|
|
721 | |
|
|
722 | bool |
|
|
723 | rxvt_image::set_file (const char *file) |
|
|
724 | { |
|
|
725 | bool ret = false; |
|
|
726 | |
655 | # ifdef HAVE_PIXBUF |
727 | # ifdef HAVE_PIXBUF |
656 | GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); |
728 | GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); |
657 | if (image) |
729 | if (image) |
658 | { |
730 | { |
659 | if (pixbuf) |
731 | if (pixbuf) |
… | |
… | |
662 | ret = true; |
734 | ret = true; |
663 | } |
735 | } |
664 | # endif |
736 | # endif |
665 | |
737 | |
666 | if (ret) |
738 | if (ret) |
667 | { |
739 | 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 | |
740 | |
676 | return ret; |
741 | return ret; |
677 | } |
742 | } |
678 | |
743 | |
679 | # endif /* BG_IMAGE_FROM_FILE */ |
744 | # endif /* BG_IMAGE_FROM_FILE */ |
… | |
… | |
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)) |
… | |
… | |
1136 | if (!strcmp (filters->filter[i], FilterConvolution)) |
1201 | if (!strcmp (filters->filter[i], FilterConvolution)) |
1137 | bg_flags |= BG_HAS_RENDER_CONV; |
1202 | bg_flags |= BG_HAS_RENDER_CONV; |
1138 | |
1203 | |
1139 | XFree (filters); |
1204 | XFree (filters); |
1140 | } |
1205 | } |
|
|
1206 | #endif |
|
|
1207 | |
|
|
1208 | #ifdef BG_IMAGE_FROM_FILE |
|
|
1209 | if (rs[Rs_backgroundPixmap]) |
|
|
1210 | { |
|
|
1211 | rxvt_image *image = new_image (); |
|
|
1212 | if (!image->set_file_geometry (rs[Rs_backgroundPixmap])) |
|
|
1213 | image_vec.pop_back (); |
|
|
1214 | } |
|
|
1215 | |
|
|
1216 | # ifndef NO_RESOURCES |
|
|
1217 | find_resources ("image", "Image", XrmEnumAllLevels, rxvt_define_image); |
|
|
1218 | vector<rxvt_image>::iterator bg_image = image_vec.begin (); |
|
|
1219 | while (bg_image != image_vec.end ()) |
|
|
1220 | { |
|
|
1221 | if (!(bg_image->flags & IM_IS_SET)) |
|
|
1222 | bg_image = image_vec.erase (bg_image); |
|
|
1223 | else |
|
|
1224 | { |
|
|
1225 | if (bg_image->is_size_sensitive ()) |
|
|
1226 | bg_image->flags |= IM_IS_SIZE_SENSITIVE; |
|
|
1227 | |
|
|
1228 | bg_image++; |
|
|
1229 | } |
|
|
1230 | } |
|
|
1231 | # endif |
|
|
1232 | |
|
|
1233 | if (image_vec.size () > 0 |
|
|
1234 | && !bg_window_position_sensitive ()) |
|
|
1235 | update_background (); |
1141 | #endif |
1236 | #endif |
1142 | } |
1237 | } |
1143 | |
1238 | |
1144 | #endif /* HAVE_BG_PIXMAP */ |
1239 | #endif /* HAVE_BG_PIXMAP */ |
1145 | |
1240 | |