… | |
… | |
23 | *---------------------------------------------------------------------*/ |
23 | *---------------------------------------------------------------------*/ |
24 | |
24 | |
25 | #include <cmath> |
25 | #include <cmath> |
26 | #include "../config.h" /* NECESSARY */ |
26 | #include "../config.h" /* NECESSARY */ |
27 | #include "rxvt.h" /* NECESSARY */ |
27 | #include "rxvt.h" /* NECESSARY */ |
|
|
28 | |
|
|
29 | #if XRENDER |
|
|
30 | # include <X11/extensions/Xrender.h> |
|
|
31 | #endif |
|
|
32 | |
|
|
33 | #ifndef FilterConvolution |
|
|
34 | #define FilterConvolution "convolution" |
|
|
35 | #endif |
28 | |
36 | |
29 | #define DO_TIMING_TEST 0 |
37 | #define DO_TIMING_TEST 0 |
30 | |
38 | |
31 | #if DO_TIMING_TEST |
39 | #if DO_TIMING_TEST |
32 | # include <sys/time.h> |
40 | # include <sys/time.h> |
… | |
… | |
108 | h_scale = v_scale = 0; |
116 | h_scale = v_scale = 0; |
109 | h_align = v_align = 0; |
117 | h_align = v_align = 0; |
110 | #endif |
118 | #endif |
111 | #ifdef ENABLE_TRANSPARENCY |
119 | #ifdef ENABLE_TRANSPARENCY |
112 | shade = 100; |
120 | shade = 100; |
113 | recoded_root_pmap = None; |
|
|
114 | #endif |
121 | #endif |
115 | flags = 0; |
122 | flags = 0; |
116 | pixmap = None; |
123 | pixmap = None; |
117 | valid_since = invalid_since = 0; |
124 | valid_since = invalid_since = 0; |
118 | target = 0; |
125 | target = 0; |
… | |
… | |
129 | #ifdef HAVE_PIXBUF |
136 | #ifdef HAVE_PIXBUF |
130 | if (pixbuf) |
137 | if (pixbuf) |
131 | g_object_unref (pixbuf); |
138 | g_object_unref (pixbuf); |
132 | #endif |
139 | #endif |
133 | |
140 | |
134 | #ifdef ENABLE_TRANSPARENCY |
|
|
135 | if (recoded_root_pmap && target) |
|
|
136 | XFreePixmap (target->dpy, recoded_root_pmap); |
|
|
137 | #endif |
|
|
138 | |
|
|
139 | if (pixmap && target) |
141 | if (pixmap && target) |
140 | XFreePixmap (target->dpy, pixmap); |
142 | XFreePixmap (target->dpy, pixmap); |
141 | } |
143 | } |
142 | |
144 | |
143 | bool |
145 | bool |
… | |
… | |
174 | return true; |
176 | return true; |
175 | } |
177 | } |
176 | # endif |
178 | # endif |
177 | |
179 | |
178 | return false; |
180 | return false; |
179 | }; |
181 | } |
180 | |
182 | |
181 | bool bgPixmap_t::need_client_side_rendering () |
183 | bool bgPixmap_t::need_client_side_rendering () |
182 | { |
184 | { |
183 | # ifdef HAVE_AFTERIMAGE |
185 | # ifdef HAVE_AFTERIMAGE |
184 | if (original_asim) |
186 | if (original_asim) |
… | |
… | |
256 | } |
258 | } |
257 | |
259 | |
258 | bool |
260 | bool |
259 | bgPixmap_t::set_geometry (const char *geom) |
261 | bgPixmap_t::set_geometry (const char *geom) |
260 | { |
262 | { |
|
|
263 | bool changed = false; |
261 | int geom_flags = 0, changed = 0; |
264 | int geom_flags = 0; |
262 | int x = 0, y = 0; |
265 | int x = 0, y = 0; |
263 | unsigned int w = 0, h = 0; |
266 | unsigned int w = 0, h = 0; |
264 | unsigned int n; |
267 | unsigned int n; |
265 | unsigned long new_flags = (flags & (~geometryFlags)); |
268 | unsigned long new_flags = (flags & (~geometryFlags)); |
266 | const char *p; |
269 | const char *p; |
… | |
… | |
422 | |
425 | |
423 | while (*ops != ':' && *ops != '\0') ++ops; |
426 | while (*ops != ':' && *ops != '\0') ++ops; |
424 | } /* done parsing ops */ |
427 | } /* done parsing ops */ |
425 | } |
428 | } |
426 | |
429 | |
427 | if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) ++changed; |
430 | if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) changed = true; |
428 | if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) ++changed; |
431 | if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) changed = true; |
429 | if (check_set_align_value (geom_flags, XValue, h_align, x)) ++changed; |
432 | if (check_set_align_value (geom_flags, XValue, h_align, x)) changed = true; |
430 | if (check_set_align_value (geom_flags, YValue, v_align, y)) ++changed; |
433 | if (check_set_align_value (geom_flags, YValue, v_align, y)) changed = true; |
431 | } |
434 | } |
432 | |
435 | |
433 | if (new_flags != flags) |
436 | if (new_flags != flags) |
434 | { |
437 | { |
435 | flags = new_flags; |
438 | flags = new_flags; |
436 | changed++; |
439 | changed = true; |
437 | } |
440 | } |
438 | |
441 | |
439 | return (changed > 0); |
442 | return changed; |
440 | } |
443 | } |
441 | |
444 | |
442 | void |
445 | void |
443 | bgPixmap_t::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y) |
446 | bgPixmap_t::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y) |
444 | { |
447 | { |
… | |
… | |
667 | if (result) |
670 | if (result) |
668 | { |
671 | { |
669 | XGCValues gcv; |
672 | XGCValues gcv; |
670 | GC gc; |
673 | GC gc; |
671 | |
674 | |
672 | if (pixmap) |
|
|
673 | { |
|
|
674 | if (pmap_width != new_pmap_width |
|
|
675 | || pmap_height != new_pmap_height |
|
|
676 | || pmap_depth != target->depth) |
|
|
677 | { |
|
|
678 | XFreePixmap (target->dpy, pixmap); |
|
|
679 | pixmap = None; |
|
|
680 | } |
|
|
681 | } |
|
|
682 | |
|
|
683 | /* create Pixmap */ |
675 | /* create Pixmap */ |
684 | if (pixmap == None) |
676 | if (pixmap == None |
|
|
677 | || pmap_width != new_pmap_width |
|
|
678 | || pmap_height != new_pmap_height |
|
|
679 | || pmap_depth != target->depth) |
685 | { |
680 | { |
|
|
681 | if (pixmap) |
|
|
682 | XFreePixmap (target->dpy, pixmap); |
686 | pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); |
683 | pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); |
687 | pmap_width = new_pmap_width; |
684 | pmap_width = new_pmap_width; |
688 | pmap_height = new_pmap_height; |
685 | pmap_height = new_pmap_height; |
689 | pmap_depth = target->depth; |
686 | pmap_depth = target->depth; |
690 | } |
687 | } |
… | |
… | |
735 | return false; |
732 | return false; |
736 | |
733 | |
737 | if (!pixbuf) |
734 | if (!pixbuf) |
738 | return false; |
735 | return false; |
739 | |
736 | |
740 | #if !XRENDER |
|
|
741 | if (background_flags) |
737 | if (background_flags |
|
|
738 | && !(flags & HAS_RENDER)) |
742 | return false; |
739 | return false; |
743 | #endif |
|
|
744 | |
740 | |
745 | GdkPixbuf *result; |
741 | GdkPixbuf *result; |
746 | |
742 | |
747 | int image_width = gdk_pixbuf_get_width (pixbuf); |
743 | int image_width = gdk_pixbuf_get_width (pixbuf); |
748 | int image_height = gdk_pixbuf_get_height (pixbuf); |
744 | int image_height = gdk_pixbuf_get_height (pixbuf); |
… | |
… | |
799 | new_pmap_width = min (image_width, target_width); |
795 | new_pmap_width = min (image_width, target_width); |
800 | new_pmap_height = min (image_height, target_height); |
796 | new_pmap_height = min (image_height, target_height); |
801 | } |
797 | } |
802 | } |
798 | } |
803 | |
799 | |
804 | if (pixmap) |
|
|
805 | { |
|
|
806 | if (pmap_width != new_pmap_width |
|
|
807 | || pmap_height != new_pmap_height |
|
|
808 | || pmap_depth != target->depth) |
|
|
809 | { |
|
|
810 | XFreePixmap (target->dpy, pixmap); |
|
|
811 | pixmap = None; |
|
|
812 | } |
|
|
813 | } |
|
|
814 | |
|
|
815 | if (pixmap == None) |
800 | if (pixmap == None |
|
|
801 | || pmap_width != new_pmap_width |
|
|
802 | || pmap_height != new_pmap_height |
|
|
803 | || pmap_depth != target->depth) |
816 | { |
804 | { |
|
|
805 | if (pixmap) |
|
|
806 | XFreePixmap (target->dpy, pixmap); |
817 | pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); |
807 | pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); |
818 | pmap_width = new_pmap_width; |
808 | pmap_width = new_pmap_width; |
819 | pmap_height = new_pmap_height; |
809 | pmap_height = new_pmap_height; |
820 | pmap_depth = target->depth; |
810 | pmap_depth = target->depth; |
821 | } |
811 | } |
… | |
… | |
915 | # endif /* HAVE_PIXBUF */ |
905 | # endif /* HAVE_PIXBUF */ |
916 | |
906 | |
917 | bool |
907 | bool |
918 | bgPixmap_t::set_file (const char *file) |
908 | bgPixmap_t::set_file (const char *file) |
919 | { |
909 | { |
920 | assert (file); |
910 | if (!file || !*file) |
|
|
911 | return false; |
921 | |
912 | |
922 | if (*file) |
|
|
923 | { |
|
|
924 | if (const char *p = strchr (file, ';')) |
913 | if (const char *p = strchr (file, ';')) |
925 | { |
914 | { |
926 | size_t len = p - file; |
915 | size_t len = p - file; |
927 | char *f = rxvt_temp_buf<char> (len + 1); |
916 | char *f = rxvt_temp_buf<char> (len + 1); |
928 | memcpy (f, file, len); |
917 | memcpy (f, file, len); |
929 | f[len] = '\0'; |
918 | f[len] = '\0'; |
930 | file = f; |
919 | file = f; |
931 | } |
920 | } |
932 | |
921 | |
933 | # ifdef HAVE_AFTERIMAGE |
922 | # ifdef HAVE_AFTERIMAGE |
934 | if (!target->asimman) |
923 | if (!target->asimman) |
935 | target->asimman = create_generic_imageman (target->rs[Rs_path]); |
924 | target->asimman = create_generic_imageman (target->rs[Rs_path]); |
936 | ASImage *image = get_asimage (target->asimman, file, 0xFFFFFFFF, 100); |
925 | ASImage *image = get_asimage (target->asimman, file, 0xFFFFFFFF, 100); |
937 | if (image) |
926 | if (image) |
938 | { |
927 | { |
939 | if (original_asim) |
928 | if (original_asim) |
940 | safe_asimage_destroy (original_asim); |
929 | safe_asimage_destroy (original_asim); |
941 | original_asim = image; |
930 | original_asim = image; |
942 | have_image = true; |
931 | have_image = true; |
943 | return true; |
932 | return true; |
944 | } |
933 | } |
945 | # endif |
934 | # endif |
946 | |
935 | |
947 | # ifdef HAVE_PIXBUF |
936 | # ifdef HAVE_PIXBUF |
948 | GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); |
937 | GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); |
949 | if (image) |
938 | if (image) |
950 | { |
939 | { |
951 | if (pixbuf) |
940 | if (pixbuf) |
952 | g_object_unref (pixbuf); |
941 | g_object_unref (pixbuf); |
953 | pixbuf = image; |
942 | pixbuf = image; |
954 | have_image = true; |
943 | have_image = true; |
955 | return true; |
944 | return true; |
956 | } |
945 | } |
957 | # endif |
946 | # endif |
958 | } |
|
|
959 | |
947 | |
960 | return false; |
948 | return false; |
961 | } |
949 | } |
962 | |
950 | |
963 | # endif /* BG_IMAGE_FROM_FILE */ |
951 | # endif /* BG_IMAGE_FROM_FILE */ |
… | |
… | |
976 | } |
964 | } |
977 | |
965 | |
978 | bool |
966 | bool |
979 | bgPixmap_t::set_blur_radius (const char *geom) |
967 | bgPixmap_t::set_blur_radius (const char *geom) |
980 | { |
968 | { |
981 | int changed = 0; |
969 | bool changed = false; |
982 | unsigned int hr, vr; |
970 | unsigned int hr, vr; |
983 | int junk; |
971 | int junk; |
984 | int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); |
972 | int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); |
985 | |
973 | |
986 | if (!(geom_flags & WidthValue)) |
974 | if (!(geom_flags & WidthValue)) |
… | |
… | |
991 | min_it (hr, 128); |
979 | min_it (hr, 128); |
992 | min_it (vr, 128); |
980 | min_it (vr, 128); |
993 | |
981 | |
994 | if (h_blurRadius != hr) |
982 | if (h_blurRadius != hr) |
995 | { |
983 | { |
996 | ++changed; |
984 | changed = true; |
997 | h_blurRadius = hr; |
985 | h_blurRadius = hr; |
998 | } |
986 | } |
999 | |
987 | |
1000 | if (v_blurRadius != vr) |
988 | if (v_blurRadius != vr) |
1001 | { |
989 | { |
1002 | ++changed; |
990 | changed = true; |
1003 | v_blurRadius = vr; |
991 | v_blurRadius = vr; |
1004 | } |
992 | } |
1005 | |
993 | |
1006 | if (v_blurRadius == 0 && h_blurRadius == 0) |
994 | if (v_blurRadius == 0 && h_blurRadius == 0) |
1007 | flags &= ~blurNeeded; |
995 | flags &= ~blurNeeded; |
1008 | else |
996 | else |
1009 | flags |= blurNeeded; |
997 | flags |= blurNeeded; |
1010 | |
998 | |
1011 | #if XRENDER |
|
|
1012 | XFilters *filters = XRenderQueryFilters (target->dpy, target->vt); |
|
|
1013 | if (filters) |
|
|
1014 | { |
|
|
1015 | for (int i = 0; i < filters->nfilter; i++) |
|
|
1016 | if (!strcmp (filters->filter[i], FilterConvolution)) |
|
|
1017 | flags |= bgPixmap_t::blurServerSide; |
|
|
1018 | |
|
|
1019 | XFree (filters); |
|
|
1020 | } |
|
|
1021 | #endif |
|
|
1022 | |
|
|
1023 | return (changed > 0); |
999 | return changed; |
1024 | } |
1000 | } |
1025 | |
1001 | |
1026 | static inline unsigned long |
1002 | static inline unsigned long |
1027 | compute_tint_shade_flags (rxvt_color *tint, int shade) |
1003 | compute_tint_shade_flags (rxvt_color *tint, int shade) |
1028 | { |
1004 | { |
… | |
… | |
1047 | { |
1023 | { |
1048 | if ((c.r > 0x000700 || c.g > 0x000700 || c.b > 0x000700) |
1024 | if ((c.r > 0x000700 || c.g > 0x000700 || c.b > 0x000700) |
1049 | && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700)) |
1025 | && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700)) |
1050 | { |
1026 | { |
1051 | flags |= bgPixmap_t::tintNeeded; |
1027 | flags |= bgPixmap_t::tintNeeded; |
1052 | } |
|
|
1053 | } |
|
|
1054 | |
|
|
1055 | if (flags & bgPixmap_t::tintNeeded) |
|
|
1056 | { |
|
|
1057 | if (flags & bgPixmap_t::tintWholesome) |
|
|
1058 | flags |= bgPixmap_t::tintServerSide; |
|
|
1059 | else |
|
|
1060 | { |
|
|
1061 | #if XRENDER |
|
|
1062 | flags |= bgPixmap_t::tintServerSide; |
|
|
1063 | #endif |
|
|
1064 | } |
1028 | } |
1065 | } |
1029 | } |
1066 | |
1030 | |
1067 | return flags; |
1031 | return flags; |
1068 | } |
1032 | } |
… | |
… | |
1267 | |
1231 | |
1268 | if (mask_pic && overlay_pic && back_pic) |
1232 | if (mask_pic && overlay_pic && back_pic) |
1269 | { |
1233 | { |
1270 | XRenderColor mask_c; |
1234 | XRenderColor mask_c; |
1271 | |
1235 | |
1272 | memset (&mask_c, (shade > 100) ? 0xFF : 0x0, sizeof (mask_c)); |
1236 | mask_c.red = mask_c.green = mask_c.blue = shade > 100 ? 0xffff : 0; |
1273 | mask_c.alpha = 0xffff; |
1237 | mask_c.alpha = 0xffff; |
1274 | XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); |
1238 | XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); |
1275 | |
1239 | |
1276 | mask_c.alpha = 0; |
1240 | mask_c.alpha = 0; |
1277 | mask_c.red = 0xffff - c.r; |
1241 | mask_c.red = 0xffff - c.r; |
… | |
… | |
1307 | /* root dimensions may change from call to call - but Display structure should |
1271 | /* root dimensions may change from call to call - but Display structure should |
1308 | * be always up-to-date, so let's use it : |
1272 | * be always up-to-date, so let's use it : |
1309 | */ |
1273 | */ |
1310 | int screen = target->display->screen; |
1274 | int screen = target->display->screen; |
1311 | Display *dpy = target->dpy; |
1275 | Display *dpy = target->dpy; |
|
|
1276 | int root_depth = DefaultDepth (dpy, screen); |
1312 | int root_width = DisplayWidth (dpy, screen); |
1277 | int root_width = DisplayWidth (dpy, screen); |
1313 | int root_height = DisplayHeight (dpy, screen); |
1278 | int root_height = DisplayHeight (dpy, screen); |
|
|
1279 | unsigned int root_pmap_width, root_pmap_height; |
1314 | int window_width = target->szHint.width; |
1280 | int window_width = target->szHint.width; |
1315 | int window_height = target->szHint.height; |
1281 | int window_height = target->szHint.height; |
1316 | int sx, sy; |
1282 | int sx, sy; |
1317 | XGCValues gcv; |
1283 | XGCValues gcv; |
1318 | GC gc; |
1284 | GC gc; |
… | |
… | |
1322 | /* check if we are outside of the visible part of the virtual screen : */ |
1288 | /* check if we are outside of the visible part of the virtual screen : */ |
1323 | if (sx + window_width <= 0 || sy + window_height <= 0 |
1289 | if (sx + window_width <= 0 || sy + window_height <= 0 |
1324 | || sx >= root_width || sy >= root_height) |
1290 | || sx >= root_width || sy >= root_height) |
1325 | return 0; |
1291 | return 0; |
1326 | |
1292 | |
|
|
1293 | // validate root pixmap and get its size |
|
|
1294 | if (root_pixmap != None) |
|
|
1295 | { |
|
|
1296 | Window wdummy; |
|
|
1297 | int idummy; |
|
|
1298 | unsigned int udummy; |
|
|
1299 | |
|
|
1300 | target->allowedxerror = -1; |
|
|
1301 | |
|
|
1302 | if (!XGetGeometry (dpy, root_pixmap, &wdummy, &idummy, &idummy, &root_pmap_width, &root_pmap_height, &udummy, &udummy)) |
|
|
1303 | root_pixmap = None; |
|
|
1304 | |
|
|
1305 | target->allowedxerror = 0; |
|
|
1306 | } |
|
|
1307 | |
|
|
1308 | Pixmap recoded_root_pmap = root_pixmap; |
|
|
1309 | |
|
|
1310 | if (root_pixmap != None && root_depth != target->depth) |
|
|
1311 | { |
|
|
1312 | #if XRENDER |
|
|
1313 | if (flags & HAS_RENDER) |
|
|
1314 | { |
|
|
1315 | XRenderPictureAttributes pa; |
|
|
1316 | |
|
|
1317 | XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen)); |
|
|
1318 | Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, &pa); |
|
|
1319 | |
|
|
1320 | recoded_root_pmap = XCreatePixmap (dpy, target->vt, root_pmap_width, root_pmap_height, target->depth); |
|
|
1321 | XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, target->visual); |
|
|
1322 | Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, &pa); |
|
|
1323 | |
|
|
1324 | if (src && dst) |
|
|
1325 | XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, root_pmap_width, root_pmap_height); |
|
|
1326 | else |
|
|
1327 | { |
|
|
1328 | XFreePixmap (dpy, recoded_root_pmap); |
|
|
1329 | root_pixmap = None; |
|
|
1330 | } |
|
|
1331 | |
|
|
1332 | XRenderFreePicture (dpy, src); |
|
|
1333 | XRenderFreePicture (dpy, dst); |
|
|
1334 | } |
|
|
1335 | else |
|
|
1336 | #endif |
|
|
1337 | root_pixmap = None; |
|
|
1338 | } |
|
|
1339 | |
1327 | if (root_pixmap == None) |
1340 | if (root_pixmap == None) |
1328 | return 0; |
1341 | return 0; |
1329 | |
1342 | |
1330 | Pixmap tiled_root_pmap = XCreatePixmap (dpy, target->vt, window_width, window_height, target->depth); |
1343 | Pixmap tiled_root_pmap = XCreatePixmap (dpy, target->vt, window_width, window_height, target->depth); |
1331 | |
1344 | |
1332 | if (tiled_root_pmap == None) /* something really bad happened - abort */ |
1345 | if (tiled_root_pmap == None) /* something really bad happened - abort */ |
1333 | return 0; |
1346 | return 0; |
1334 | |
1347 | |
1335 | /* straightforward pixmap copy */ |
1348 | /* straightforward pixmap copy */ |
1336 | gcv.tile = root_pixmap; |
1349 | gcv.tile = recoded_root_pmap; |
1337 | gcv.fill_style = FillTiled; |
1350 | gcv.fill_style = FillTiled; |
1338 | |
1351 | |
1339 | while (sx < 0) sx += (int)root_width; |
1352 | while (sx < 0) sx += (int)root_width; |
1340 | while (sy < 0) sy += (int)root_height; |
1353 | while (sy < 0) sy += (int)root_height; |
1341 | |
1354 | |
… | |
… | |
1346 | if (gc) |
1359 | if (gc) |
1347 | { |
1360 | { |
1348 | XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height); |
1361 | XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height); |
1349 | result |= transpPmapTiled; |
1362 | result |= transpPmapTiled; |
1350 | XFreeGC (dpy, gc); |
1363 | XFreeGC (dpy, gc); |
1351 | } |
|
|
1352 | |
1364 | |
1353 | if (tiled_root_pmap != None) |
|
|
1354 | { |
|
|
1355 | if (!need_client_side_rendering ()) |
1365 | if (!need_client_side_rendering ()) |
1356 | { |
1366 | { |
1357 | if (flags & (blurNeeded | blurServerSide)) |
1367 | if ((flags & blurNeeded) |
|
|
1368 | && (flags & HAS_RENDER_CONV)) |
1358 | { |
1369 | { |
1359 | if (blur_pixmap (tiled_root_pmap, target->visual, window_width, window_height)) |
1370 | if (blur_pixmap (tiled_root_pmap, target->visual, window_width, window_height)) |
1360 | result |= transpPmapBlurred; |
1371 | result |= transpPmapBlurred; |
1361 | } |
1372 | } |
1362 | if (flags & (tintNeeded | tintServerSide)) |
1373 | if ((flags & tintNeeded) |
|
|
1374 | && (flags & (tintWholesome | HAS_RENDER))) |
1363 | { |
1375 | { |
1364 | if (tint_pixmap (tiled_root_pmap, target->visual, window_width, window_height)) |
1376 | if (tint_pixmap (tiled_root_pmap, target->visual, window_width, window_height)) |
1365 | result |= transpPmapTinted; |
1377 | result |= transpPmapTinted; |
1366 | } |
1378 | } |
1367 | } /* server side rendering completed */ |
1379 | } /* server side rendering completed */ |
… | |
… | |
1372 | pixmap = tiled_root_pmap; |
1384 | pixmap = tiled_root_pmap; |
1373 | pmap_width = window_width; |
1385 | pmap_width = window_width; |
1374 | pmap_height = window_height; |
1386 | pmap_height = window_height; |
1375 | pmap_depth = target->depth; |
1387 | pmap_depth = target->depth; |
1376 | } |
1388 | } |
|
|
1389 | else |
|
|
1390 | XFreePixmap (dpy, tiled_root_pmap); |
|
|
1391 | |
|
|
1392 | if (recoded_root_pmap != root_pixmap) |
|
|
1393 | XFreePixmap (dpy, recoded_root_pmap); |
1377 | |
1394 | |
1378 | return result; |
1395 | return result; |
1379 | } |
1396 | } |
1380 | |
1397 | |
1381 | void |
1398 | void |
… | |
… | |
1384 | Pixmap new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID); |
1401 | Pixmap new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID); |
1385 | if (new_root_pixmap == None) |
1402 | if (new_root_pixmap == None) |
1386 | new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID); |
1403 | new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID); |
1387 | |
1404 | |
1388 | root_pixmap = new_root_pixmap; |
1405 | root_pixmap = new_root_pixmap; |
1389 | |
|
|
1390 | unsigned int width, height; |
|
|
1391 | int depth = DefaultDepth (target->dpy, target->display->screen); |
|
|
1392 | |
|
|
1393 | // validate root pixmap |
|
|
1394 | if (root_pixmap != None) |
|
|
1395 | { |
|
|
1396 | Window wdummy; |
|
|
1397 | int idummy; |
|
|
1398 | unsigned int udummy; |
|
|
1399 | |
|
|
1400 | target->allowedxerror = -1; |
|
|
1401 | |
|
|
1402 | if (!XGetGeometry (target->dpy, root_pixmap, &wdummy, &idummy, &idummy, &width, &height, &udummy, &udummy)) |
|
|
1403 | root_pixmap = None; |
|
|
1404 | |
|
|
1405 | target->allowedxerror = 0; |
|
|
1406 | } |
|
|
1407 | |
|
|
1408 | if (root_pixmap != None && depth != target->depth) |
|
|
1409 | { |
|
|
1410 | #if XRENDER |
|
|
1411 | Display *dpy = target->dpy; |
|
|
1412 | XRenderPictureAttributes pa; |
|
|
1413 | |
|
|
1414 | XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, target->display->screen)); |
|
|
1415 | Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, &pa); |
|
|
1416 | |
|
|
1417 | if (recoded_root_pmap) |
|
|
1418 | XFreePixmap (dpy, recoded_root_pmap); |
|
|
1419 | recoded_root_pmap = XCreatePixmap (dpy, target->vt, width, height, target->depth); |
|
|
1420 | XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, target->visual); |
|
|
1421 | Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, &pa); |
|
|
1422 | |
|
|
1423 | if (src && dst) |
|
|
1424 | { |
|
|
1425 | XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, width, height); |
|
|
1426 | root_pixmap = recoded_root_pmap; |
|
|
1427 | } |
|
|
1428 | else |
|
|
1429 | root_pixmap = None; |
|
|
1430 | |
|
|
1431 | XRenderFreePicture (dpy, src); |
|
|
1432 | XRenderFreePicture (dpy, dst); |
|
|
1433 | #else |
|
|
1434 | root_pixmap = None; |
|
|
1435 | #endif |
|
|
1436 | } |
|
|
1437 | } |
1406 | } |
1438 | # endif /* ENABLE_TRANSPARENCY */ |
1407 | # endif /* ENABLE_TRANSPARENCY */ |
1439 | |
1408 | |
1440 | # ifndef HAVE_AFTERIMAGE |
1409 | #if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) |
1441 | static void ShadeXImage(Visual *visual, XImage *srcImage, int shade, int rm, int gm, int bm); |
1410 | static void ShadeXImage(Visual *visual, XImage *srcImage, int shade, const rgba &c); |
1442 | # endif |
1411 | # endif |
1443 | |
1412 | |
1444 | bool |
1413 | bool |
1445 | bgPixmap_t::render () |
1414 | bgPixmap_t::render () |
1446 | { |
1415 | { |
… | |
… | |
1469 | if (render_image (background_flags)) |
1438 | if (render_image (background_flags)) |
1470 | flags = flags & ~isInvalid; |
1439 | flags = flags & ~isInvalid; |
1471 | } |
1440 | } |
1472 | # endif |
1441 | # endif |
1473 | |
1442 | |
|
|
1443 | # if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) |
1474 | XImage *result = NULL; |
1444 | XImage *result = NULL; |
1475 | |
1445 | |
1476 | if (background_flags && (flags & isInvalid)) |
1446 | if (background_flags && (flags & isInvalid)) |
1477 | { |
1447 | { |
1478 | result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); |
1448 | result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); |
1479 | } |
1449 | } |
1480 | |
1450 | |
1481 | if (result) |
1451 | if (result) |
1482 | { |
1452 | { |
1483 | # if !defined(HAVE_AFTERIMAGE) && !XRENDER |
|
|
1484 | /* our own client-side tinting */ |
1453 | /* our own client-side tinting */ |
1485 | if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) |
1454 | if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) |
1486 | { |
1455 | { |
1487 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
1456 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
1488 | if (flags & tintSet) |
1457 | if (flags & tintSet) |
1489 | tint.get (c); |
1458 | tint.get (c); |
1490 | ShadeXImage (DefaultVisual (target->dpy, target->display->screen), result, shade, c.r, c.g, c.b); |
1459 | ShadeXImage (DefaultVisual (target->dpy, target->display->screen), result, shade, c); |
1491 | } |
1460 | } |
1492 | # endif |
|
|
1493 | |
1461 | |
1494 | GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); |
1462 | GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); |
1495 | |
1463 | |
1496 | if (gc) |
1464 | if (gc) |
1497 | { |
1465 | { |
… | |
… | |
1501 | flags = flags & ~isInvalid; |
1469 | flags = flags & ~isInvalid; |
1502 | } |
1470 | } |
1503 | |
1471 | |
1504 | XDestroyImage (result); |
1472 | XDestroyImage (result); |
1505 | } |
1473 | } |
|
|
1474 | # endif |
1506 | |
1475 | |
1507 | if (flags & isInvalid) |
1476 | if (flags & isInvalid) |
1508 | { |
1477 | { |
1509 | if (pixmap != None) |
1478 | if (pixmap != None) |
1510 | { |
1479 | { |
… | |
… | |
1518 | valid_since = ev::now (); |
1487 | valid_since = ev::now (); |
1519 | |
1488 | |
1520 | return true; |
1489 | return true; |
1521 | } |
1490 | } |
1522 | |
1491 | |
1523 | bool |
1492 | void |
1524 | bgPixmap_t::set_target (rxvt_term *new_target) |
1493 | bgPixmap_t::set_target (rxvt_term *new_target) |
1525 | { |
1494 | { |
1526 | if (new_target) |
|
|
1527 | if (target != new_target) |
|
|
1528 | { |
|
|
1529 | target = new_target; |
1495 | target = new_target; |
1530 | return true; |
1496 | |
|
|
1497 | flags &= ~(HAS_RENDER | HAS_RENDER_CONV); |
|
|
1498 | #if XRENDER |
|
|
1499 | int major, minor; |
|
|
1500 | if (XRenderQueryVersion (target->dpy, &major, &minor)) |
|
|
1501 | flags |= HAS_RENDER; |
|
|
1502 | XFilters *filters = XRenderQueryFilters (target->dpy, target->vt); |
|
|
1503 | if (filters) |
|
|
1504 | { |
|
|
1505 | for (int i = 0; i < filters->nfilter; i++) |
|
|
1506 | if (!strcmp (filters->filter[i], FilterConvolution)) |
|
|
1507 | flags |= HAS_RENDER_CONV; |
|
|
1508 | |
|
|
1509 | XFree (filters); |
1531 | } |
1510 | } |
1532 | |
1511 | #endif |
1533 | return false; |
|
|
1534 | } |
1512 | } |
1535 | |
1513 | |
1536 | void |
1514 | void |
1537 | bgPixmap_t::apply () |
1515 | bgPixmap_t::apply () |
1538 | { |
1516 | { |
1539 | if (target) |
1517 | if (target == NULL) |
1540 | { |
1518 | return; |
|
|
1519 | |
1541 | if (pixmap != None) |
1520 | if (pixmap != None) |
1542 | { |
1521 | { |
1543 | /* set target's background to pixmap */ |
1522 | /* set target's background to pixmap */ |
1544 | # ifdef ENABLE_TRANSPARENCY |
1523 | # ifdef ENABLE_TRANSPARENCY |
1545 | if (flags & isTransparent) |
1524 | if (flags & isTransparent) |
1546 | { |
1525 | { |
1547 | XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap); |
1526 | XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap); |
1548 | XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative); |
1527 | XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative); |
1549 | |
1528 | |
1550 | if (target->scrollBar.win) |
1529 | if (target->scrollBar.win) |
1551 | XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative); |
1530 | XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative); |
1552 | } |
1531 | } |
1553 | else |
1532 | else |
1554 | # endif |
1533 | # endif |
1555 | { |
1534 | { |
1556 | /* force old pixmap dereference in case it was transparent before :*/ |
1535 | /* force old pixmap dereference in case it was transparent before :*/ |
1557 | XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); |
|
|
1558 | XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap); |
|
|
1559 | /* do we also need to set scrollbar's background here ? */ |
|
|
1560 | |
|
|
1561 | if (target->scrollBar.win) |
|
|
1562 | XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); |
|
|
1563 | } |
|
|
1564 | } |
|
|
1565 | else |
|
|
1566 | { |
|
|
1567 | /* set target background to a pixel */ |
|
|
1568 | XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); |
1536 | XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); |
1569 | XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); |
1537 | XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap); |
1570 | /* do we also need to set scrollbar's background here ? */ |
1538 | /* do we also need to set scrollbar's background here ? */ |
|
|
1539 | |
1571 | if (target->scrollBar.win) |
1540 | if (target->scrollBar.win) |
1572 | XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); |
1541 | XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); |
1573 | } |
1542 | } |
|
|
1543 | } |
|
|
1544 | else |
|
|
1545 | { |
|
|
1546 | /* set target background to a pixel */ |
|
|
1547 | XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); |
|
|
1548 | XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); |
|
|
1549 | /* do we also need to set scrollbar's background here ? */ |
|
|
1550 | if (target->scrollBar.win) |
|
|
1551 | XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); |
|
|
1552 | } |
1574 | |
1553 | |
1575 | /* don't want Expose on the parent or vt. It is better to use |
1554 | /* don't want Expose on the parent or vt. It is better to use |
1576 | scr_touch or we get a great deal of flicker otherwise: */ |
1555 | scr_touch or we get a great deal of flicker otherwise: */ |
1577 | XClearWindow (target->dpy, target->parent[0]); |
1556 | XClearWindow (target->dpy, target->parent[0]); |
1578 | |
1557 | |
1579 | if (target->scrollBar.state && target->scrollBar.win) |
1558 | if (target->scrollBar.state && target->scrollBar.win) |
1580 | { |
1559 | { |
1581 | target->scrollBar.state = STATE_IDLE; |
1560 | target->scrollBar.state = STATE_IDLE; |
1582 | target->scrollBar.show (0); |
1561 | target->scrollBar.show (0); |
1583 | } |
1562 | } |
1584 | |
1563 | |
1585 | target->want_refresh = 1; |
1564 | target->want_refresh = 1; |
1586 | flags |= hasChanged; |
1565 | flags |= hasChanged; |
1587 | } |
|
|
1588 | } |
1566 | } |
1589 | |
1567 | |
1590 | #endif /* HAVE_BG_PIXMAP */ |
1568 | #endif /* HAVE_BG_PIXMAP */ |
1591 | |
1569 | |
1592 | #if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) && !XRENDER |
1570 | #if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) |
1593 | /* taken from aterm-0.4.2 */ |
1571 | /* taken from aterm-0.4.2 */ |
1594 | |
1572 | |
1595 | static void |
1573 | static void |
1596 | ShadeXImage(Visual *visual, XImage *srcImage, int shade, int rm, int gm, int bm) |
1574 | ShadeXImage(Visual *visual, XImage *srcImage, int shade, const rgba &c) |
1597 | { |
1575 | { |
1598 | int sh_r, sh_g, sh_b; |
1576 | int sh_r, sh_g, sh_b; |
1599 | uint32_t mask_r, mask_g, mask_b; |
1577 | uint32_t mask_r, mask_g, mask_b; |
1600 | uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; |
1578 | uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; |
1601 | unsigned int lower_lim_r, lower_lim_g, lower_lim_b; |
1579 | rgba low; |
1602 | unsigned int upper_lim_r, upper_lim_g, upper_lim_b; |
1580 | rgba high; |
1603 | int i; |
1581 | int i; |
1604 | int host_byte_order = byteorder.big_endian () ? MSBFirst : LSBFirst; |
1582 | int host_byte_order = byteorder.big_endian () ? MSBFirst : LSBFirst; |
1605 | |
1583 | |
1606 | if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return; |
1584 | if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return; |
1607 | |
1585 | |
… | |
… | |
1672 | /* prepare limits for color transformation (each channel is handled separately) */ |
1650 | /* prepare limits for color transformation (each channel is handled separately) */ |
1673 | if (shade > 100) |
1651 | if (shade > 100) |
1674 | { |
1652 | { |
1675 | shade = 200 - shade; |
1653 | shade = 200 - shade; |
1676 | |
1654 | |
1677 | lower_lim_r = 65535-rm; |
1655 | high.r = (65535 - c.r) * shade / 100; |
1678 | lower_lim_g = 65535-gm; |
1656 | high.g = (65535 - c.g) * shade / 100; |
1679 | lower_lim_b = 65535-bm; |
1657 | high.b = (65535 - c.b) * shade / 100; |
1680 | |
1658 | |
1681 | lower_lim_r = 65535-(unsigned int)(((uint32_t)lower_lim_r)*((uint32_t)shade)/100); |
1659 | low.r = 65535 - high.r; |
1682 | lower_lim_g = 65535-(unsigned int)(((uint32_t)lower_lim_g)*((uint32_t)shade)/100); |
1660 | low.g = 65535 - high.g; |
1683 | lower_lim_b = 65535-(unsigned int)(((uint32_t)lower_lim_b)*((uint32_t)shade)/100); |
1661 | low.b = 65535 - high.b; |
1684 | |
|
|
1685 | upper_lim_r = upper_lim_g = upper_lim_b = 65535; |
|
|
1686 | } |
1662 | } |
1687 | else |
1663 | else |
1688 | { |
1664 | { |
|
|
1665 | high.r = c.r * shade / 100; |
|
|
1666 | high.g = c.g * shade / 100; |
|
|
1667 | high.b = c.b * shade / 100; |
1689 | |
1668 | |
1690 | lower_lim_r = lower_lim_g = lower_lim_b = 0; |
1669 | low.r = low.g = low.b = 0; |
1691 | |
|
|
1692 | upper_lim_r = (unsigned int)((((uint32_t)rm)*((uint32_t)shade))/100); |
|
|
1693 | upper_lim_g = (unsigned int)((((uint32_t)gm)*((uint32_t)shade))/100); |
|
|
1694 | upper_lim_b = (unsigned int)((((uint32_t)bm)*((uint32_t)shade))/100); |
|
|
1695 | } |
1670 | } |
1696 | |
1671 | |
1697 | /* fill our lookup tables */ |
1672 | /* fill our lookup tables */ |
1698 | for (i = 0; i <= mask_r>>sh_r; i++) |
1673 | for (i = 0; i <= mask_r>>sh_r; i++) |
1699 | { |
1674 | { |
1700 | uint32_t tmp; |
1675 | uint32_t tmp; |
1701 | tmp = ((uint32_t)i)*((uint32_t)(upper_lim_r-lower_lim_r)); |
1676 | tmp = i * high.r; |
1702 | tmp += ((uint32_t)(mask_r>>sh_r))*((uint32_t)lower_lim_r); |
1677 | tmp += (mask_r>>sh_r) * low.r; |
1703 | lookup_r[i] = (tmp/65535)<<sh_r; |
1678 | lookup_r[i] = (tmp/65535)<<sh_r; |
1704 | } |
1679 | } |
1705 | for (i = 0; i <= mask_g>>sh_g; i++) |
1680 | for (i = 0; i <= mask_g>>sh_g; i++) |
1706 | { |
1681 | { |
1707 | uint32_t tmp; |
1682 | uint32_t tmp; |
1708 | tmp = ((uint32_t)i)*((uint32_t)(upper_lim_g-lower_lim_g)); |
1683 | tmp = i * high.g; |
1709 | tmp += ((uint32_t)(mask_g>>sh_g))*((uint32_t)lower_lim_g); |
1684 | tmp += (mask_g>>sh_g) * low.g; |
1710 | lookup_g[i] = (tmp/65535)<<sh_g; |
1685 | lookup_g[i] = (tmp/65535)<<sh_g; |
1711 | } |
1686 | } |
1712 | for (i = 0; i <= mask_b>>sh_b; i++) |
1687 | for (i = 0; i <= mask_b>>sh_b; i++) |
1713 | { |
1688 | { |
1714 | uint32_t tmp; |
1689 | uint32_t tmp; |
1715 | tmp = ((uint32_t)i)*((uint32_t)(upper_lim_b-lower_lim_b)); |
1690 | tmp = i * high.b; |
1716 | tmp += ((uint32_t)(mask_b>>sh_b))*((uint32_t)lower_lim_b); |
1691 | tmp += (mask_b>>sh_b) * low.b; |
1717 | lookup_b[i] = (tmp/65535)<<sh_b; |
1692 | lookup_b[i] = (tmp/65535)<<sh_b; |
1718 | } |
1693 | } |
1719 | |
1694 | |
1720 | /* apply table to input image (replacing colors by newly calculated ones) */ |
1695 | /* apply table to input image (replacing colors by newly calculated ones) */ |
1721 | if (srcImage->bits_per_pixel == 32 |
1696 | if (srcImage->bits_per_pixel == 32 |