… | |
… | |
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> |
… | |
… | |
168 | return true; |
176 | return true; |
169 | } |
177 | } |
170 | # endif |
178 | # endif |
171 | |
179 | |
172 | return false; |
180 | return false; |
173 | }; |
181 | } |
174 | |
182 | |
175 | bool bgPixmap_t::need_client_side_rendering () |
183 | bool bgPixmap_t::need_client_side_rendering () |
176 | { |
184 | { |
177 | # ifdef HAVE_AFTERIMAGE |
185 | # ifdef HAVE_AFTERIMAGE |
178 | if (original_asim) |
186 | if (original_asim) |
… | |
… | |
250 | } |
258 | } |
251 | |
259 | |
252 | bool |
260 | bool |
253 | bgPixmap_t::set_geometry (const char *geom) |
261 | bgPixmap_t::set_geometry (const char *geom) |
254 | { |
262 | { |
|
|
263 | bool changed = false; |
255 | int geom_flags = 0, changed = 0; |
264 | int geom_flags = 0; |
256 | int x = 0, y = 0; |
265 | int x = 0, y = 0; |
257 | unsigned int w = 0, h = 0; |
266 | unsigned int w = 0, h = 0; |
258 | unsigned int n; |
267 | unsigned int n; |
259 | unsigned long new_flags = (flags & (~geometryFlags)); |
268 | unsigned long new_flags = (flags & (~geometryFlags)); |
260 | const char *p; |
269 | const char *p; |
… | |
… | |
416 | |
425 | |
417 | while (*ops != ':' && *ops != '\0') ++ops; |
426 | while (*ops != ':' && *ops != '\0') ++ops; |
418 | } /* done parsing ops */ |
427 | } /* done parsing ops */ |
419 | } |
428 | } |
420 | |
429 | |
421 | 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; |
422 | 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; |
423 | 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; |
424 | 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; |
425 | } |
434 | } |
426 | |
435 | |
427 | if (new_flags != flags) |
436 | if (new_flags != flags) |
428 | { |
437 | { |
429 | flags = new_flags; |
438 | flags = new_flags; |
430 | changed++; |
439 | changed = true; |
431 | } |
440 | } |
432 | |
441 | |
433 | return (changed > 0); |
442 | return changed; |
434 | } |
443 | } |
435 | |
444 | |
436 | void |
445 | void |
437 | 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) |
438 | { |
447 | { |
… | |
… | |
661 | if (result) |
670 | if (result) |
662 | { |
671 | { |
663 | XGCValues gcv; |
672 | XGCValues gcv; |
664 | GC gc; |
673 | GC gc; |
665 | |
674 | |
666 | if (pixmap) |
|
|
667 | { |
|
|
668 | if (pmap_width != new_pmap_width |
|
|
669 | || pmap_height != new_pmap_height |
|
|
670 | || pmap_depth != target->depth) |
|
|
671 | { |
|
|
672 | XFreePixmap (target->dpy, pixmap); |
|
|
673 | pixmap = None; |
|
|
674 | } |
|
|
675 | } |
|
|
676 | |
|
|
677 | /* create Pixmap */ |
675 | /* create Pixmap */ |
678 | if (pixmap == None) |
676 | if (pixmap == None |
|
|
677 | || pmap_width != new_pmap_width |
|
|
678 | || pmap_height != new_pmap_height |
|
|
679 | || pmap_depth != target->depth) |
679 | { |
680 | { |
|
|
681 | if (pixmap) |
|
|
682 | XFreePixmap (target->dpy, pixmap); |
680 | 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); |
681 | pmap_width = new_pmap_width; |
684 | pmap_width = new_pmap_width; |
682 | pmap_height = new_pmap_height; |
685 | pmap_height = new_pmap_height; |
683 | pmap_depth = target->depth; |
686 | pmap_depth = target->depth; |
684 | } |
687 | } |
… | |
… | |
729 | return false; |
732 | return false; |
730 | |
733 | |
731 | if (!pixbuf) |
734 | if (!pixbuf) |
732 | return false; |
735 | return false; |
733 | |
736 | |
734 | #if !XRENDER |
|
|
735 | if (background_flags) |
737 | if (background_flags |
|
|
738 | && !(flags & HAS_RENDER)) |
736 | return false; |
739 | return false; |
737 | #endif |
|
|
738 | |
740 | |
739 | GdkPixbuf *result; |
741 | GdkPixbuf *result; |
740 | |
742 | |
741 | int image_width = gdk_pixbuf_get_width (pixbuf); |
743 | int image_width = gdk_pixbuf_get_width (pixbuf); |
742 | int image_height = gdk_pixbuf_get_height (pixbuf); |
744 | int image_height = gdk_pixbuf_get_height (pixbuf); |
… | |
… | |
793 | new_pmap_width = min (image_width, target_width); |
795 | new_pmap_width = min (image_width, target_width); |
794 | new_pmap_height = min (image_height, target_height); |
796 | new_pmap_height = min (image_height, target_height); |
795 | } |
797 | } |
796 | } |
798 | } |
797 | |
799 | |
798 | if (pixmap) |
|
|
799 | { |
|
|
800 | if (pmap_width != new_pmap_width |
|
|
801 | || pmap_height != new_pmap_height |
|
|
802 | || pmap_depth != target->depth) |
|
|
803 | { |
|
|
804 | XFreePixmap (target->dpy, pixmap); |
|
|
805 | pixmap = None; |
|
|
806 | } |
|
|
807 | } |
|
|
808 | |
|
|
809 | if (pixmap == None) |
800 | if (pixmap == None |
|
|
801 | || pmap_width != new_pmap_width |
|
|
802 | || pmap_height != new_pmap_height |
|
|
803 | || pmap_depth != target->depth) |
810 | { |
804 | { |
|
|
805 | if (pixmap) |
|
|
806 | XFreePixmap (target->dpy, pixmap); |
811 | 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); |
812 | pmap_width = new_pmap_width; |
808 | pmap_width = new_pmap_width; |
813 | pmap_height = new_pmap_height; |
809 | pmap_height = new_pmap_height; |
814 | pmap_depth = target->depth; |
810 | pmap_depth = target->depth; |
815 | } |
811 | } |
… | |
… | |
909 | # endif /* HAVE_PIXBUF */ |
905 | # endif /* HAVE_PIXBUF */ |
910 | |
906 | |
911 | bool |
907 | bool |
912 | bgPixmap_t::set_file (const char *file) |
908 | bgPixmap_t::set_file (const char *file) |
913 | { |
909 | { |
914 | assert (file); |
910 | if (!file || !*file) |
|
|
911 | return false; |
915 | |
912 | |
916 | if (*file) |
|
|
917 | { |
|
|
918 | if (const char *p = strchr (file, ';')) |
913 | if (const char *p = strchr (file, ';')) |
919 | { |
914 | { |
920 | size_t len = p - file; |
915 | size_t len = p - file; |
921 | char *f = rxvt_temp_buf<char> (len + 1); |
916 | char *f = rxvt_temp_buf<char> (len + 1); |
922 | memcpy (f, file, len); |
917 | memcpy (f, file, len); |
923 | f[len] = '\0'; |
918 | f[len] = '\0'; |
924 | file = f; |
919 | file = f; |
925 | } |
920 | } |
926 | |
921 | |
927 | # ifdef HAVE_AFTERIMAGE |
922 | # ifdef HAVE_AFTERIMAGE |
928 | if (!target->asimman) |
923 | if (!target->asimman) |
929 | target->asimman = create_generic_imageman (target->rs[Rs_path]); |
924 | target->asimman = create_generic_imageman (target->rs[Rs_path]); |
930 | ASImage *image = get_asimage (target->asimman, file, 0xFFFFFFFF, 100); |
925 | ASImage *image = get_asimage (target->asimman, file, 0xFFFFFFFF, 100); |
931 | if (image) |
926 | if (image) |
932 | { |
927 | { |
933 | if (original_asim) |
928 | if (original_asim) |
934 | safe_asimage_destroy (original_asim); |
929 | safe_asimage_destroy (original_asim); |
935 | original_asim = image; |
930 | original_asim = image; |
936 | have_image = true; |
931 | have_image = true; |
937 | return true; |
932 | return true; |
938 | } |
933 | } |
939 | # endif |
934 | # endif |
940 | |
935 | |
941 | # ifdef HAVE_PIXBUF |
936 | # ifdef HAVE_PIXBUF |
942 | GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); |
937 | GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); |
943 | if (image) |
938 | if (image) |
944 | { |
939 | { |
945 | if (pixbuf) |
940 | if (pixbuf) |
946 | g_object_unref (pixbuf); |
941 | g_object_unref (pixbuf); |
947 | pixbuf = image; |
942 | pixbuf = image; |
948 | have_image = true; |
943 | have_image = true; |
949 | return true; |
944 | return true; |
950 | } |
945 | } |
951 | # endif |
946 | # endif |
952 | } |
|
|
953 | |
947 | |
954 | return false; |
948 | return false; |
955 | } |
949 | } |
956 | |
950 | |
957 | # endif /* BG_IMAGE_FROM_FILE */ |
951 | # endif /* BG_IMAGE_FROM_FILE */ |
… | |
… | |
970 | } |
964 | } |
971 | |
965 | |
972 | bool |
966 | bool |
973 | bgPixmap_t::set_blur_radius (const char *geom) |
967 | bgPixmap_t::set_blur_radius (const char *geom) |
974 | { |
968 | { |
975 | int changed = 0; |
969 | bool changed = false; |
976 | unsigned int hr, vr; |
970 | unsigned int hr, vr; |
977 | int junk; |
971 | int junk; |
978 | int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); |
972 | int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); |
979 | |
973 | |
980 | if (!(geom_flags & WidthValue)) |
974 | if (!(geom_flags & WidthValue)) |
… | |
… | |
985 | min_it (hr, 128); |
979 | min_it (hr, 128); |
986 | min_it (vr, 128); |
980 | min_it (vr, 128); |
987 | |
981 | |
988 | if (h_blurRadius != hr) |
982 | if (h_blurRadius != hr) |
989 | { |
983 | { |
990 | ++changed; |
984 | changed = true; |
991 | h_blurRadius = hr; |
985 | h_blurRadius = hr; |
992 | } |
986 | } |
993 | |
987 | |
994 | if (v_blurRadius != vr) |
988 | if (v_blurRadius != vr) |
995 | { |
989 | { |
996 | ++changed; |
990 | changed = true; |
997 | v_blurRadius = vr; |
991 | v_blurRadius = vr; |
998 | } |
992 | } |
999 | |
993 | |
1000 | if (v_blurRadius == 0 && h_blurRadius == 0) |
994 | if (v_blurRadius == 0 && h_blurRadius == 0) |
1001 | flags &= ~blurNeeded; |
995 | flags &= ~blurNeeded; |
1002 | else |
996 | else |
1003 | flags |= blurNeeded; |
997 | flags |= blurNeeded; |
1004 | |
998 | |
1005 | #if XRENDER |
|
|
1006 | XFilters *filters = XRenderQueryFilters (target->dpy, target->vt); |
|
|
1007 | if (filters) |
|
|
1008 | { |
|
|
1009 | for (int i = 0; i < filters->nfilter; i++) |
|
|
1010 | if (!strcmp (filters->filter[i], FilterConvolution)) |
|
|
1011 | flags |= bgPixmap_t::blurServerSide; |
|
|
1012 | |
|
|
1013 | XFree (filters); |
|
|
1014 | } |
|
|
1015 | #endif |
|
|
1016 | |
|
|
1017 | return (changed > 0); |
999 | return changed; |
1018 | } |
1000 | } |
1019 | |
1001 | |
1020 | static inline unsigned long |
1002 | static inline unsigned long |
1021 | compute_tint_shade_flags (rxvt_color *tint, int shade) |
1003 | compute_tint_shade_flags (rxvt_color *tint, int shade) |
1022 | { |
1004 | { |
… | |
… | |
1041 | { |
1023 | { |
1042 | if ((c.r > 0x000700 || c.g > 0x000700 || c.b > 0x000700) |
1024 | if ((c.r > 0x000700 || c.g > 0x000700 || c.b > 0x000700) |
1043 | && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700)) |
1025 | && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700)) |
1044 | { |
1026 | { |
1045 | flags |= bgPixmap_t::tintNeeded; |
1027 | flags |= bgPixmap_t::tintNeeded; |
1046 | } |
|
|
1047 | } |
|
|
1048 | |
|
|
1049 | if (flags & bgPixmap_t::tintNeeded) |
|
|
1050 | { |
|
|
1051 | if (flags & bgPixmap_t::tintWholesome) |
|
|
1052 | flags |= bgPixmap_t::tintServerSide; |
|
|
1053 | else |
|
|
1054 | { |
|
|
1055 | #if XRENDER |
|
|
1056 | flags |= bgPixmap_t::tintServerSide; |
|
|
1057 | #endif |
|
|
1058 | } |
1028 | } |
1059 | } |
1029 | } |
1060 | |
1030 | |
1061 | return flags; |
1031 | return flags; |
1062 | } |
1032 | } |
… | |
… | |
1261 | |
1231 | |
1262 | if (mask_pic && overlay_pic && back_pic) |
1232 | if (mask_pic && overlay_pic && back_pic) |
1263 | { |
1233 | { |
1264 | XRenderColor mask_c; |
1234 | XRenderColor mask_c; |
1265 | |
1235 | |
1266 | memset (&mask_c, (shade > 100) ? 0xFF : 0x0, sizeof (mask_c)); |
1236 | mask_c.red = mask_c.green = mask_c.blue = shade > 100 ? 0xffff : 0; |
1267 | mask_c.alpha = 0xffff; |
1237 | mask_c.alpha = 0xffff; |
1268 | XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); |
1238 | XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); |
1269 | |
1239 | |
1270 | mask_c.alpha = 0; |
1240 | mask_c.alpha = 0; |
1271 | mask_c.red = 0xffff - c.r; |
1241 | mask_c.red = 0xffff - c.r; |
… | |
… | |
1338 | Pixmap recoded_root_pmap = root_pixmap; |
1308 | Pixmap recoded_root_pmap = root_pixmap; |
1339 | |
1309 | |
1340 | if (root_pixmap != None && root_depth != target->depth) |
1310 | if (root_pixmap != None && root_depth != target->depth) |
1341 | { |
1311 | { |
1342 | #if XRENDER |
1312 | #if XRENDER |
|
|
1313 | if (flags & HAS_RENDER) |
|
|
1314 | { |
1343 | XRenderPictureAttributes pa; |
1315 | XRenderPictureAttributes pa; |
1344 | |
1316 | |
1345 | XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen)); |
1317 | XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen)); |
1346 | Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, &pa); |
1318 | Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, &pa); |
1347 | |
1319 | |
1348 | recoded_root_pmap = XCreatePixmap (dpy, target->vt, root_pmap_width, root_pmap_height, target->depth); |
1320 | recoded_root_pmap = XCreatePixmap (dpy, target->vt, root_pmap_width, root_pmap_height, target->depth); |
1349 | XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, target->visual); |
1321 | XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, target->visual); |
1350 | Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, &pa); |
1322 | Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, &pa); |
1351 | |
1323 | |
1352 | if (src && dst) |
1324 | if (src && dst) |
1353 | XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, root_pmap_width, root_pmap_height); |
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 | } |
1354 | else |
1335 | else |
1355 | root_pixmap = None; |
1336 | #endif |
1356 | |
|
|
1357 | XRenderFreePicture (dpy, src); |
|
|
1358 | XRenderFreePicture (dpy, dst); |
|
|
1359 | #else |
|
|
1360 | root_pixmap = None; |
1337 | root_pixmap = None; |
1361 | #endif |
|
|
1362 | } |
1338 | } |
1363 | |
1339 | |
1364 | if (root_pixmap == None) |
1340 | if (root_pixmap == None) |
1365 | return 0; |
1341 | return 0; |
1366 | |
1342 | |
… | |
… | |
1383 | if (gc) |
1359 | if (gc) |
1384 | { |
1360 | { |
1385 | 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); |
1386 | result |= transpPmapTiled; |
1362 | result |= transpPmapTiled; |
1387 | XFreeGC (dpy, gc); |
1363 | XFreeGC (dpy, gc); |
1388 | } |
|
|
1389 | |
1364 | |
1390 | if (tiled_root_pmap != None) |
|
|
1391 | { |
|
|
1392 | if (!need_client_side_rendering ()) |
1365 | if (!need_client_side_rendering ()) |
1393 | { |
1366 | { |
1394 | if (flags & (blurNeeded | blurServerSide)) |
1367 | if ((flags & blurNeeded) |
|
|
1368 | && (flags & HAS_RENDER_CONV)) |
1395 | { |
1369 | { |
1396 | 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)) |
1397 | result |= transpPmapBlurred; |
1371 | result |= transpPmapBlurred; |
1398 | } |
1372 | } |
1399 | if (flags & (tintNeeded | tintServerSide)) |
1373 | if ((flags & tintNeeded) |
|
|
1374 | && (flags & (tintWholesome | HAS_RENDER))) |
1400 | { |
1375 | { |
1401 | 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)) |
1402 | result |= transpPmapTinted; |
1377 | result |= transpPmapTinted; |
1403 | } |
1378 | } |
1404 | } /* server side rendering completed */ |
1379 | } /* server side rendering completed */ |
… | |
… | |
1409 | pixmap = tiled_root_pmap; |
1384 | pixmap = tiled_root_pmap; |
1410 | pmap_width = window_width; |
1385 | pmap_width = window_width; |
1411 | pmap_height = window_height; |
1386 | pmap_height = window_height; |
1412 | pmap_depth = target->depth; |
1387 | pmap_depth = target->depth; |
1413 | } |
1388 | } |
|
|
1389 | else |
|
|
1390 | XFreePixmap (dpy, tiled_root_pmap); |
1414 | |
1391 | |
1415 | if (recoded_root_pmap != root_pixmap) |
1392 | if (recoded_root_pmap != root_pixmap) |
1416 | XFreePixmap (dpy, recoded_root_pmap); |
1393 | XFreePixmap (dpy, recoded_root_pmap); |
1417 | |
1394 | |
1418 | return result; |
1395 | return result; |
… | |
… | |
1427 | |
1404 | |
1428 | root_pixmap = new_root_pixmap; |
1405 | root_pixmap = new_root_pixmap; |
1429 | } |
1406 | } |
1430 | # endif /* ENABLE_TRANSPARENCY */ |
1407 | # endif /* ENABLE_TRANSPARENCY */ |
1431 | |
1408 | |
1432 | # ifndef HAVE_AFTERIMAGE |
1409 | #if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) |
1433 | 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); |
1434 | # endif |
1411 | # endif |
1435 | |
1412 | |
1436 | bool |
1413 | bool |
1437 | bgPixmap_t::render () |
1414 | bgPixmap_t::render () |
1438 | { |
1415 | { |
… | |
… | |
1461 | if (render_image (background_flags)) |
1438 | if (render_image (background_flags)) |
1462 | flags = flags & ~isInvalid; |
1439 | flags = flags & ~isInvalid; |
1463 | } |
1440 | } |
1464 | # endif |
1441 | # endif |
1465 | |
1442 | |
|
|
1443 | # if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) |
1466 | XImage *result = NULL; |
1444 | XImage *result = NULL; |
1467 | |
1445 | |
1468 | if (background_flags && (flags & isInvalid)) |
1446 | if (background_flags && (flags & isInvalid)) |
1469 | { |
1447 | { |
1470 | 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); |
1471 | } |
1449 | } |
1472 | |
1450 | |
1473 | if (result) |
1451 | if (result) |
1474 | { |
1452 | { |
1475 | # if !defined(HAVE_AFTERIMAGE) && !XRENDER |
|
|
1476 | /* our own client-side tinting */ |
1453 | /* our own client-side tinting */ |
1477 | if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) |
1454 | if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) |
1478 | { |
1455 | { |
1479 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
1456 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
1480 | if (flags & tintSet) |
1457 | if (flags & tintSet) |
1481 | tint.get (c); |
1458 | tint.get (c); |
1482 | 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); |
1483 | } |
1460 | } |
1484 | # endif |
|
|
1485 | |
1461 | |
1486 | GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); |
1462 | GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); |
1487 | |
1463 | |
1488 | if (gc) |
1464 | if (gc) |
1489 | { |
1465 | { |
… | |
… | |
1493 | flags = flags & ~isInvalid; |
1469 | flags = flags & ~isInvalid; |
1494 | } |
1470 | } |
1495 | |
1471 | |
1496 | XDestroyImage (result); |
1472 | XDestroyImage (result); |
1497 | } |
1473 | } |
|
|
1474 | # endif |
1498 | |
1475 | |
1499 | if (flags & isInvalid) |
1476 | if (flags & isInvalid) |
1500 | { |
1477 | { |
1501 | if (pixmap != None) |
1478 | if (pixmap != None) |
1502 | { |
1479 | { |
… | |
… | |
1510 | valid_since = ev::now (); |
1487 | valid_since = ev::now (); |
1511 | |
1488 | |
1512 | return true; |
1489 | return true; |
1513 | } |
1490 | } |
1514 | |
1491 | |
1515 | bool |
1492 | void |
1516 | bgPixmap_t::set_target (rxvt_term *new_target) |
1493 | bgPixmap_t::set_target (rxvt_term *new_target) |
1517 | { |
1494 | { |
1518 | if (new_target) |
|
|
1519 | if (target != new_target) |
|
|
1520 | { |
|
|
1521 | target = new_target; |
1495 | target = new_target; |
1522 | 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); |
1523 | } |
1510 | } |
1524 | |
1511 | #endif |
1525 | return false; |
|
|
1526 | } |
1512 | } |
1527 | |
1513 | |
1528 | void |
1514 | void |
1529 | bgPixmap_t::apply () |
1515 | bgPixmap_t::apply () |
1530 | { |
1516 | { |
1531 | if (target) |
1517 | if (target == NULL) |
1532 | { |
1518 | return; |
|
|
1519 | |
1533 | if (pixmap != None) |
1520 | if (pixmap != None) |
1534 | { |
1521 | { |
1535 | /* set target's background to pixmap */ |
1522 | /* set target's background to pixmap */ |
1536 | # ifdef ENABLE_TRANSPARENCY |
1523 | # ifdef ENABLE_TRANSPARENCY |
1537 | if (flags & isTransparent) |
1524 | if (flags & isTransparent) |
1538 | { |
1525 | { |
1539 | XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap); |
1526 | XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap); |
1540 | XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative); |
1527 | XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative); |
1541 | |
1528 | |
1542 | if (target->scrollBar.win) |
1529 | if (target->scrollBar.win) |
1543 | XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative); |
1530 | XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative); |
1544 | } |
1531 | } |
1545 | else |
1532 | else |
1546 | # endif |
1533 | # endif |
1547 | { |
1534 | { |
1548 | /* force old pixmap dereference in case it was transparent before :*/ |
1535 | /* force old pixmap dereference in case it was transparent before :*/ |
1549 | XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); |
|
|
1550 | XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap); |
|
|
1551 | /* do we also need to set scrollbar's background here ? */ |
|
|
1552 | |
|
|
1553 | if (target->scrollBar.win) |
|
|
1554 | XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); |
|
|
1555 | } |
|
|
1556 | } |
|
|
1557 | else |
|
|
1558 | { |
|
|
1559 | /* set target background to a pixel */ |
|
|
1560 | XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); |
1536 | XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); |
1561 | XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); |
1537 | XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap); |
1562 | /* do we also need to set scrollbar's background here ? */ |
1538 | /* do we also need to set scrollbar's background here ? */ |
|
|
1539 | |
1563 | if (target->scrollBar.win) |
1540 | if (target->scrollBar.win) |
1564 | XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); |
1541 | XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); |
1565 | } |
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 | } |
1566 | |
1553 | |
1567 | /* 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 |
1568 | scr_touch or we get a great deal of flicker otherwise: */ |
1555 | scr_touch or we get a great deal of flicker otherwise: */ |
1569 | XClearWindow (target->dpy, target->parent[0]); |
1556 | XClearWindow (target->dpy, target->parent[0]); |
1570 | |
1557 | |
1571 | if (target->scrollBar.state && target->scrollBar.win) |
1558 | if (target->scrollBar.state && target->scrollBar.win) |
1572 | { |
1559 | { |
1573 | target->scrollBar.state = STATE_IDLE; |
1560 | target->scrollBar.state = STATE_IDLE; |
1574 | target->scrollBar.show (0); |
1561 | target->scrollBar.show (0); |
1575 | } |
1562 | } |
1576 | |
1563 | |
1577 | target->want_refresh = 1; |
1564 | target->want_refresh = 1; |
1578 | flags |= hasChanged; |
1565 | flags |= hasChanged; |
1579 | } |
|
|
1580 | } |
1566 | } |
1581 | |
1567 | |
1582 | #endif /* HAVE_BG_PIXMAP */ |
1568 | #endif /* HAVE_BG_PIXMAP */ |
1583 | |
1569 | |
1584 | #if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) && !XRENDER |
1570 | #if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) |
1585 | /* taken from aterm-0.4.2 */ |
1571 | /* taken from aterm-0.4.2 */ |
1586 | |
1572 | |
1587 | static void |
1573 | static void |
1588 | ShadeXImage(Visual *visual, XImage *srcImage, int shade, int rm, int gm, int bm) |
1574 | ShadeXImage(Visual *visual, XImage *srcImage, int shade, const rgba &c) |
1589 | { |
1575 | { |
1590 | int sh_r, sh_g, sh_b; |
1576 | int sh_r, sh_g, sh_b; |
1591 | uint32_t mask_r, mask_g, mask_b; |
1577 | uint32_t mask_r, mask_g, mask_b; |
1592 | uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; |
1578 | uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; |
1593 | unsigned int lower_lim_r, lower_lim_g, lower_lim_b; |
1579 | rgba low; |
1594 | unsigned int upper_lim_r, upper_lim_g, upper_lim_b; |
1580 | rgba high; |
1595 | int i; |
1581 | int i; |
1596 | int host_byte_order = byteorder.big_endian () ? MSBFirst : LSBFirst; |
1582 | int host_byte_order = byteorder.big_endian () ? MSBFirst : LSBFirst; |
1597 | |
1583 | |
1598 | if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return; |
1584 | if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return; |
1599 | |
1585 | |
… | |
… | |
1664 | /* prepare limits for color transformation (each channel is handled separately) */ |
1650 | /* prepare limits for color transformation (each channel is handled separately) */ |
1665 | if (shade > 100) |
1651 | if (shade > 100) |
1666 | { |
1652 | { |
1667 | shade = 200 - shade; |
1653 | shade = 200 - shade; |
1668 | |
1654 | |
1669 | lower_lim_r = 65535-rm; |
1655 | high.r = (65535 - c.r) * shade / 100; |
1670 | lower_lim_g = 65535-gm; |
1656 | high.g = (65535 - c.g) * shade / 100; |
1671 | lower_lim_b = 65535-bm; |
1657 | high.b = (65535 - c.b) * shade / 100; |
1672 | |
1658 | |
1673 | lower_lim_r = 65535-(unsigned int)(((uint32_t)lower_lim_r)*((uint32_t)shade)/100); |
1659 | low.r = 65535 - high.r; |
1674 | lower_lim_g = 65535-(unsigned int)(((uint32_t)lower_lim_g)*((uint32_t)shade)/100); |
1660 | low.g = 65535 - high.g; |
1675 | lower_lim_b = 65535-(unsigned int)(((uint32_t)lower_lim_b)*((uint32_t)shade)/100); |
1661 | low.b = 65535 - high.b; |
1676 | |
|
|
1677 | upper_lim_r = upper_lim_g = upper_lim_b = 65535; |
|
|
1678 | } |
1662 | } |
1679 | else |
1663 | else |
1680 | { |
1664 | { |
|
|
1665 | high.r = c.r * shade / 100; |
|
|
1666 | high.g = c.g * shade / 100; |
|
|
1667 | high.b = c.b * shade / 100; |
1681 | |
1668 | |
1682 | lower_lim_r = lower_lim_g = lower_lim_b = 0; |
1669 | low.r = low.g = low.b = 0; |
1683 | |
|
|
1684 | upper_lim_r = (unsigned int)((((uint32_t)rm)*((uint32_t)shade))/100); |
|
|
1685 | upper_lim_g = (unsigned int)((((uint32_t)gm)*((uint32_t)shade))/100); |
|
|
1686 | upper_lim_b = (unsigned int)((((uint32_t)bm)*((uint32_t)shade))/100); |
|
|
1687 | } |
1670 | } |
1688 | |
1671 | |
1689 | /* fill our lookup tables */ |
1672 | /* fill our lookup tables */ |
1690 | for (i = 0; i <= mask_r>>sh_r; i++) |
1673 | for (i = 0; i <= mask_r>>sh_r; i++) |
1691 | { |
1674 | { |
1692 | uint32_t tmp; |
1675 | uint32_t tmp; |
1693 | tmp = ((uint32_t)i)*((uint32_t)(upper_lim_r-lower_lim_r)); |
1676 | tmp = i * high.r; |
1694 | tmp += ((uint32_t)(mask_r>>sh_r))*((uint32_t)lower_lim_r); |
1677 | tmp += (mask_r>>sh_r) * low.r; |
1695 | lookup_r[i] = (tmp/65535)<<sh_r; |
1678 | lookup_r[i] = (tmp/65535)<<sh_r; |
1696 | } |
1679 | } |
1697 | for (i = 0; i <= mask_g>>sh_g; i++) |
1680 | for (i = 0; i <= mask_g>>sh_g; i++) |
1698 | { |
1681 | { |
1699 | uint32_t tmp; |
1682 | uint32_t tmp; |
1700 | tmp = ((uint32_t)i)*((uint32_t)(upper_lim_g-lower_lim_g)); |
1683 | tmp = i * high.g; |
1701 | tmp += ((uint32_t)(mask_g>>sh_g))*((uint32_t)lower_lim_g); |
1684 | tmp += (mask_g>>sh_g) * low.g; |
1702 | lookup_g[i] = (tmp/65535)<<sh_g; |
1685 | lookup_g[i] = (tmp/65535)<<sh_g; |
1703 | } |
1686 | } |
1704 | for (i = 0; i <= mask_b>>sh_b; i++) |
1687 | for (i = 0; i <= mask_b>>sh_b; i++) |
1705 | { |
1688 | { |
1706 | uint32_t tmp; |
1689 | uint32_t tmp; |
1707 | tmp = ((uint32_t)i)*((uint32_t)(upper_lim_b-lower_lim_b)); |
1690 | tmp = i * high.b; |
1708 | tmp += ((uint32_t)(mask_b>>sh_b))*((uint32_t)lower_lim_b); |
1691 | tmp += (mask_b>>sh_b) * low.b; |
1709 | lookup_b[i] = (tmp/65535)<<sh_b; |
1692 | lookup_b[i] = (tmp/65535)<<sh_b; |
1710 | } |
1693 | } |
1711 | |
1694 | |
1712 | /* apply table to input image (replacing colors by newly calculated ones) */ |
1695 | /* apply table to input image (replacing colors by newly calculated ones) */ |
1713 | if (srcImage->bits_per_pixel == 32 |
1696 | if (srcImage->bits_per_pixel == 32 |