… | |
… | |
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 ? |
… | |
… | |
95 | { |
95 | { |
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 |
|
|
101 | #ifdef HAVE_PIXBUF |
|
|
102 | pixbuf = NULL; |
100 | #endif |
103 | #endif |
101 | #ifdef BG_IMAGE_FROM_FILE |
104 | #ifdef BG_IMAGE_FROM_FILE |
102 | have_image = false; |
105 | have_image = false; |
103 | h_scale = v_scale = 0; |
106 | h_scale = v_scale = 0; |
104 | h_align = v_align = 0; |
107 | h_align = v_align = 0; |
… | |
… | |
113 | bgPixmap_t::destroy () |
116 | bgPixmap_t::destroy () |
114 | { |
117 | { |
115 | #ifdef HAVE_AFTERIMAGE |
118 | #ifdef HAVE_AFTERIMAGE |
116 | if (original_asim) |
119 | if (original_asim) |
117 | safe_asimage_destroy (original_asim); |
120 | safe_asimage_destroy (original_asim); |
|
|
121 | #endif |
|
|
122 | |
|
|
123 | #ifdef HAVE_PIXBUF |
|
|
124 | if (pixbuf) |
|
|
125 | g_object_unref (pixbuf); |
118 | #endif |
126 | #endif |
119 | |
127 | |
120 | if (pixmap && target) |
128 | if (pixmap && target) |
121 | XFreePixmap (target->dpy, pixmap); |
129 | XFreePixmap (target->dpy, pixmap); |
122 | } |
130 | } |
… | |
… | |
445 | return (changed > 0); |
453 | return (changed > 0); |
446 | } |
454 | } |
447 | |
455 | |
448 | # ifdef HAVE_AFTERIMAGE |
456 | # ifdef HAVE_AFTERIMAGE |
449 | bool |
457 | bool |
450 | bgPixmap_t::render_asim (unsigned long background_flags) |
458 | bgPixmap_t::render_image (unsigned long background_flags) |
451 | { |
459 | { |
452 | if (target == NULL) |
460 | if (target == NULL) |
453 | return false; |
461 | return false; |
454 | |
462 | |
455 | target->init_asv (); |
463 | target->init_asv (); |
… | |
… | |
642 | free (layers); |
650 | free (layers); |
643 | } |
651 | } |
644 | } |
652 | } |
645 | TIMING_TEST_PRINT_RESULT (asim); |
653 | TIMING_TEST_PRINT_RESULT (asim); |
646 | |
654 | |
647 | if (pixmap) |
655 | bool ret = false; |
648 | { |
|
|
649 | if (result == NULL |
|
|
650 | || pmap_width != new_pmap_width |
|
|
651 | || pmap_height != new_pmap_height |
|
|
652 | || pmap_depth != target->depth) |
|
|
653 | { |
|
|
654 | XFreePixmap (target->dpy, pixmap); |
|
|
655 | pixmap = None; |
|
|
656 | } |
|
|
657 | } |
|
|
658 | |
656 | |
659 | if (result) |
657 | if (result) |
660 | { |
658 | { |
661 | XGCValues gcv; |
659 | XGCValues gcv; |
662 | 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 | } |
663 | |
672 | |
664 | /* create Pixmap */ |
673 | /* create Pixmap */ |
665 | if (pixmap == None) |
674 | if (pixmap == None) |
666 | { |
675 | { |
667 | 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); |
… | |
… | |
693 | if (result != background && result != original_asim) |
702 | if (result != background && result != original_asim) |
694 | destroy_asimage (&result); |
703 | destroy_asimage (&result); |
695 | |
704 | |
696 | XFreeGC (target->dpy, gc); |
705 | XFreeGC (target->dpy, gc); |
697 | TIMING_TEST_PRINT_RESULT (asim); |
706 | TIMING_TEST_PRINT_RESULT (asim); |
|
|
707 | |
|
|
708 | ret = true; |
698 | } |
709 | } |
699 | |
710 | |
700 | if (background) |
711 | if (background) |
701 | destroy_asimage (&background); |
712 | destroy_asimage (&background); |
702 | |
713 | |
703 | return true; |
714 | return ret; |
704 | } |
715 | } |
705 | # endif /* HAVE_AFTERIMAGE */ |
716 | # endif /* HAVE_AFTERIMAGE */ |
|
|
717 | |
|
|
718 | # ifdef HAVE_PIXBUF |
|
|
719 | bool |
|
|
720 | bgPixmap_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 */ |
706 | |
866 | |
707 | bool |
867 | bool |
708 | bgPixmap_t::set_file (const char *file) |
868 | bgPixmap_t::set_file (const char *file) |
709 | { |
869 | { |
710 | assert (file); |
870 | assert (file); |
… | |
… | |
726 | original_asim = get_asimage (target->asimman, file, 0xFFFFFFFF, 100); |
886 | original_asim = get_asimage (target->asimman, file, 0xFFFFFFFF, 100); |
727 | if (original_asim) |
887 | if (original_asim) |
728 | have_image = true; |
888 | have_image = true; |
729 | return have_image; |
889 | return have_image; |
730 | # endif |
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; |
|
|
897 | # endif |
731 | } |
898 | } |
732 | |
899 | |
733 | return false; |
900 | return false; |
734 | } |
901 | } |
735 | |
902 | |
… | |
… | |
754 | int changed = 0; |
921 | int changed = 0; |
755 | unsigned int hr, vr; |
922 | unsigned int hr, vr; |
756 | int junk; |
923 | int junk; |
757 | int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); |
924 | int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); |
758 | |
925 | |
759 | if (!(geom_flags&WidthValue)) |
926 | if (!(geom_flags & WidthValue)) |
760 | hr = 1; |
927 | hr = 1; |
761 | if (!(geom_flags&HeightValue)) |
928 | if (!(geom_flags & HeightValue)) |
762 | vr = hr; |
929 | vr = hr; |
763 | |
930 | |
764 | if (h_blurRadius != hr) |
931 | if (h_blurRadius != hr) |
765 | { |
932 | { |
766 | ++changed; |
933 | ++changed; |
… | |
… | |
776 | if (v_blurRadius == 0 && h_blurRadius == 0) |
943 | if (v_blurRadius == 0 && h_blurRadius == 0) |
777 | flags &= ~blurNeeded; |
944 | flags &= ~blurNeeded; |
778 | else |
945 | else |
779 | flags |= blurNeeded; |
946 | flags |= blurNeeded; |
780 | |
947 | |
781 | return (changed>0); |
948 | return (changed > 0); |
782 | } |
949 | } |
783 | |
950 | |
784 | static inline unsigned long |
951 | static inline unsigned long |
785 | compute_tint_shade_flags (rxvt_color *tint, int shade) |
952 | compute_tint_shade_flags (rxvt_color *tint, int shade) |
786 | { |
953 | { |
… | |
… | |
844 | { |
1011 | { |
845 | unsigned long new_flags = compute_tint_shade_flags (NULL, shade); |
1012 | unsigned long new_flags = compute_tint_shade_flags (NULL, shade); |
846 | |
1013 | |
847 | if (new_flags != (flags & tintFlags)) |
1014 | if (new_flags != (flags & tintFlags)) |
848 | { |
1015 | { |
849 | flags = (flags&~tintFlags)|new_flags; |
1016 | flags = (flags & ~tintFlags) | new_flags; |
850 | return true; |
1017 | return true; |
851 | } |
1018 | } |
852 | |
1019 | |
853 | return false; |
1020 | return false; |
854 | } |
1021 | } |
… | |
… | |
1172 | && pmap_depth == target->depth) |
1339 | && pmap_depth == target->depth) |
1173 | flags = flags & ~isInvalid; |
1340 | flags = flags & ~isInvalid; |
1174 | } |
1341 | } |
1175 | # endif |
1342 | # endif |
1176 | |
1343 | |
1177 | # ifdef HAVE_AFTERIMAGE |
1344 | # ifdef BG_IMAGE_FROM_FILE |
1178 | if (original_asim |
1345 | if (have_image |
1179 | || (background_flags & transpTransformations) != (flags & transpTransformations)) |
1346 | || (background_flags & transpTransformations) != (flags & transpTransformations)) |
1180 | { |
1347 | { |
1181 | if (render_asim (background_flags)) |
1348 | if (render_image (background_flags)) |
1182 | flags = flags & ~isInvalid; |
1349 | flags = flags & ~isInvalid; |
1183 | } |
1350 | } |
1184 | # endif |
1351 | # endif |
1185 | |
1352 | |
1186 | XImage *result = NULL; |
1353 | XImage *result = NULL; |
1187 | |
1354 | |
1188 | if (background_flags && (flags & isInvalid)) |
1355 | if (background_flags && (flags & isInvalid)) |
1189 | { |
1356 | { |
1190 | 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 | } |
1191 | |
1359 | |
|
|
1360 | if (result) |
|
|
1361 | { |
1192 | # if !defined(HAVE_AFTERIMAGE) && !XFT |
1362 | # if !defined(HAVE_AFTERIMAGE) && !XFT |
1193 | /* our own client-side tinting */ |
1363 | /* our own client-side tinting */ |
1194 | /* 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. |
1195 | 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 !!! */ |
1196 | if (result != NULL && !(background_flags & transpPmapTinted) && (flags & tintNeeded)) |
1366 | if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) |
1197 | { |
1367 | { |
1198 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
1368 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
1199 | if (flags & tintSet) |
1369 | if (flags & tintSet) |
1200 | tint.get (c); |
1370 | tint.get (c); |
1201 | ShadeXImage (target, result, shade, c.r, c.g, c.b); |
1371 | ShadeXImage (target, result, shade, c.r, c.g, c.b); |
1202 | } |
1372 | } |
1203 | # endif |
1373 | # endif |
1204 | } |
|
|
1205 | |
1374 | |
1206 | if (result) |
|
|
1207 | { |
|
|
1208 | GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); |
1375 | GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); |
1209 | |
1376 | |
1210 | if (gc) |
1377 | if (gc) |
1211 | { |
1378 | { |
1212 | if (/*pmap_depth != target->depth &&*/ pixmap != None) |
1379 | if (/*pmap_depth != target->depth &&*/ pixmap != None) |