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.48 by sf-exg, Tue Aug 31 14:12:20 2010 UTC vs.
Revision 1.55 by sf-exg, Thu Sep 2 15:48:10 2010 UTC

52 * adjustment and may optionally be followed by a colon and one or more 52 * adjustment and may optionally be followed by a colon and one or more
53 * colon-delimited pixmap operations. 53 * colon-delimited pixmap operations.
54 * The following table shows the valid geometry strings and their 54 * The following table shows the valid geometry strings and their
55 * effects on the background image : 55 * effects on the background image :
56 * 56 *
57 * WxH+X+Y Set scaling to W% by H%, and position to X% by Y%. 57 * WxH+X+Y Set scaling to W% by H%, and position to X% by Y%.
58 * W and H are percentages of the terminal window size. 58 * W and H are percentages of the terminal window size.
59 * X and Y are also percentages; e.g., +50+50 centers 59 * X and Y are also percentages; e.g., +50+50 centers
60 * the image in the window. 60 * the image in the window.
61 * WxH+X Assumes Y == X 61 * WxH+X Assumes Y == X
62 * WxH Assumes Y == X == 50 (centers the image) 62 * WxH Assumes Y == X == 50 (centers the image)
63 * W+X+Y Assumes H == W 63 * W+X+Y Assumes H == W
64 * W+X Assumes H == W and Y == X 64 * W+X Assumes H == W and Y == X
65 * W Assumes H == W and Y == X == 50 65 * W Assumes H == W and Y == X == 50
66 * 66 *
67 * Adjusting position only : 67 * Adjusting position only :
68 * =+X+Y Set position to X% by Y% (absolute). 68 * =+X+Y Set position to X% by Y% (absolute).
69 * =+X Set position to X% by X%. 69 * =+X Set position to X% by X%.
70 * +X+Y Adjust position horizontally X% and vertically Y% 70 * +X+Y Adjust position horizontally X% and vertically Y%
71 * from current position (relative). 71 * from current position (relative).
72 * +X Adjust position horizontally X% and vertically X% 72 * +X Adjust position horizontally X% and vertically X%
73 * from current position. 73 * from current position.
74 * 74 *
75 * Adjusting scale only : 75 * Adjusting scale only :
76 * Wx0 Multiply horizontal scaling factor by W% 76 * Wx0 Multiply horizontal scaling factor by W%
77 * 0xH Multiply vertical scaling factor by H% 77 * 0xH Multiply vertical scaling factor by H%
78 * 0x0 No scaling (show image at normal size). 78 * 0x0 No scaling (show image at normal size).
79 * 79 *
80 * Pixmap Operations : (should be prepended by a colon) 80 * Pixmap Operations : (should be prepended by a colon)
81 * tile Tile image. Scaling/position modifiers above will affect 81 * tile Tile image. Scaling/position modifiers above will affect
82 * the tile size and origin. 82 * the tile size and origin.
83 * propscale When scaling, scale proportionally. That is, maintain the 83 * propscale When scaling, scale proportionally. That is, maintain the
84 * proper aspect ratio for the image. Any portion of the 84 * proper aspect ratio for the image. Any portion of the
85 * background not covered by the image is filled with the 85 * background not covered by the image is filled with the
86 * current background color. 86 * current background color.
87 * hscale Scale horizontally, tile vertically ? 87 * hscale Scale horizontally, tile vertically ?
88 * vscale Tile horizontally, scale vertically ? 88 * vscale Tile horizontally, scale vertically ?
96 // this is basically redundant as bgPixmap_t is only used in 96 // this is basically redundant as bgPixmap_t is only used in
97 // zero_initialised-derived structs 97 // zero_initialised-derived structs
98#ifdef HAVE_AFTERIMAGE 98#ifdef HAVE_AFTERIMAGE
99 original_asim = NULL; 99 original_asim = NULL;
100#endif 100#endif
101#ifdef HAVE_PIXBUF
102 pixbuf = NULL;
103#endif
101#ifdef BG_IMAGE_FROM_FILE 104#ifdef BG_IMAGE_FROM_FILE
105 have_image = false;
102 h_scale = v_scale = 0; 106 h_scale = v_scale = 0;
103 h_align = v_align = 0; 107 h_align = v_align = 0;
104#endif 108#endif
105 flags = 0; 109 flags = 0;
106 pixmap = None; 110 pixmap = None;
114#ifdef HAVE_AFTERIMAGE 118#ifdef HAVE_AFTERIMAGE
115 if (original_asim) 119 if (original_asim)
116 safe_asimage_destroy (original_asim); 120 safe_asimage_destroy (original_asim);
117#endif 121#endif
118 122
123#ifdef HAVE_PIXBUF
124 if (pixbuf)
125 g_object_unref (pixbuf);
126#endif
127
119 if (pixmap && target) 128 if (pixmap && target)
120 XFreePixmap (target->dpy, pixmap); 129 XFreePixmap (target->dpy, pixmap);
121} 130}
122 131
123bool 132bool
127 if (flags & isTransparent) 136 if (flags & isTransparent)
128 return true; 137 return true;
129# endif 138# endif
130 139
131# ifdef BG_IMAGE_FROM_FILE 140# ifdef BG_IMAGE_FROM_FILE
132# ifdef HAVE_AFTERIMAGE 141 if (have_image)
133 if (original_asim)
134# endif
135 { 142 {
136 if (h_scale != 0 || v_scale != 0 143 if (h_scale != 0 || v_scale != 0
137 || h_align != 0 || v_align != 0) 144 || h_align != 0 || v_align != 0)
138 return true; 145 return true;
139 } 146 }
149 if (flags & isTransparent) 156 if (flags & isTransparent)
150 return true; 157 return true;
151# endif 158# endif
152 159
153# ifdef BG_IMAGE_FROM_FILE 160# ifdef BG_IMAGE_FROM_FILE
154# ifdef HAVE_AFTERIMAGE 161 if (have_image)
155 if (original_asim)
156# endif
157 { 162 {
158 if (h_align == rootAlign || v_align == rootAlign) 163 if (h_align == rootAlign || v_align == rootAlign)
159 return true; 164 return true;
160 } 165 }
161# endif 166# endif
448 return (changed > 0); 453 return (changed > 0);
449} 454}
450 455
451# ifdef HAVE_AFTERIMAGE 456# ifdef HAVE_AFTERIMAGE
452bool 457bool
453bgPixmap_t::render_asim (unsigned long background_flags) 458bgPixmap_t::render_image (unsigned long background_flags)
454{ 459{
455 if (target == NULL) 460 if (target == NULL)
456 return false; 461 return false;
457 462
458 target->init_asv (); 463 target->init_asv ();
645 free (layers); 650 free (layers);
646 } 651 }
647 } 652 }
648 TIMING_TEST_PRINT_RESULT (asim); 653 TIMING_TEST_PRINT_RESULT (asim);
649 654
650 if (pixmap) 655 bool ret = false;
651 {
652 if (result == NULL
653 || pmap_width != new_pmap_width
654 || pmap_height != new_pmap_height
655 || pmap_depth != target->depth)
656 {
657 XFreePixmap (target->dpy, pixmap);
658 pixmap = None;
659 }
660 }
661 656
662 if (result) 657 if (result)
663 { 658 {
664 XGCValues gcv; 659 XGCValues gcv;
665 GC gc; 660 GC gc;
661
662 if (pixmap)
663 {
664 if (pmap_width != new_pmap_width
665 || pmap_height != new_pmap_height
666 || pmap_depth != target->depth)
667 {
668 XFreePixmap (target->dpy, pixmap);
669 pixmap = None;
670 }
671 }
666 672
667 /* create Pixmap */ 673 /* create Pixmap */
668 if (pixmap == None) 674 if (pixmap == None)
669 { 675 {
670 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); 676 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth);
696 if (result != background && result != original_asim) 702 if (result != background && result != original_asim)
697 destroy_asimage (&result); 703 destroy_asimage (&result);
698 704
699 XFreeGC (target->dpy, gc); 705 XFreeGC (target->dpy, gc);
700 TIMING_TEST_PRINT_RESULT (asim); 706 TIMING_TEST_PRINT_RESULT (asim);
707
708 ret = true;
701 } 709 }
702 710
703 if (background) 711 if (background)
704 destroy_asimage (&background); 712 destroy_asimage (&background);
705 713
706 return true; 714 return ret;
707} 715}
708# endif /* HAVE_AFTERIMAGE */ 716# endif /* HAVE_AFTERIMAGE */
717
718# ifdef HAVE_PIXBUF
719bool
720bgPixmap_t::render_image (unsigned long background_flags)
721{
722 if (target == NULL)
723 return false;
724
725 if (!pixbuf)
726 return false;
727
728 // TODO: add alpha blending
729 if (background_flags)
730 return false;
731
732 GdkPixbuf *result;
733
734 int image_width = gdk_pixbuf_get_width (pixbuf);
735 int image_height = gdk_pixbuf_get_height (pixbuf);
736
737 int target_width = target->szHint.width;
738 int target_height = target->szHint.height;
739 int new_pmap_width = target_width;
740 int new_pmap_height = target_height;
741
742 int x = 0;
743 int y = 0;
744 int w = h_scale * target_width / 100;
745 int h = v_scale * target_height / 100;
746
747 if (h_align == rootAlign || v_align == rootAlign)
748 {
749 target->get_window_origin (x, y);
750 x = -x;
751 y = -y;
752 }
753
754 if (h_align != rootAlign)
755 x = make_align_position (h_align, target_width, w > 0 ? w : image_width);
756
757 if (v_align != rootAlign)
758 y = make_align_position (v_align, target_height, h > 0 ? h : image_height);
759
760 if (x >= target_width
761 || y >= target_height
762 || (w > 0 && x + w <= 0)
763 || (h > 0 && y + h <= 0))
764 return false;
765
766 result = pixbuf;
767
768 if ((w > 0 && w != image_width)
769 || (h > 0 && h != image_height))
770 {
771 result = gdk_pixbuf_scale_simple (pixbuf,
772 w > 0 ? w : image_width,
773 h > 0 ? h : image_height,
774 GDK_INTERP_BILINEAR);
775 }
776
777 bool ret = false;
778
779 if (result)
780 {
781 XGCValues gcv;
782 GC gc;
783
784 image_width = gdk_pixbuf_get_width (result);
785 image_height = gdk_pixbuf_get_height (result);
786
787 if (h_scale == 0)
788 new_pmap_width = min (image_width, target_width);
789 if (v_scale == 0)
790 new_pmap_height = min (image_height, target_height);
791
792 if (pixmap)
793 {
794 if (pmap_width != new_pmap_width
795 || pmap_height != new_pmap_height
796 || pmap_depth != target->depth)
797 {
798 XFreePixmap (target->dpy, pixmap);
799 pixmap = None;
800 }
801 }
802
803 if (pixmap == None)
804 {
805 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth);
806 pmap_width = new_pmap_width;
807 pmap_height = new_pmap_height;
808 pmap_depth = target->depth;
809 }
810
811 gcv.foreground = target->pix_colors[Color_bg];
812 gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv);
813
814 if (h_scale == 0 || v_scale == 0)
815 {
816 Pixmap tile = XCreatePixmap (target->dpy, target->vt, image_width, image_height, target->depth);
817 gdk_pixbuf_xlib_render_to_drawable (result, tile, gc,
818 0, 0,
819 0, 0,
820 image_width, image_height,
821 XLIB_RGB_DITHER_NONE,
822 0, 0);
823
824 gcv.tile = tile;
825 gcv.fill_style = FillTiled;
826 gcv.ts_x_origin = x;
827 gcv.ts_y_origin = y;
828 XChangeGC (target->dpy, gc, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv);
829
830 XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height);
831 XFreePixmap (target->dpy, tile);
832 }
833 else
834 {
835 int src_x, src_y, dst_x, dst_y;
836 int dst_width, dst_height;
837
838 src_x = make_clip_rectangle (x, image_width , new_pmap_width , dst_x, dst_width );
839 src_y = make_clip_rectangle (y, image_height, new_pmap_height, dst_y, dst_height);
840
841 if (dst_x > 0 || dst_y > 0
842 || dst_x + dst_width < new_pmap_width
843 || dst_y + dst_height < new_pmap_height)
844 XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height);
845
846 if (dst_x < new_pmap_width && dst_y < new_pmap_height)
847 gdk_pixbuf_xlib_render_to_drawable (result, pixmap, gc,
848 src_x, src_y,
849 dst_x, dst_y,
850 dst_width, dst_height,
851 XLIB_RGB_DITHER_NONE,
852 0, 0);
853 }
854
855 if (result != pixbuf)
856 g_object_unref (result);
857
858 XFreeGC (target->dpy, gc);
859
860 ret = true;
861 }
862
863 return ret;
864}
865# endif /* HAVE_PIXBUF */
709 866
710bool 867bool
711bgPixmap_t::set_file (const char *file) 868bgPixmap_t::set_file (const char *file)
712{ 869{
713 assert (file); 870 assert (file);
725 882
726# ifdef HAVE_AFTERIMAGE 883# ifdef HAVE_AFTERIMAGE
727 if (!target->asimman) 884 if (!target->asimman)
728 target->asimman = create_generic_imageman (target->rs[Rs_path]); 885 target->asimman = create_generic_imageman (target->rs[Rs_path]);
729 original_asim = get_asimage (target->asimman, file, 0xFFFFFFFF, 100); 886 original_asim = get_asimage (target->asimman, file, 0xFFFFFFFF, 100);
730 return original_asim; 887 if (original_asim)
888 have_image = true;
889 return have_image;
890# endif
891
892# ifdef HAVE_PIXBUF
893 pixbuf = gdk_pixbuf_new_from_file (file, NULL);
894 if (pixbuf)
895 have_image = true;
896 return have_image;
731# endif 897# endif
732 } 898 }
733 899
734 return false; 900 return false;
735} 901}
755 int changed = 0; 921 int changed = 0;
756 unsigned int hr, vr; 922 unsigned int hr, vr;
757 int junk; 923 int junk;
758 int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); 924 int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr);
759 925
760 if (!(geom_flags&WidthValue)) 926 if (!(geom_flags & WidthValue))
761 hr = 1; 927 hr = 1;
762 if (!(geom_flags&HeightValue)) 928 if (!(geom_flags & HeightValue))
763 vr = hr; 929 vr = hr;
764 930
765 if (h_blurRadius != hr) 931 if (h_blurRadius != hr)
766 { 932 {
767 ++changed; 933 ++changed;
777 if (v_blurRadius == 0 && h_blurRadius == 0) 943 if (v_blurRadius == 0 && h_blurRadius == 0)
778 flags &= ~blurNeeded; 944 flags &= ~blurNeeded;
779 else 945 else
780 flags |= blurNeeded; 946 flags |= blurNeeded;
781 947
782 return (changed>0); 948 return (changed > 0);
783} 949}
784 950
785static inline unsigned long 951static inline unsigned long
786compute_tint_shade_flags (rxvt_color *tint, int shade) 952compute_tint_shade_flags (rxvt_color *tint, int shade)
787{ 953{
845{ 1011{
846 unsigned long new_flags = compute_tint_shade_flags (NULL, shade); 1012 unsigned long new_flags = compute_tint_shade_flags (NULL, shade);
847 1013
848 if (new_flags != (flags & tintFlags)) 1014 if (new_flags != (flags & tintFlags))
849 { 1015 {
850 flags = (flags&~tintFlags)|new_flags; 1016 flags = (flags & ~tintFlags) | new_flags;
851 return true; 1017 return true;
852 } 1018 }
853 1019
854 return false; 1020 return false;
855} 1021}
1173 && pmap_depth == target->depth) 1339 && pmap_depth == target->depth)
1174 flags = flags & ~isInvalid; 1340 flags = flags & ~isInvalid;
1175 } 1341 }
1176# endif 1342# endif
1177 1343
1178# ifdef HAVE_AFTERIMAGE 1344# ifdef BG_IMAGE_FROM_FILE
1179 if (original_asim 1345 if (have_image
1180 || (background_flags & transpTransformations) != (flags & transpTransformations)) 1346 || (background_flags & transpTransformations) != (flags & transpTransformations))
1181 { 1347 {
1182 if (render_asim (background_flags)) 1348 if (render_image (background_flags))
1183 flags = flags & ~isInvalid; 1349 flags = flags & ~isInvalid;
1184 } 1350 }
1185# endif 1351# endif
1186 1352
1187 XImage *result = NULL; 1353 XImage *result = NULL;
1188 1354
1189 if (background_flags && (flags & isInvalid)) 1355 if (background_flags && (flags & isInvalid))
1190 { 1356 {
1191 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); 1357 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap);
1358 }
1192 1359
1360 if (result)
1361 {
1193# if !defined(HAVE_AFTERIMAGE) && !XFT 1362# if !defined(HAVE_AFTERIMAGE) && !XFT
1194 /* our own client-side tinting */ 1363 /* our own client-side tinting */
1195 /* ATTENTION: We ASSUME that XFT will let us do all the tinting necessary server-side. 1364 /* ATTENTION: We ASSUME that XFT will let us do all the tinting necessary server-side.
1196 This may need to be changed in need_client_side_rendering() logic is altered !!! */ 1365 This may need to be changed in need_client_side_rendering() logic is altered !!! */
1197 if (result != NULL && !(background_flags & transpPmapTinted) && (flags & tintNeeded)) 1366 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded))
1198 { 1367 {
1199 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 1368 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1200 if (flags & tintSet) 1369 if (flags & tintSet)
1201 tint.get (c); 1370 tint.get (c);
1202 ShadeXImage (target, result, shade, c.r, c.g, c.b); 1371 ShadeXImage (target, result, shade, c.r, c.g, c.b);
1203 } 1372 }
1204# endif 1373# endif
1205 }
1206 1374
1207 if (result)
1208 {
1209 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); 1375 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL);
1210 1376
1211 if (gc) 1377 if (gc)
1212 { 1378 {
1213 if (/*pmap_depth != target->depth &&*/ pixmap != None) 1379 if (/*pmap_depth != target->depth &&*/ pixmap != None)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines