ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/background.C
(Generate patch)

Comparing rxvt-unicode/src/background.C (file contents):
Revision 1.230 by sf-exg, Sun Jun 3 15:50:22 2012 UTC vs.
Revision 1.234 by sf-exg, Thu Jun 7 09:21:18 2012 UTC

58# endif 58# endif
59 59
60void 60void
61rxvt_term::bg_destroy () 61rxvt_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
86bool 85bool
87rxvt_term::bg_window_size_sensitive () 86rxvt_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
107bool 106bool
108rxvt_term::bg_window_position_sensitive () 107rxvt_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
127static inline int 126static inline int
128make_align_position (int align, int window_size, int image_size) 127make_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
353bool 352bool
354rxvt_term::pixbuf_to_pixmap (GdkPixbuf *pixbuf, Pixmap pixmap, GC gc, 353rxvt_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
657static int
658rxvt_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
680void
681rxvt_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
689rxvt_image::rxvt_image () 651rxvt_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
703bool 665bool
727bool 689bool
728rxvt_image::set_file (const char *file) 690rxvt_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
1136void 1098void
1137rxvt_term::bg_set_root_pixmap () 1099rxvt_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
1147bool 1109void
1148rxvt_term::bg_render () 1110rxvt_term::bg_render ()
1149{ 1111{
1150 bg_invalidate (); 1112 bg_invalidate ();
1151# ifdef ENABLE_TRANSPARENCY 1113# if ENABLE_TRANSPARENCY
1152 if (bg_flags & BG_IS_TRANSPARENT) 1114 if (bg_flags & BG_IS_TRANSPARENT)
1153 { 1115 {
1154 /* we need to re-generate transparency pixmap in that case ! */ 1116 /* we need to re-generate transparency pixmap in that case ! */
1155 if (render_root_image ()) 1117 if (render_root_image ())
1156 bg_flags |= BG_IS_VALID; 1118 bg_flags |= BG_IS_VALID;
1157 } 1119 }
1158# endif 1120# endif
1159 1121
1160# ifdef BG_IMAGE_FROM_FILE 1122# if BG_IMAGE_FROM_FILE
1161 for (vector<rxvt_image>::iterator bg_image = image_vec.begin (); bg_image < image_vec.end (); bg_image++) 1123 if (fimage.flags & IM_IS_SET)
1162 { 1124 {
1163 if (render_image (*bg_image)) 1125 if (render_image (fimage))
1164 bg_flags |= BG_IS_VALID; 1126 bg_flags |= BG_IS_VALID;
1165 } 1127 }
1166# endif 1128# endif
1167 1129
1168 if (!(bg_flags & BG_IS_VALID)) 1130 if (!(bg_flags & BG_IS_VALID))
1176 1138
1177 scr_recolour (false); 1139 scr_recolour (false);
1178 bg_flags |= BG_NEEDS_REFRESH; 1140 bg_flags |= BG_NEEDS_REFRESH;
1179 1141
1180 bg_valid_since = ev::now (); 1142 bg_valid_since = ev::now ();
1181
1182 return true;
1183} 1143}
1184 1144
1185void 1145void
1186rxvt_term::bg_init () 1146rxvt_term::bg_init ()
1187{ 1147{
1188#ifdef BG_IMAGE_FROM_FILE 1148#if BG_IMAGE_FROM_FILE
1189 if (rs[Rs_backgroundPixmap]) 1149 if (rs[Rs_backgroundPixmap])
1190 { 1150 {
1191 rxvt_image *image = new_image ();
1192 if (!image->set_file_geometry (rs[Rs_backgroundPixmap])) 1151 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 ()) 1152 && !bg_window_position_sensitive ())
1216 update_background (); 1153 update_background ();
1154 }
1217#endif 1155#endif
1218} 1156}
1219 1157
1220/* based on code from aterm-0.4.2 */ 1158/* based on code from aterm-0.4.2 */
1221 1159

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines