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.226 by sf-exg, Thu May 31 05:53:46 2012 UTC vs.
Revision 1.235 by sf-exg, Thu Jun 7 09:34:51 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{
484 return false; 483 return false;
485 484
486 bool need_blend = bg_flags & BG_IS_VALID; 485 bool need_blend = bg_flags & BG_IS_VALID;
487 486
488 if (need_blend 487 if (need_blend
489 && !(bg_flags & BG_HAS_RENDER)) 488 && !(display->flags & DISPLAY_HAS_RENDER))
490 return false; 489 return false;
491 490
492 GdkPixbuf *result; 491 GdkPixbuf *result;
493 492
494 int image_width = gdk_pixbuf_get_width (pixbuf); 493 int image_width = gdk_pixbuf_get_width (pixbuf);
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
679void
680rxvt_term::parse_image (int id, const char *type, const char *arg)
681{
682 if (image_vec.size () < id + 1)
683 image_vec.resize (id + 1);
684
685 rxvt_image *image = &image_vec[id];
686}
687# endif
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);
837bool 799bool
838rxvt_term::blur_pixmap (Pixmap pixmap, int width, int height, bool argb, int h_blurRadius, int v_blurRadius) 800rxvt_term::blur_pixmap (Pixmap pixmap, int width, int height, bool argb, int h_blurRadius, int v_blurRadius)
839{ 801{
840 bool ret = false; 802 bool ret = false;
841#if XRENDER 803#if XRENDER
842 if (!(bg_flags & BG_HAS_RENDER_CONV)) 804 if (!(display->flags & DISPLAY_HAS_RENDER_CONV))
843 return false; 805 return false;
844 806
845 int size = max (h_blurRadius, v_blurRadius) * 2 + 1; 807 int size = max (h_blurRadius, v_blurRadius) * 2 + 1;
846 double *kernel = (double *)malloc (size * sizeof (double)); 808 double *kernel = (double *)malloc (size * sizeof (double));
847 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); 809 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed));
931 ret = true; 893 ret = true;
932 XFreeGC (dpy, gc); 894 XFreeGC (dpy, gc);
933 } 895 }
934 } 896 }
935# if XRENDER 897# if XRENDER
936 else if (bg_flags & BG_HAS_RENDER) 898 else if (display->flags & DISPLAY_HAS_RENDER)
937 { 899 {
938 if (shade <= 100) 900 if (shade <= 100)
939 { 901 {
940 c.r = c.r * shade / 100; 902 c.r = c.r * shade / 100;
941 c.g = c.g * shade / 100; 903 c.g = c.g * shade / 100;
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 */
1004bool 966bool
1005rxvt_term::make_transparency_pixmap () 967rxvt_term::render_root_image ()
1006{ 968{
1007 bool ret = false; 969 bool ret = false;
1008 970
1009 /* root dimensions may change from call to call - but Display structure should 971 /* root dimensions may change from call to call - but Display structure should
1010 * be always up-to-date, so let's use it : 972 * be always up-to-date, so let's use it :
1046 Pixmap recoded_root_pmap = root_pixmap; 1008 Pixmap recoded_root_pmap = root_pixmap;
1047 1009
1048 if (root_pixmap != None && root_depth != depth) 1010 if (root_pixmap != None && root_depth != depth)
1049 { 1011 {
1050#if XRENDER 1012#if XRENDER
1051 if (bg_flags & BG_HAS_RENDER) 1013 if (display->flags & DISPLAY_HAS_RENDER)
1052 { 1014 {
1053 recoded_root_pmap = XCreatePixmap (dpy, vt, root_pmap_width, root_pmap_height, depth); 1015 recoded_root_pmap = XCreatePixmap (dpy, vt, root_pmap_width, root_pmap_height, depth);
1054 1016
1055 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen)); 1017 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen));
1056 Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, 0); 1018 Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, 0);
1097 XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height); 1059 XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height);
1098 ret = true; 1060 ret = true;
1099 bool need_blur = root_effects.need_blur (); 1061 bool need_blur = root_effects.need_blur ();
1100 bool need_tint = root_effects.need_tint (); 1062 bool need_tint = root_effects.need_tint ();
1101 1063
1102 if (!(bg_flags & BG_CLIENT_RENDER))
1103 {
1104 if (need_blur) 1064 if (need_blur)
1065 {
1066 if (blur_pixmap (bg_pixmap, window_width, window_height, false,
1067 root_effects.h_blurRadius, root_effects.v_blurRadius))
1068 need_blur = false;
1069 }
1070 if (need_tint)
1071 {
1072 if (tint_pixmap (bg_pixmap, window_width, window_height, false,
1073 root_effects.tint, root_effects.tint_set, root_effects.shade))
1074 need_tint = false;
1075 }
1076 if (need_tint)
1077 {
1078 XImage *ximage = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap);
1079 if (ximage)
1105 { 1080 {
1106 if (blur_pixmap (bg_pixmap, window_width, window_height, false, 1081 /* our own client-side tinting */
1107 root_effects.h_blurRadius, root_effects.v_blurRadius)) 1082 tint_ximage (ximage, root_effects.tint, root_effects.tint_set, root_effects.shade);
1108 need_blur = false; 1083
1084 XPutImage (dpy, bg_pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height);
1085 XDestroyImage (ximage);
1109 } 1086 }
1110 if (need_tint)
1111 {
1112 if (tint_pixmap (bg_pixmap, window_width, window_height, false,
1113 root_effects.tint, root_effects.tint_set, root_effects.shade))
1114 need_tint = false;
1115 } 1087 }
1116 if (need_tint)
1117 {
1118 XImage *ximage = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap);
1119 if (ximage)
1120 {
1121 /* our own client-side tinting */
1122 tint_ximage (ximage, root_effects.tint, root_effects.tint_set, root_effects.shade);
1123
1124 XPutImage (dpy, bg_pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height);
1125 XDestroyImage (ximage);
1126 }
1127 }
1128 } /* server side rendering completed */
1129 1088
1130 XFreeGC (dpy, gc); 1089 XFreeGC (dpy, gc);
1131 } 1090 }
1132 1091
1133 if (recoded_root_pmap != root_pixmap) 1092 if (recoded_root_pmap != root_pixmap)
1137} 1096}
1138 1097
1139void 1098void
1140rxvt_term::bg_set_root_pixmap () 1099rxvt_term::bg_set_root_pixmap ()
1141{ 1100{
1142 Pixmap new_root_pixmap = get_pixmap_property (xa[XA_XROOTPMAP_ID]); 1101 Pixmap new_root_pixmap = display->get_pixmap_property (xa[XA_XROOTPMAP_ID]);
1143 if (new_root_pixmap == None) 1102 if (new_root_pixmap == None)
1144 new_root_pixmap = get_pixmap_property (xa[XA_ESETROOT_PMAP_ID]); 1103 new_root_pixmap = display->get_pixmap_property (xa[XA_ESETROOT_PMAP_ID]);
1145 1104
1146 root_pixmap = new_root_pixmap; 1105 root_pixmap = new_root_pixmap;
1147} 1106}
1148# endif /* ENABLE_TRANSPARENCY */ 1107# endif /* ENABLE_TRANSPARENCY */
1149 1108
1150bool 1109void
1151rxvt_term::bg_render () 1110rxvt_term::bg_render ()
1152{ 1111{
1112 if (bg_flags & BG_INHIBIT_RENDER)
1113 return;
1114
1153 bg_invalidate (); 1115 bg_invalidate ();
1154# ifdef ENABLE_TRANSPARENCY 1116# if ENABLE_TRANSPARENCY
1155 if (bg_flags & BG_IS_TRANSPARENT) 1117 if (bg_flags & BG_IS_TRANSPARENT)
1156 { 1118 {
1157 /* we need to re-generate transparency pixmap in that case ! */ 1119 /* we need to re-generate transparency pixmap in that case ! */
1158 if (make_transparency_pixmap ()) 1120 if (render_root_image ())
1159 bg_flags |= BG_IS_VALID; 1121 bg_flags |= BG_IS_VALID;
1160 } 1122 }
1161# endif 1123# endif
1162 1124
1163# ifdef BG_IMAGE_FROM_FILE 1125# if BG_IMAGE_FROM_FILE
1164 for (vector<rxvt_image>::iterator bg_image = image_vec.begin (); bg_image < image_vec.end (); bg_image++) 1126 if (fimage.flags & IM_IS_SET)
1165 { 1127 {
1166 if (render_image (*bg_image)) 1128 if (render_image (fimage))
1167 bg_flags |= BG_IS_VALID; 1129 bg_flags |= BG_IS_VALID;
1168 } 1130 }
1169# endif 1131# endif
1170 1132
1171 if (!(bg_flags & BG_IS_VALID)) 1133 if (!(bg_flags & BG_IS_VALID))
1179 1141
1180 scr_recolour (false); 1142 scr_recolour (false);
1181 bg_flags |= BG_NEEDS_REFRESH; 1143 bg_flags |= BG_NEEDS_REFRESH;
1182 1144
1183 bg_valid_since = ev::now (); 1145 bg_valid_since = ev::now ();
1184
1185 return true;
1186} 1146}
1187 1147
1188void 1148void
1189rxvt_term::bg_init () 1149rxvt_term::bg_init ()
1190{ 1150{
1191 bg_flags &= ~(BG_HAS_RENDER | BG_HAS_RENDER_CONV);
1192#if XRENDER
1193 int major, minor;
1194 if (XRenderQueryVersion (dpy, &major, &minor))
1195 bg_flags |= BG_HAS_RENDER;
1196 XFilters *filters = XRenderQueryFilters (dpy, vt);
1197 if (filters)
1198 {
1199 for (int i = 0; i < filters->nfilter; i++)
1200 if (!strcmp (filters->filter[i], FilterConvolution))
1201 bg_flags |= BG_HAS_RENDER_CONV;
1202
1203 XFree (filters);
1204 }
1205#endif
1206
1207#ifdef BG_IMAGE_FROM_FILE 1151#if BG_IMAGE_FROM_FILE
1208 if (rs[Rs_backgroundPixmap]) 1152 if (rs[Rs_backgroundPixmap])
1209 { 1153 {
1210 rxvt_image *image = new_image ();
1211 if (!image->set_file_geometry (rs[Rs_backgroundPixmap])) 1154 if (fimage.set_file_geometry (rs[Rs_backgroundPixmap])
1212 image_vec.pop_back ();
1213 }
1214
1215# ifndef NO_RESOURCES
1216 find_resources ("image", "Image", XrmEnumAllLevels, rxvt_define_image);
1217 vector<rxvt_image>::iterator bg_image = image_vec.begin ();
1218 while (bg_image != image_vec.end ())
1219 {
1220 if (!(bg_image->flags & IM_IS_SET))
1221 bg_image = image_vec.erase (bg_image);
1222 else
1223 {
1224 if (bg_image->is_size_sensitive ())
1225 bg_image->flags |= IM_IS_SIZE_SENSITIVE;
1226
1227 bg_image++;
1228 }
1229 }
1230# endif
1231
1232 if (image_vec.size () > 0
1233 && !bg_window_position_sensitive ()) 1155 && !bg_window_position_sensitive ())
1234 update_background (); 1156 update_background ();
1157 }
1235#endif 1158#endif
1236} 1159}
1237 1160
1238/* based on code from aterm-0.4.2 */ 1161/* based on code from aterm-0.4.2 */
1239 1162

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines