… | |
… | |
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; |
… | |
… | |
527 | |
539 | |
528 | if (need_blend) |
540 | if (need_blend) |
529 | tmp_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, 32); |
541 | tmp_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, 32); |
530 | else |
542 | else |
531 | { |
543 | { |
|
|
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. |
532 | if (image.flags & IM_TILE) |
547 | if ((image.flags & IM_TILE) |
|
|
548 | && image_vec.size () == 1) |
533 | { |
549 | { |
534 | new_pmap_width = min (image_width, target_width); |
550 | new_pmap_width = min (image_width, target_width); |
535 | new_pmap_height = min (image_height, target_height); |
551 | new_pmap_height = min (image_height, target_height); |
536 | } |
552 | } |
537 | |
553 | |
… | |
… | |
603 | |
619 | |
604 | Picture mask = create_xrender_mask (dpy, vt, False, False); |
620 | Picture mask = create_xrender_mask (dpy, vt, False, False); |
605 | |
621 | |
606 | XRenderColor mask_c; |
622 | XRenderColor mask_c; |
607 | |
623 | |
608 | mask_c.alpha = 0x8000; |
624 | mask_c.alpha = image.alpha; |
609 | mask_c.red = |
625 | mask_c.red = |
610 | mask_c.green = |
626 | mask_c.green = |
611 | mask_c.blue = 0; |
627 | mask_c.blue = 0; |
612 | XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); |
628 | XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); |
613 | |
629 | |
… | |
… | |
632 | |
648 | |
633 | return ret; |
649 | return ret; |
634 | } |
650 | } |
635 | # endif /* HAVE_PIXBUF */ |
651 | # endif /* HAVE_PIXBUF */ |
636 | |
652 | |
|
|
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 | if (image_vec.size () < id + 1) |
|
|
680 | image_vec.resize (id + 1); |
|
|
681 | |
|
|
682 | rxvt_image *image = &image_vec[id]; |
|
|
683 | } |
|
|
684 | # endif |
|
|
685 | |
|
|
686 | rxvt_image::rxvt_image () |
|
|
687 | { |
|
|
688 | alpha = 0xffff; |
|
|
689 | flags = 0; |
|
|
690 | h_scale = |
|
|
691 | v_scale = defaultScale; |
|
|
692 | h_align = |
|
|
693 | v_align = defaultAlign; |
|
|
694 | |
|
|
695 | # ifdef HAVE_PIXBUF |
|
|
696 | pixbuf = 0; |
|
|
697 | # endif |
|
|
698 | } |
|
|
699 | |
637 | bool |
700 | bool |
638 | rxvt_image::set_file (const char *file) |
701 | rxvt_image::set_file_geometry (const char *file) |
639 | { |
702 | { |
640 | if (!file || !*file) |
703 | if (!file || !*file) |
641 | return false; |
704 | return false; |
642 | |
705 | |
643 | bool ret = false; |
|
|
644 | const char *p = strchr (file, ';'); |
706 | const char *p = strchr (file, ';'); |
645 | |
707 | |
646 | if (p) |
708 | if (p) |
647 | { |
709 | { |
648 | size_t len = p - file; |
710 | size_t len = p - file; |
… | |
… | |
650 | memcpy (f, file, len); |
712 | memcpy (f, file, len); |
651 | f[len] = '\0'; |
713 | f[len] = '\0'; |
652 | file = f; |
714 | file = f; |
653 | } |
715 | } |
654 | |
716 | |
|
|
717 | bool ret = set_file (file); |
|
|
718 | alpha = 0x8000; |
|
|
719 | if (ret) |
|
|
720 | set_geometry (p ? p + 1 : ""); |
|
|
721 | return ret; |
|
|
722 | } |
|
|
723 | |
|
|
724 | bool |
|
|
725 | rxvt_image::set_file (const char *file) |
|
|
726 | { |
|
|
727 | bool ret = false; |
|
|
728 | |
655 | # ifdef HAVE_PIXBUF |
729 | # ifdef HAVE_PIXBUF |
656 | GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); |
730 | GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); |
657 | if (image) |
731 | if (image) |
658 | { |
732 | { |
659 | if (pixbuf) |
733 | if (pixbuf) |
… | |
… | |
662 | ret = true; |
736 | ret = true; |
663 | } |
737 | } |
664 | # endif |
738 | # endif |
665 | |
739 | |
666 | if (ret) |
740 | if (ret) |
667 | { |
741 | 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 | |
742 | |
676 | return ret; |
743 | return ret; |
677 | } |
744 | } |
678 | |
745 | |
679 | # endif /* BG_IMAGE_FROM_FILE */ |
746 | # endif /* BG_IMAGE_FROM_FILE */ |
… | |
… | |
1091 | bg_flags |= BG_IS_VALID; |
1158 | bg_flags |= BG_IS_VALID; |
1092 | } |
1159 | } |
1093 | # endif |
1160 | # endif |
1094 | |
1161 | |
1095 | # ifdef BG_IMAGE_FROM_FILE |
1162 | # ifdef BG_IMAGE_FROM_FILE |
1096 | if (bg_image.flags & IM_IS_SET) |
1163 | for (vector<rxvt_image>::iterator bg_image = image_vec.begin (); bg_image < image_vec.end (); bg_image++) |
1097 | { |
1164 | { |
1098 | if (render_image (bg_image)) |
1165 | if (render_image (*bg_image)) |
1099 | bg_flags |= BG_IS_VALID; |
1166 | bg_flags |= BG_IS_VALID; |
1100 | } |
1167 | } |
1101 | # endif |
1168 | # endif |
1102 | |
1169 | |
1103 | if (!(bg_flags & BG_IS_VALID)) |
1170 | if (!(bg_flags & BG_IS_VALID)) |
… | |
… | |
1136 | if (!strcmp (filters->filter[i], FilterConvolution)) |
1203 | if (!strcmp (filters->filter[i], FilterConvolution)) |
1137 | bg_flags |= BG_HAS_RENDER_CONV; |
1204 | bg_flags |= BG_HAS_RENDER_CONV; |
1138 | |
1205 | |
1139 | XFree (filters); |
1206 | XFree (filters); |
1140 | } |
1207 | } |
|
|
1208 | #endif |
|
|
1209 | |
|
|
1210 | #ifdef BG_IMAGE_FROM_FILE |
|
|
1211 | if (rs[Rs_backgroundPixmap]) |
|
|
1212 | { |
|
|
1213 | rxvt_image *image = new_image (); |
|
|
1214 | if (!image->set_file_geometry (rs[Rs_backgroundPixmap])) |
|
|
1215 | image_vec.pop_back (); |
|
|
1216 | } |
|
|
1217 | |
|
|
1218 | # ifndef NO_RESOURCES |
|
|
1219 | find_resources ("image", "Image", XrmEnumAllLevels, rxvt_define_image); |
|
|
1220 | vector<rxvt_image>::iterator bg_image = image_vec.begin (); |
|
|
1221 | while (bg_image != image_vec.end ()) |
|
|
1222 | { |
|
|
1223 | if (!(bg_image->flags & IM_IS_SET)) |
|
|
1224 | bg_image = image_vec.erase (bg_image); |
|
|
1225 | else |
|
|
1226 | bg_image++; |
|
|
1227 | } |
|
|
1228 | # endif |
|
|
1229 | |
|
|
1230 | if (image_vec.size () > 0 |
|
|
1231 | && !bg_window_position_sensitive ()) |
|
|
1232 | update_background (); |
1141 | #endif |
1233 | #endif |
1142 | } |
1234 | } |
1143 | |
1235 | |
1144 | #endif /* HAVE_BG_PIXMAP */ |
1236 | #endif /* HAVE_BG_PIXMAP */ |
1145 | |
1237 | |