… | |
… | |
85 | if (bg_flags & BG_IS_TRANSPARENT) |
85 | if (bg_flags & BG_IS_TRANSPARENT) |
86 | return true; |
86 | return true; |
87 | # endif |
87 | # endif |
88 | |
88 | |
89 | # ifdef BG_IMAGE_FROM_FILE |
89 | # ifdef BG_IMAGE_FROM_FILE |
90 | if (bg_image.flags & IM_IS_SET) |
90 | for (vector<rxvt_image>::iterator bg_image = image_vec.begin (); bg_image < image_vec.end (); bg_image++) |
91 | { |
91 | { |
92 | if ((bg_image.flags & IM_IS_SIZE_SENSITIVE) |
92 | if ((bg_image->flags & IM_IS_SIZE_SENSITIVE) |
93 | || bg_image.width () > szHint.width |
93 | || bg_image->width () > szHint.width |
94 | || bg_image.height () > szHint.height) |
94 | || bg_image->height () > szHint.height) |
95 | return true; |
95 | return true; |
96 | } |
96 | } |
97 | # endif |
97 | # endif |
98 | |
98 | |
99 | return false; |
99 | return false; |
… | |
… | |
106 | if (bg_flags & BG_IS_TRANSPARENT) |
106 | if (bg_flags & BG_IS_TRANSPARENT) |
107 | return true; |
107 | return true; |
108 | # endif |
108 | # endif |
109 | |
109 | |
110 | # ifdef BG_IMAGE_FROM_FILE |
110 | # ifdef BG_IMAGE_FROM_FILE |
111 | if (bg_image.flags & IM_IS_SET) |
111 | for (vector<rxvt_image>::iterator bg_image = image_vec.begin (); bg_image < image_vec.end (); bg_image++) |
112 | { |
112 | { |
113 | if (bg_image.flags & IM_ROOT_ALIGN) |
113 | if (bg_image->flags & IM_ROOT_ALIGN) |
114 | return true; |
114 | return true; |
115 | } |
115 | } |
116 | # endif |
116 | # endif |
117 | |
117 | |
118 | return false; |
118 | return false; |
… | |
… | |
145 | |
145 | |
146 | min_it (dst_size, target_size - dst_pos); |
146 | min_it (dst_size, target_size - dst_pos); |
147 | return src_pos; |
147 | return src_pos; |
148 | } |
148 | } |
149 | |
149 | |
|
|
150 | static void |
|
|
151 | parse_style (const char *style, int &x, int &y, unsigned int &w, unsigned int &h, uint8_t &flags) |
|
|
152 | { |
|
|
153 | if (!strcasecmp (style, "tiled")) |
|
|
154 | { |
|
|
155 | flags = IM_TILE; |
|
|
156 | w = h = noScale; |
|
|
157 | x = y = 0; |
|
|
158 | } |
|
|
159 | else if (!strcasecmp (style, "aspect-stretched")) |
|
|
160 | { |
|
|
161 | flags = IM_KEEP_ASPECT; |
|
|
162 | w = h = windowScale; |
|
|
163 | x = y = centerAlign; |
|
|
164 | } |
|
|
165 | else if (!strcasecmp (style, "stretched")) |
|
|
166 | { |
|
|
167 | flags = 0; |
|
|
168 | w = h = windowScale; |
|
|
169 | x = y = centerAlign; |
|
|
170 | } |
|
|
171 | else if (!strcasecmp (style, "centered")) |
|
|
172 | { |
|
|
173 | flags = 0; |
|
|
174 | w = h = noScale; |
|
|
175 | x = y = centerAlign; |
|
|
176 | } |
|
|
177 | else if (!strcasecmp (style, "root-tiled")) |
|
|
178 | { |
|
|
179 | flags = IM_TILE|IM_ROOT_ALIGN; |
|
|
180 | w = h = noScale; |
|
|
181 | x = y = 0; |
|
|
182 | } |
|
|
183 | } |
|
|
184 | |
150 | bool |
185 | bool |
151 | rxvt_image::set_geometry (const char *geom, bool update) |
186 | rxvt_image::set_geometry (const char *geom, bool update) |
152 | { |
187 | { |
153 | bool changed = false; |
188 | bool changed = false; |
154 | int geom_flags = 0; |
189 | int geom_flags = 0; |
155 | int x = h_align; |
190 | int x = h_align; |
156 | int y = v_align; |
191 | int y = v_align; |
157 | unsigned int w = h_scale; |
192 | unsigned int w = h_scale; |
158 | unsigned int h = v_scale; |
193 | unsigned int h = v_scale; |
159 | unsigned long new_flags = 0; |
194 | uint8_t new_flags = 0; |
160 | |
195 | |
161 | if (geom == NULL) |
196 | if (geom == NULL) |
162 | return false; |
197 | return false; |
163 | |
198 | |
164 | if (geom[0]) |
199 | if (geom[0]) |
165 | { |
200 | { |
166 | char **arr = rxvt_strsplit (':', geom); |
201 | char **arr = rxvt_strsplit (':', geom); |
167 | |
202 | |
168 | for (int i = 0; arr[i]; i++) |
203 | for (int i = 0; arr[i]; i++) |
169 | { |
204 | { |
170 | if (!strcasecmp (arr[i], "style=tiled")) |
205 | if (!strncasecmp (arr[i], "style=", 6)) |
171 | { |
206 | { |
172 | new_flags = IM_TILE; |
207 | 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; |
208 | 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 | } |
209 | } |
203 | else if (!strcasecmp (arr[i], "op=tile")) |
210 | else if (!strcasecmp (arr[i], "op=tile")) |
204 | new_flags |= IM_TILE; |
211 | new_flags |= IM_TILE; |
205 | else if (!strcasecmp (arr[i], "op=keep-aspect")) |
212 | else if (!strcasecmp (arr[i], "op=keep-aspect")) |
206 | new_flags |= IM_KEEP_ASPECT; |
213 | new_flags |= IM_KEEP_ASPECT; |
… | |
… | |
527 | |
534 | |
528 | if (need_blend) |
535 | if (need_blend) |
529 | tmp_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, 32); |
536 | tmp_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, 32); |
530 | else |
537 | else |
531 | { |
538 | { |
|
|
539 | // optimise bg pixmap size when tiling, but only if there are no |
|
|
540 | // other pixbufs to render. Otherwise, the bg pixmap size must |
|
|
541 | // be equal to the window size. |
532 | if (image.flags & IM_TILE) |
542 | if ((image.flags & IM_TILE) |
|
|
543 | && image_vec.size () == 1) |
533 | { |
544 | { |
534 | new_pmap_width = min (image_width, target_width); |
545 | new_pmap_width = min (image_width, target_width); |
535 | new_pmap_height = min (image_height, target_height); |
546 | new_pmap_height = min (image_height, target_height); |
536 | } |
547 | } |
537 | |
548 | |
… | |
… | |
603 | |
614 | |
604 | Picture mask = create_xrender_mask (dpy, vt, False, False); |
615 | Picture mask = create_xrender_mask (dpy, vt, False, False); |
605 | |
616 | |
606 | XRenderColor mask_c; |
617 | XRenderColor mask_c; |
607 | |
618 | |
608 | mask_c.alpha = 0x8000; |
619 | mask_c.alpha = gdk_pixbuf_get_has_alpha (image.pixbuf) ? 0xffff : image.alpha; |
609 | mask_c.red = |
620 | mask_c.red = |
610 | mask_c.green = |
621 | mask_c.green = |
611 | mask_c.blue = 0; |
622 | mask_c.blue = 0; |
612 | XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); |
623 | XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); |
613 | |
624 | |
… | |
… | |
632 | |
643 | |
633 | return ret; |
644 | return ret; |
634 | } |
645 | } |
635 | # endif /* HAVE_PIXBUF */ |
646 | # endif /* HAVE_PIXBUF */ |
636 | |
647 | |
|
|
648 | # ifndef NO_RESOURCES |
|
|
649 | static int |
|
|
650 | rxvt_define_image (XrmDatabase *database ecb_unused, |
|
|
651 | XrmBindingList bindings ecb_unused, |
|
|
652 | XrmQuarkList quarks, |
|
|
653 | XrmRepresentation *type ecb_unused, |
|
|
654 | XrmValue *value, |
|
|
655 | XPointer closure ecb_unused) |
|
|
656 | { |
|
|
657 | int size; |
|
|
658 | |
|
|
659 | for (size = 0; quarks[size] != NULLQUARK; size++) |
|
|
660 | ; |
|
|
661 | |
|
|
662 | if (size >= 2) |
|
|
663 | { |
|
|
664 | int id = strtol (XrmQuarkToString (quarks[size-2]), 0, 0); |
|
|
665 | if (id >= 1) |
|
|
666 | GET_R->parse_image (id, XrmQuarkToString (quarks[size-1]), (char *)value->addr); |
|
|
667 | } |
|
|
668 | return False; |
|
|
669 | } |
|
|
670 | |
|
|
671 | void |
|
|
672 | rxvt_term::parse_image (int id, const char *type, const char *arg) |
|
|
673 | { |
|
|
674 | rxvt_image *image; |
|
|
675 | |
|
|
676 | for (image = image_vec.begin (); image < image_vec.end (); image++) |
|
|
677 | if (image->id == id) |
|
|
678 | break; |
|
|
679 | |
|
|
680 | if (image == image_vec.end ()) |
|
|
681 | { |
|
|
682 | image = new_image (); |
|
|
683 | image->id = id; |
|
|
684 | } |
|
|
685 | } |
|
|
686 | # endif |
|
|
687 | |
|
|
688 | rxvt_image::rxvt_image () |
|
|
689 | { |
|
|
690 | id = |
|
|
691 | alpha = |
|
|
692 | flags = |
|
|
693 | h_scale = |
|
|
694 | v_scale = |
|
|
695 | h_align = |
|
|
696 | v_align = 0; |
|
|
697 | |
|
|
698 | # ifdef HAVE_PIXBUF |
|
|
699 | pixbuf.reset (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 && p) |
|
|
723 | set_geometry (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) |
660 | g_object_unref (pixbuf); |
737 | g_object_unref (pixbuf); |
661 | pixbuf = image; |
738 | pixbuf.reset (image); |
662 | ret = true; |
739 | ret = true; |
663 | } |
740 | } |
664 | # endif |
741 | # endif |
665 | |
742 | |
666 | if (ret) |
743 | if (ret) |
667 | { |
744 | { |
|
|
745 | alpha = 0xffff; |
668 | flags = IM_IS_SET | IM_IS_SIZE_SENSITIVE; |
746 | flags = IM_IS_SET | IM_IS_SIZE_SENSITIVE; |
669 | h_scale = v_scale = defaultScale; |
747 | h_scale = v_scale = defaultScale; |
670 | h_align = v_align = defaultAlign; |
748 | h_align = v_align = defaultAlign; |
671 | |
|
|
672 | if (p) |
|
|
673 | set_geometry (p + 1); |
|
|
674 | } |
749 | } |
675 | |
750 | |
676 | return ret; |
751 | return ret; |
677 | } |
752 | } |
678 | |
753 | |
… | |
… | |
1091 | bg_flags |= BG_IS_VALID; |
1166 | bg_flags |= BG_IS_VALID; |
1092 | } |
1167 | } |
1093 | # endif |
1168 | # endif |
1094 | |
1169 | |
1095 | # ifdef BG_IMAGE_FROM_FILE |
1170 | # ifdef BG_IMAGE_FROM_FILE |
1096 | if (bg_image.flags & IM_IS_SET) |
1171 | for (vector<rxvt_image>::iterator bg_image = image_vec.begin (); bg_image < image_vec.end (); bg_image++) |
1097 | { |
1172 | { |
1098 | if (render_image (bg_image)) |
1173 | if (render_image (*bg_image)) |
1099 | bg_flags |= BG_IS_VALID; |
1174 | bg_flags |= BG_IS_VALID; |
1100 | } |
1175 | } |
1101 | # endif |
1176 | # endif |
1102 | |
1177 | |
1103 | if (!(bg_flags & BG_IS_VALID)) |
1178 | if (!(bg_flags & BG_IS_VALID)) |
… | |
… | |
1136 | if (!strcmp (filters->filter[i], FilterConvolution)) |
1211 | if (!strcmp (filters->filter[i], FilterConvolution)) |
1137 | bg_flags |= BG_HAS_RENDER_CONV; |
1212 | bg_flags |= BG_HAS_RENDER_CONV; |
1138 | |
1213 | |
1139 | XFree (filters); |
1214 | XFree (filters); |
1140 | } |
1215 | } |
|
|
1216 | #endif |
|
|
1217 | |
|
|
1218 | #ifdef BG_IMAGE_FROM_FILE |
|
|
1219 | if (rs[Rs_backgroundPixmap]) |
|
|
1220 | { |
|
|
1221 | rxvt_image *image = new_image (); |
|
|
1222 | if (!image->set_file_geometry (rs[Rs_backgroundPixmap])) |
|
|
1223 | image_vec.pop_back (); |
|
|
1224 | } |
|
|
1225 | |
|
|
1226 | # ifndef NO_RESOURCES |
|
|
1227 | find_resources ("image", "Image", XrmEnumAllLevels, rxvt_define_image); |
|
|
1228 | vector<rxvt_image>::iterator bg_image = image_vec.begin (); |
|
|
1229 | while (bg_image != image_vec.end ()) |
|
|
1230 | { |
|
|
1231 | if (!(bg_image->flags & IM_IS_SET)) |
|
|
1232 | bg_image = image_vec.erase (bg_image); |
|
|
1233 | else |
|
|
1234 | bg_image++; |
|
|
1235 | } |
|
|
1236 | # endif |
|
|
1237 | |
|
|
1238 | if (image_vec.size () > 0 |
|
|
1239 | && !bg_window_position_sensitive ()) |
|
|
1240 | update_background (); |
1141 | #endif |
1241 | #endif |
1142 | } |
1242 | } |
1143 | |
1243 | |
1144 | #endif /* HAVE_BG_PIXMAP */ |
1244 | #endif /* HAVE_BG_PIXMAP */ |
1145 | |
1245 | |