… | |
… | |
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++) |
|
|
65 | bg_image->destroy (); |
64 | fimage.destroy (); |
66 | # endif |
65 | # endif |
67 | |
66 | |
68 | if (bg_pixmap) |
67 | if (bg_pixmap) |
69 | XFreePixmap (dpy, bg_pixmap); |
68 | XFreePixmap (dpy, bg_pixmap); |
70 | } |
69 | } |
… | |
… | |
84 | } |
83 | } |
85 | |
84 | |
86 | bool |
85 | bool |
87 | rxvt_term::bg_window_size_sensitive () |
86 | rxvt_term::bg_window_size_sensitive () |
88 | { |
87 | { |
89 | # ifdef ENABLE_TRANSPARENCY |
88 | # if ENABLE_TRANSPARENCY |
90 | if (bg_flags & BG_IS_TRANSPARENT) |
89 | if (bg_flags & BG_IS_TRANSPARENT) |
91 | return true; |
90 | return true; |
92 | # endif |
91 | # endif |
93 | |
92 | |
94 | # ifdef BG_IMAGE_FROM_FILE |
93 | # if BG_IMAGE_FROM_FILE |
95 | for (vector<rxvt_image>::iterator bg_image = image_vec.begin (); bg_image < image_vec.end (); bg_image++) |
94 | if (fimage.flags & IM_IS_SET) |
96 | { |
95 | { |
97 | if ((bg_image->flags & IM_IS_SIZE_SENSITIVE) |
96 | if ((fimage.flags & IM_IS_SIZE_SENSITIVE) |
98 | || bg_image->width () > szHint.width |
97 | || fimage.width () > szHint.width |
99 | || bg_image->height () > szHint.height) |
98 | || fimage.height () > szHint.height) |
100 | return true; |
99 | return true; |
101 | } |
100 | } |
102 | # endif |
101 | # endif |
103 | |
102 | |
104 | return false; |
103 | return false; |
105 | } |
104 | } |
106 | |
105 | |
107 | bool |
106 | bool |
108 | rxvt_term::bg_window_position_sensitive () |
107 | rxvt_term::bg_window_position_sensitive () |
109 | { |
108 | { |
110 | # ifdef ENABLE_TRANSPARENCY |
109 | # if ENABLE_TRANSPARENCY |
111 | if (bg_flags & BG_IS_TRANSPARENT) |
110 | if (bg_flags & BG_IS_TRANSPARENT) |
112 | return true; |
111 | return true; |
113 | # endif |
112 | # endif |
114 | |
113 | |
115 | # ifdef BG_IMAGE_FROM_FILE |
114 | # if BG_IMAGE_FROM_FILE |
116 | for (vector<rxvt_image>::iterator bg_image = image_vec.begin (); bg_image < image_vec.end (); bg_image++) |
115 | if (fimage.flags & IM_IS_SET) |
117 | { |
116 | { |
118 | if (bg_image->flags & IM_ROOT_ALIGN) |
117 | if (fimage.flags & IM_ROOT_ALIGN) |
119 | return true; |
118 | return true; |
120 | } |
119 | } |
121 | # endif |
120 | # endif |
122 | |
121 | |
123 | return false; |
122 | return false; |
124 | } |
123 | } |
125 | |
124 | |
126 | # ifdef BG_IMAGE_FROM_FILE |
125 | # if BG_IMAGE_FROM_FILE |
127 | static inline int |
126 | static inline int |
128 | make_align_position (int align, int window_size, int image_size) |
127 | make_align_position (int align, int window_size, int image_size) |
129 | { |
128 | { |
130 | if (align >= 0 && align <= 100) |
129 | if (align >= 0 && align <= 100) |
131 | return lerp (0, window_size - image_size, align); |
130 | return lerp (0, window_size - image_size, align); |
… | |
… | |
347 | x = make_align_position (image.h_align, target_width, w); |
346 | x = make_align_position (image.h_align, target_width, w); |
348 | y = make_align_position (image.v_align, target_height, h); |
347 | y = make_align_position (image.v_align, target_height, h); |
349 | } |
348 | } |
350 | } |
349 | } |
351 | |
350 | |
352 | # ifdef HAVE_PIXBUF |
351 | # if HAVE_PIXBUF |
353 | bool |
352 | bool |
354 | rxvt_term::pixbuf_to_pixmap (GdkPixbuf *pixbuf, Pixmap pixmap, GC gc, |
353 | rxvt_term::pixbuf_to_pixmap (GdkPixbuf *pixbuf, Pixmap pixmap, GC gc, |
355 | int src_x, int src_y, int dst_x, int dst_y, |
354 | int src_x, int src_y, int dst_x, int dst_y, |
356 | unsigned int width, unsigned int height, bool argb) |
355 | unsigned int width, unsigned int height, bool argb) |
357 | { |
356 | { |
… | |
… | |
537 | |
536 | |
538 | if (need_blend) |
537 | if (need_blend) |
539 | tmp_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, 32); |
538 | tmp_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, 32); |
540 | else |
539 | else |
541 | { |
540 | { |
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. |
|
|
545 | if ((image.flags & IM_TILE) |
541 | if (image.flags & IM_TILE) |
546 | && image_vec.size () == 1) |
|
|
547 | { |
542 | { |
548 | new_pmap_width = min (image_width, target_width); |
543 | new_pmap_width = min (image_width, target_width); |
549 | new_pmap_height = min (image_height, target_height); |
544 | new_pmap_height = min (image_height, target_height); |
550 | } |
545 | } |
551 | |
546 | |
… | |
… | |
650 | XFreePixmap (dpy, tmp_pixmap); |
645 | XFreePixmap (dpy, tmp_pixmap); |
651 | |
646 | |
652 | return ret; |
647 | return ret; |
653 | } |
648 | } |
654 | # endif /* HAVE_PIXBUF */ |
649 | # endif /* HAVE_PIXBUF */ |
655 | |
|
|
656 | # ifndef NO_RESOURCES |
|
|
657 | static int |
|
|
658 | rxvt_define_image (XrmDatabase *database ecb_unused, |
|
|
659 | XrmBindingList bindings ecb_unused, |
|
|
660 | XrmQuarkList quarks, |
|
|
661 | XrmRepresentation *type ecb_unused, |
|
|
662 | XrmValue *value, |
|
|
663 | XPointer closure ecb_unused) |
|
|
664 | { |
|
|
665 | int size; |
|
|
666 | |
|
|
667 | for (size = 0; quarks[size] != NULLQUARK; size++) |
|
|
668 | ; |
|
|
669 | |
|
|
670 | if (size >= 2) |
|
|
671 | { |
|
|
672 | int id = strtol (XrmQuarkToString (quarks[size-2]), 0, 0); |
|
|
673 | if (id >= 1) |
|
|
674 | GET_R->parse_image (id, XrmQuarkToString (quarks[size-1]), (char *)value->addr); |
|
|
675 | } |
|
|
676 | return False; |
|
|
677 | } |
|
|
678 | # endif |
|
|
679 | |
|
|
680 | void |
|
|
681 | rxvt_term::parse_image (int id, const char *type, const char *arg) |
|
|
682 | { |
|
|
683 | if (image_vec.size () < id + 1) |
|
|
684 | image_vec.resize (id + 1); |
|
|
685 | |
|
|
686 | rxvt_image *image = &image_vec[id]; |
|
|
687 | } |
|
|
688 | |
650 | |
689 | rxvt_image::rxvt_image () |
651 | rxvt_image::rxvt_image () |
690 | { |
652 | { |
691 | alpha = 0xffff; |
653 | alpha = 0xffff; |
692 | flags = 0; |
654 | flags = 0; |
693 | h_scale = |
655 | h_scale = |
694 | v_scale = defaultScale; |
656 | v_scale = defaultScale; |
695 | h_align = |
657 | h_align = |
696 | v_align = defaultAlign; |
658 | v_align = defaultAlign; |
697 | |
659 | |
698 | # ifdef HAVE_PIXBUF |
660 | # if HAVE_PIXBUF |
699 | pixbuf = 0; |
661 | pixbuf = 0; |
700 | # endif |
662 | # endif |
701 | } |
663 | } |
702 | |
664 | |
703 | bool |
665 | bool |
… | |
… | |
727 | bool |
689 | bool |
728 | rxvt_image::set_file (const char *file) |
690 | rxvt_image::set_file (const char *file) |
729 | { |
691 | { |
730 | bool ret = false; |
692 | bool ret = false; |
731 | |
693 | |
732 | # ifdef HAVE_PIXBUF |
694 | # if HAVE_PIXBUF |
733 | GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); |
695 | GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); |
734 | if (image) |
696 | if (image) |
735 | { |
697 | { |
736 | if (pixbuf) |
698 | if (pixbuf) |
737 | g_object_unref (pixbuf); |
699 | g_object_unref (pixbuf); |
… | |
… | |
993 | # endif |
955 | # endif |
994 | |
956 | |
995 | return ret; |
957 | return ret; |
996 | } |
958 | } |
997 | |
959 | |
998 | # ifdef ENABLE_TRANSPARENCY |
960 | # if ENABLE_TRANSPARENCY |
999 | /* |
961 | /* |
1000 | * Builds a pixmap of the same size as the terminal window that contains |
962 | * 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 |
963 | * the tiled portion of the root pixmap that is supposed to be covered by |
1002 | * our window. |
964 | * our window. |
1003 | */ |
965 | */ |
… | |
… | |
1134 | } |
1096 | } |
1135 | |
1097 | |
1136 | void |
1098 | void |
1137 | rxvt_term::bg_set_root_pixmap () |
1099 | rxvt_term::bg_set_root_pixmap () |
1138 | { |
1100 | { |
1139 | Pixmap new_root_pixmap = get_pixmap_property (xa[XA_XROOTPMAP_ID]); |
1101 | Pixmap new_root_pixmap = display->get_pixmap_property (xa[XA_XROOTPMAP_ID]); |
1140 | if (new_root_pixmap == None) |
1102 | if (new_root_pixmap == None) |
1141 | new_root_pixmap = get_pixmap_property (xa[XA_ESETROOT_PMAP_ID]); |
1103 | new_root_pixmap = display->get_pixmap_property (xa[XA_ESETROOT_PMAP_ID]); |
1142 | |
1104 | |
1143 | root_pixmap = new_root_pixmap; |
1105 | root_pixmap = new_root_pixmap; |
1144 | } |
1106 | } |
1145 | # endif /* ENABLE_TRANSPARENCY */ |
1107 | # endif /* ENABLE_TRANSPARENCY */ |
1146 | |
1108 | |
1147 | bool |
1109 | void |
1148 | rxvt_term::bg_render () |
1110 | rxvt_term::bg_render () |
1149 | { |
1111 | { |
|
|
1112 | if (bg_flags & BG_INHIBIT_RENDER) |
|
|
1113 | return; |
|
|
1114 | |
1150 | bg_invalidate (); |
1115 | bg_invalidate (); |
1151 | # ifdef ENABLE_TRANSPARENCY |
1116 | # if ENABLE_TRANSPARENCY |
1152 | if (bg_flags & BG_IS_TRANSPARENT) |
1117 | if (bg_flags & BG_IS_TRANSPARENT) |
1153 | { |
1118 | { |
1154 | /* we need to re-generate transparency pixmap in that case ! */ |
1119 | /* we need to re-generate transparency pixmap in that case ! */ |
1155 | if (render_root_image ()) |
1120 | if (render_root_image ()) |
1156 | bg_flags |= BG_IS_VALID; |
1121 | bg_flags |= BG_IS_VALID; |
1157 | } |
1122 | } |
1158 | # endif |
1123 | # endif |
1159 | |
1124 | |
1160 | # ifdef BG_IMAGE_FROM_FILE |
1125 | # if BG_IMAGE_FROM_FILE |
1161 | for (vector<rxvt_image>::iterator bg_image = image_vec.begin (); bg_image < image_vec.end (); bg_image++) |
1126 | if (fimage.flags & IM_IS_SET) |
1162 | { |
1127 | { |
1163 | if (render_image (*bg_image)) |
1128 | if (render_image (fimage)) |
1164 | bg_flags |= BG_IS_VALID; |
1129 | bg_flags |= BG_IS_VALID; |
1165 | } |
1130 | } |
1166 | # endif |
1131 | # endif |
1167 | |
1132 | |
1168 | if (!(bg_flags & BG_IS_VALID)) |
1133 | if (!(bg_flags & BG_IS_VALID)) |
… | |
… | |
1176 | |
1141 | |
1177 | scr_recolour (false); |
1142 | scr_recolour (false); |
1178 | bg_flags |= BG_NEEDS_REFRESH; |
1143 | bg_flags |= BG_NEEDS_REFRESH; |
1179 | |
1144 | |
1180 | bg_valid_since = ev::now (); |
1145 | bg_valid_since = ev::now (); |
1181 | |
|
|
1182 | return true; |
|
|
1183 | } |
1146 | } |
1184 | |
1147 | |
1185 | void |
1148 | void |
1186 | rxvt_term::bg_init () |
1149 | rxvt_term::bg_init () |
1187 | { |
1150 | { |
1188 | #ifdef BG_IMAGE_FROM_FILE |
1151 | #if BG_IMAGE_FROM_FILE |
1189 | if (rs[Rs_backgroundPixmap]) |
1152 | if (rs[Rs_backgroundPixmap]) |
1190 | { |
1153 | { |
1191 | rxvt_image *image = new_image (); |
|
|
1192 | if (!image->set_file_geometry (rs[Rs_backgroundPixmap])) |
1154 | if (fimage.set_file_geometry (rs[Rs_backgroundPixmap]) |
1193 | image_vec.pop_back (); |
|
|
1194 | } |
|
|
1195 | |
|
|
1196 | # ifndef NO_RESOURCES |
|
|
1197 | find_resources ("image", "Image", XrmEnumAllLevels, rxvt_define_image); |
|
|
1198 | # endif |
|
|
1199 | |
|
|
1200 | vector<rxvt_image>::iterator bg_image = image_vec.begin (); |
|
|
1201 | while (bg_image != image_vec.end ()) |
|
|
1202 | { |
|
|
1203 | if (!(bg_image->flags & IM_IS_SET)) |
|
|
1204 | bg_image = image_vec.erase (bg_image); |
|
|
1205 | else |
|
|
1206 | { |
|
|
1207 | if (bg_image->is_size_sensitive ()) |
|
|
1208 | bg_image->flags |= IM_IS_SIZE_SENSITIVE; |
|
|
1209 | |
|
|
1210 | bg_image++; |
|
|
1211 | } |
|
|
1212 | } |
|
|
1213 | |
|
|
1214 | if (image_vec.size () > 0 |
|
|
1215 | && !bg_window_position_sensitive ()) |
1155 | && !bg_window_position_sensitive ()) |
1216 | update_background (); |
1156 | update_background (); |
|
|
1157 | } |
1217 | #endif |
1158 | #endif |
1218 | } |
1159 | } |
1219 | |
1160 | |
1220 | /* based on code from aterm-0.4.2 */ |
1161 | /* based on code from aterm-0.4.2 */ |
1221 | |
1162 | |