… | |
… | |
25 | #include "rxvt.h" /* NECESSARY */ |
25 | #include "rxvt.h" /* NECESSARY */ |
26 | |
26 | |
27 | #define DO_TIMING_TEST 0 |
27 | #define DO_TIMING_TEST 0 |
28 | |
28 | |
29 | #if DO_TIMING_TEST |
29 | #if DO_TIMING_TEST |
|
|
30 | # include <sys/time.h> |
30 | #define TIMING_TEST_START(id) \ |
31 | #define TIMING_TEST_START(id) \ |
31 | struct timeval timing_test_##id##_stv;\ |
32 | struct timeval timing_test_##id##_stv;\ |
32 | gettimeofday (&timing_test_##id##_stv, NULL); |
33 | gettimeofday (&timing_test_##id##_stv, NULL); |
33 | |
34 | |
34 | #define TIMING_TEST_PRINT_RESULT(id) \ |
35 | #define TIMING_TEST_PRINT_RESULT(id) \ |
… | |
… | |
95 | h_scale = v_scale = 0; |
96 | h_scale = v_scale = 0; |
96 | h_align = v_align = 0; |
97 | h_align = v_align = 0; |
97 | #endif |
98 | #endif |
98 | flags = 0; |
99 | flags = 0; |
99 | pixmap = None; |
100 | pixmap = None; |
|
|
101 | valid_since = invalid_since = 0; |
100 | } |
102 | } |
101 | |
103 | |
102 | void |
104 | void |
103 | bgPixmap_t::destroy () |
105 | bgPixmap_t::destroy () |
104 | { |
106 | { |
… | |
… | |
255 | int x = 0, y = 0; |
257 | int x = 0, y = 0; |
256 | unsigned int w = 0, h = 0; |
258 | unsigned int w = 0, h = 0; |
257 | unsigned int n; |
259 | unsigned int n; |
258 | unsigned long new_flags = (flags & (~geometryFlags)); |
260 | unsigned long new_flags = (flags & (~geometryFlags)); |
259 | char *p; |
261 | char *p; |
260 | # define MAXLEN_GEOM 256 /* could be longer then regular geometry string */ |
262 | # define MAXLEN_GEOM 256 /* could be longer than regular geometry string */ |
261 | |
263 | |
262 | if (geom == NULL) |
264 | if (geom == NULL) |
263 | return false; |
265 | return false; |
264 | |
266 | |
265 | char str[MAXLEN_GEOM]; |
267 | char str[MAXLEN_GEOM]; |
… | |
… | |
302 | y = x; |
304 | y = x; |
303 | geom_flags |= YValue; |
305 | geom_flags |= YValue; |
304 | } |
306 | } |
305 | |
307 | |
306 | if (flags & geometrySet) |
308 | if (flags & geometrySet) |
|
|
309 | { |
307 | {/* new geometry is an adjustment to the old one ! */ |
310 | /* new geometry is an adjustment to the old one ! */ |
308 | if ((geom_flags & WidthValue) && (geom_flags & HeightValue)) |
311 | if ((geom_flags & WidthValue) && (geom_flags & HeightValue)) |
309 | { |
312 | { |
310 | if (w == 0 && h != 0) |
313 | if (w == 0 && h != 0) |
311 | { |
314 | { |
312 | w = h_scale; |
315 | w = h_scale; |
… | |
… | |
328 | } |
331 | } |
329 | } |
332 | } |
330 | else /* setting up geometry from scratch */ |
333 | else /* setting up geometry from scratch */ |
331 | { |
334 | { |
332 | if (!(geom_flags & XValue)) |
335 | if (!(geom_flags & XValue)) |
|
|
336 | { |
333 | {/* use default geometry - centered */ |
337 | /* use default geometry - centered */ |
334 | x = y = defaultAlign; |
338 | x = y = defaultAlign; |
335 | } |
339 | } |
336 | else if (!(geom_flags & YValue)) |
340 | else if (!(geom_flags & YValue)) |
337 | y = x; |
341 | y = x; |
338 | |
342 | |
339 | if ((geom_flags & (WidthValue|HeightValue)) == 0) |
343 | if ((geom_flags & (WidthValue|HeightValue)) == 0) |
|
|
344 | { |
340 | {/* use default geometry - scaled */ |
345 | /* use default geometry - scaled */ |
341 | w = h = defaultScale; |
346 | w = h = defaultScale; |
342 | } |
347 | } |
343 | else if (geom_flags & WidthValue) |
348 | else if (geom_flags & WidthValue) |
344 | { |
349 | { |
345 | if (!(geom_flags & HeightValue)) |
350 | if (!(geom_flags & HeightValue)) |
… | |
… | |
431 | if (new_flags != flags) |
436 | if (new_flags != flags) |
432 | { |
437 | { |
433 | flags = new_flags; |
438 | flags = new_flags; |
434 | changed++; |
439 | changed++; |
435 | } |
440 | } |
436 | //fprintf( stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n", |
441 | //fprintf (stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n", |
437 | // flags, h_scale, v_scale, h_align, v_align); |
442 | // flags, h_scale, v_scale, h_align, v_align); |
438 | return (changed > 0); |
443 | return (changed > 0); |
439 | } |
444 | } |
440 | |
445 | |
441 | # ifdef HAVE_AFTERIMAGE |
446 | # ifdef HAVE_AFTERIMAGE |
… | |
… | |
505 | h > 0 ? h : original_asim->height, |
510 | h > 0 ? h : original_asim->height, |
506 | background ? ASA_ASImage : ASA_XImage, |
511 | background ? ASA_ASImage : ASA_XImage, |
507 | 100, ASIMAGE_QUALITY_DEFAULT); |
512 | 100, ASIMAGE_QUALITY_DEFAULT); |
508 | } |
513 | } |
509 | if (background == NULL) |
514 | if (background == NULL) |
|
|
515 | { |
510 | {/* if tiling - pixmap has to be sized exactly as the image, |
516 | /* if tiling - pixmap has to be sized exactly as the image, |
511 | but there is no need to make it bigger then the window! */ |
517 | but there is no need to make it bigger than the window! */ |
512 | if (h_scale == 0) |
518 | if (h_scale == 0) |
513 | new_pmap_width = min (result->width, target_width); |
519 | new_pmap_width = min (result->width, target_width); |
514 | if (v_scale == 0) |
520 | if (v_scale == 0) |
515 | new_pmap_height = min (result->height, target_height); |
521 | new_pmap_height = min (result->height, target_height); |
516 | /* we also need to tile our image in one or both directions */ |
522 | /* we also need to tile our image in one or both directions */ |
… | |
… | |
530 | result = tmp; |
536 | result = tmp; |
531 | } |
537 | } |
532 | } |
538 | } |
533 | } |
539 | } |
534 | else |
540 | else |
|
|
541 | { |
535 | {/* if blending background and image - pixmap has to be sized same as target window */ |
542 | /* if blending background and image - pixmap has to be sized same as target window */ |
536 | ASImageLayer *layers = create_image_layers (2); |
543 | ASImageLayer *layers = create_image_layers (2); |
537 | ASImage *merged_im = NULL; |
544 | ASImage *merged_im = NULL; |
538 | |
545 | |
539 | layers[0].im = background; |
546 | layers[0].im = background; |
540 | layers[0].clip_width = target_width; |
547 | layers[0].clip_width = target_width; |
541 | layers[0].clip_height = target_height; |
548 | layers[0].clip_height = target_height; |
542 | layers[0].tint = background_tint; |
549 | layers[0].tint = background_tint; |
543 | layers[1].im = result; |
550 | layers[1].im = result; |
544 | if (w <= 0) |
551 | if (w <= 0) |
|
|
552 | { |
545 | {/* tile horizontally */ |
553 | /* tile horizontally */ |
546 | while (x > 0) x -= (int)result->width; |
554 | while (x > 0) x -= (int)result->width; |
547 | layers[1].dst_x = x; |
555 | layers[1].dst_x = x; |
548 | layers[1].clip_width = result->width+target_width; |
556 | layers[1].clip_width = result->width+target_width; |
549 | } |
557 | } |
550 | else |
558 | else |
|
|
559 | { |
551 | {/* clip horizontally */ |
560 | /* clip horizontally */ |
552 | layers[1].dst_x = x; |
561 | layers[1].dst_x = x; |
553 | layers[1].clip_width = result->width; |
562 | layers[1].clip_width = result->width; |
554 | } |
563 | } |
555 | if (h <= 0) |
564 | if (h <= 0) |
556 | { |
565 | { |
… | |
… | |
771 | unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade); |
780 | unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade); |
772 | tint = new_tint; |
781 | tint = new_tint; |
773 | flags = (flags & ~tintFlags) | new_flags | tintSet; |
782 | flags = (flags & ~tintFlags) | new_flags | tintSet; |
774 | return true; |
783 | return true; |
775 | } |
784 | } |
|
|
785 | |
776 | return false; |
786 | return false; |
777 | } |
787 | } |
778 | |
788 | |
779 | bool |
789 | bool |
780 | bgPixmap_t::unset_tint () |
790 | bgPixmap_t::unset_tint () |
… | |
… | |
784 | if (new_flags != (flags & tintFlags)) |
794 | if (new_flags != (flags & tintFlags)) |
785 | { |
795 | { |
786 | flags = (flags&~tintFlags)|new_flags; |
796 | flags = (flags&~tintFlags)|new_flags; |
787 | return true; |
797 | return true; |
788 | } |
798 | } |
|
|
799 | |
789 | return false; |
800 | return false; |
790 | } |
801 | } |
791 | |
802 | |
792 | bool |
803 | bool |
793 | bgPixmap_t::set_shade (const char *shade_str) |
804 | bgPixmap_t::set_shade (const char *shade_str) |
794 | { |
805 | { |
795 | int new_shade = (shade_str) ? atoi (shade_str) : 0; |
806 | int new_shade = (shade_str) ? atoi (shade_str) : 0; |
796 | |
807 | |
797 | if (new_shade < 0 && new_shade > -100) |
808 | if (new_shade < 0 && new_shade > -100) |
798 | new_shade = 200 - (100 + new_shade); |
809 | new_shade = 200 - (100 + new_shade); |
799 | else if (new_shade == 100) |
810 | else if (new_shade == 100) |
800 | new_shade = 0; |
811 | new_shade = 0; |
801 | |
812 | |
802 | if (new_shade != shade) |
813 | if (new_shade != shade) |
803 | { |
814 | { |
804 | unsigned long new_flags = compute_tint_shade_flags ((flags & tintSet) ? &tint : NULL, new_shade); |
815 | unsigned long new_flags = compute_tint_shade_flags ((flags & tintSet) ? &tint : NULL, new_shade); |
805 | shade = new_shade; |
816 | shade = new_shade; |
806 | flags = (flags & (~tintFlags | tintSet)) | new_flags; |
817 | flags = (flags & (~tintFlags | tintSet)) | new_flags; |
807 | return true; |
818 | return true; |
808 | } |
819 | } |
|
|
820 | |
809 | return false; |
821 | return false; |
810 | } |
822 | } |
811 | |
823 | |
812 | /* make_transparency_pixmap() |
824 | /* make_transparency_pixmap() |
813 | * Builds a pixmap sized the same as terminal window, with depth same as the root window |
825 | * Builds a pixmap sized the same as terminal window, with depth same as the root window |
… | |
… | |
843 | if (sx + window_width <= 0 || sy + window_height <= 0 |
855 | if (sx + window_width <= 0 || sy + window_height <= 0 |
844 | || sx >= root_width || sy >= root_height) |
856 | || sx >= root_width || sy >= root_height) |
845 | return 0; |
857 | return 0; |
846 | |
858 | |
847 | if (root_pixmap != None) |
859 | if (root_pixmap != None) |
|
|
860 | { |
848 | {/* we want to validate the pixmap and get it's size at the same time : */ |
861 | /* we want to validate the pixmap and get it's size at the same time : */ |
849 | int junk; |
862 | int junk; |
850 | unsigned int ujunk; |
863 | unsigned int ujunk; |
851 | /* root pixmap may be bad - allow a error */ |
864 | /* root pixmap may be bad - allow a error */ |
852 | target->allowedxerror = -1; |
865 | target->allowedxerror = -1; |
853 | |
866 | |
… | |
… | |
888 | XGrabServer (dpy); |
901 | XGrabServer (dpy); |
889 | XMapRaised (dpy, src); |
902 | XMapRaised (dpy, src); |
890 | XSync (dpy, False); |
903 | XSync (dpy, False); |
891 | |
904 | |
892 | /* XSync should get window where it's properly exposed, |
905 | /* XSync should get window where it's properly exposed, |
893 | * but to be on the safe side - let's check for the actuall event to arrive : */ |
906 | * but to be on the safe side - let's check for the actual event to arrive : */ |
894 | while (XCheckWindowEvent (dpy, src, ExposureMask, &event)) |
907 | while (XCheckWindowEvent (dpy, src, ExposureMask, &event)) |
895 | ++ev_count; |
908 | ++ev_count; |
896 | |
909 | |
897 | if (ev_count > 0); |
910 | if (ev_count > 0); |
898 | { |
911 | { |
… | |
… | |
902 | { |
915 | { |
903 | XCopyArea (dpy, src, tiled_root_pmap, gc, 0, 0, window_width, window_height, 0, 0); |
916 | XCopyArea (dpy, src, tiled_root_pmap, gc, 0, 0, window_width, window_height, 0, 0); |
904 | success = true; |
917 | success = true; |
905 | } |
918 | } |
906 | } |
919 | } |
|
|
920 | |
907 | XDestroyWindow (dpy, src); |
921 | XDestroyWindow (dpy, src); |
908 | XUngrabServer (dpy); |
922 | XUngrabServer (dpy); |
909 | //fprintf (stderr, "%s:%d: ev_count = %d\n", __FUNCTION__, __LINE__, ev_count); |
923 | //fprintf (stderr, "%s:%d: ev_count = %d\n", __FUNCTION__, __LINE__, ev_count); |
910 | } |
924 | } |
911 | |
925 | |
… | |
… | |
916 | } |
930 | } |
917 | else |
931 | else |
918 | result |= transpPmapTiled; |
932 | result |= transpPmapTiled; |
919 | } |
933 | } |
920 | else |
934 | else |
|
|
935 | { |
921 | {/* strightforward pixmap copy */ |
936 | /* strightforward pixmap copy */ |
922 | gcv.tile = root_pixmap; |
937 | gcv.tile = root_pixmap; |
923 | gcv.fill_style = FillTiled; |
938 | gcv.fill_style = FillTiled; |
924 | |
939 | |
925 | while (sx < 0) sx += (int)root_width; |
940 | while (sx < 0) sx += (int)root_width; |
926 | while (sy < 0) sy += (int)root_height; |
941 | while (sy < 0) sy += (int)root_height; |
… | |
… | |
974 | { |
989 | { |
975 | c.r = (c.r * shade) / 100; |
990 | c.r = (c.r * shade) / 100; |
976 | c.g = (c.g * shade) / 100; |
991 | c.g = (c.g * shade) / 100; |
977 | c.b = (c.b * shade) / 100; |
992 | c.b = (c.b * shade) / 100; |
978 | } |
993 | } |
979 | else if( shade > 100 && shade < 200) |
994 | else if (shade > 100 && shade < 200) |
980 | { |
995 | { |
981 | c.r = (c.r * (200 - shade)) / 100; |
996 | c.r = (c.r * (200 - shade)) / 100; |
982 | c.g = (c.g * (200 - shade)) / 100; |
997 | c.g = (c.g * (200 - shade)) / 100; |
983 | c.b = (c.b * (200 - shade)) / 100; |
998 | c.b = (c.b * (200 - shade)) / 100; |
984 | } |
999 | } |
… | |
… | |
1030 | mask_c.blue = 0xffff - c.b; |
1045 | mask_c.blue = 0xffff - c.b; |
1031 | XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1); |
1046 | XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1); |
1032 | XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, window_width, window_height); |
1047 | XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, window_width, window_height); |
1033 | result |= transpPmapTinted; |
1048 | result |= transpPmapTinted; |
1034 | } |
1049 | } |
|
|
1050 | |
1035 | XRenderFreePicture (dpy, mask_pic); |
1051 | XRenderFreePicture (dpy, mask_pic); |
1036 | XRenderFreePicture (dpy, overlay_pic); |
1052 | XRenderFreePicture (dpy, overlay_pic); |
1037 | XRenderFreePicture (dpy, back_pic); |
1053 | XRenderFreePicture (dpy, back_pic); |
1038 | # if DO_TIMING_TEST |
1054 | # if DO_TIMING_TEST |
1039 | XSync (dpy, False); |
1055 | XSync (dpy, False); |
… | |
… | |
1061 | } |
1077 | } |
1062 | |
1078 | |
1063 | bool |
1079 | bool |
1064 | bgPixmap_t::set_root_pixmap () |
1080 | bgPixmap_t::set_root_pixmap () |
1065 | { |
1081 | { |
1066 | Pixmap new_root_pixmap = None; |
|
|
1067 | |
|
|
1068 | new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID); |
1082 | Pixmap new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID); |
1069 | if (new_root_pixmap == None) |
1083 | if (new_root_pixmap == None) |
1070 | new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID); |
1084 | new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID); |
1071 | |
1085 | |
1072 | if (new_root_pixmap != root_pixmap) |
1086 | if (new_root_pixmap != root_pixmap) |
1073 | { |
1087 | { |
1074 | root_pixmap = new_root_pixmap; |
1088 | root_pixmap = new_root_pixmap; |
1075 | return true; |
1089 | return true; |
1076 | } |
1090 | } |
|
|
1091 | |
1077 | return false; |
1092 | return false; |
1078 | } |
1093 | } |
1079 | # endif /* ENABLE_TRANSPARENCY */ |
1094 | # endif /* ENABLE_TRANSPARENCY */ |
1080 | |
1095 | |
1081 | # ifndef HAVE_AFTERIMAGE |
1096 | # ifndef HAVE_AFTERIMAGE |
1082 | static void ShadeXImage(rxvt_term *term, XImage* srcImage, int shade, int rm, int gm, int bm); |
1097 | static void ShadeXImage(rxvt_term *term, XImage* srcImage, int shade, int rm, int gm, int bm); |
1083 | # endif |
1098 | # endif |
1084 | |
|
|
1085 | |
1099 | |
1086 | bool |
1100 | bool |
1087 | bgPixmap_t::render () |
1101 | bgPixmap_t::render () |
1088 | { |
1102 | { |
1089 | unsigned long background_flags = 0; |
1103 | unsigned long background_flags = 0; |
… | |
… | |
1171 | ShadeXImage (target, result, shade, c.r, c.g, c.b); |
1185 | ShadeXImage (target, result, shade, c.r, c.g, c.b); |
1172 | } |
1186 | } |
1173 | } |
1187 | } |
1174 | # endif /* HAVE_AFTERIMAGE */ |
1188 | # endif /* HAVE_AFTERIMAGE */ |
1175 | |
1189 | |
1176 | if (result != NULL) |
1190 | if (result) |
1177 | { |
1191 | { |
1178 | GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); |
1192 | GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); |
|
|
1193 | |
1179 | if (gc) |
1194 | if (gc) |
1180 | { |
1195 | { |
1181 | if (/*pmap_depth != target->depth &&*/ pixmap != None) |
1196 | if (/*pmap_depth != target->depth &&*/ pixmap != None) |
1182 | { |
1197 | { |
1183 | XFreePixmap (target->dpy, pixmap); |
1198 | XFreePixmap (target->dpy, pixmap); |
1184 | pixmap = None; |
1199 | pixmap = None; |
1185 | } |
1200 | } |
|
|
1201 | |
1186 | if (pixmap == None) |
1202 | if (pixmap == None) |
1187 | { |
1203 | { |
1188 | pixmap = XCreatePixmap (target->dpy, target->vt, result->width, result->height, target->depth); |
1204 | pixmap = XCreatePixmap (target->dpy, target->vt, result->width, result->height, target->depth); |
1189 | pmap_width = result->width; |
1205 | pmap_width = result->width; |
1190 | pmap_height = result->height; |
1206 | pmap_height = result->height; |
1191 | pmap_depth = target->depth; |
1207 | pmap_depth = target->depth; |
1192 | } |
1208 | } |
|
|
1209 | |
1193 | if (pmap_depth != result->depth) |
1210 | if (pmap_depth != result->depth) |
1194 | { |
1211 | { |
1195 | /* Bad Match error will ensue ! stupid X !!!! */ |
1212 | /* Bad Match error will ensue ! stupid X !!!! */ |
1196 | if( result->depth == 24 && pmap_depth == 32) |
1213 | if (result->depth == 24 && pmap_depth == 32) |
1197 | result->depth = 32; |
1214 | result->depth = 32; |
1198 | else if( result->depth == 32 && pmap_depth == 24) |
1215 | else if (result->depth == 32 && pmap_depth == 24) |
1199 | result->depth = 24; |
1216 | result->depth = 24; |
1200 | else |
1217 | else |
1201 | { |
1218 | { |
1202 | /* TODO: implement image recoding */ |
1219 | /* TODO: implement image recoding */ |
1203 | } |
1220 | } |
1204 | } |
1221 | } |
|
|
1222 | |
1205 | if (pmap_depth == result->depth) |
1223 | if (pmap_depth == result->depth) |
1206 | XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height); |
1224 | XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height); |
|
|
1225 | |
1207 | XFreeGC (target->dpy, gc); |
1226 | XFreeGC (target->dpy, gc); |
1208 | flags = flags & ~isInvalid; |
1227 | flags = flags & ~isInvalid; |
1209 | } |
1228 | } |
|
|
1229 | |
1210 | XDestroyImage (result); |
1230 | XDestroyImage (result); |
1211 | } |
1231 | } |
1212 | |
1232 | |
1213 | if (flags & isInvalid) |
1233 | if (flags & isInvalid) |
1214 | { |
1234 | { |
… | |
… | |
1218 | pixmap = None; |
1238 | pixmap = None; |
1219 | } |
1239 | } |
1220 | } |
1240 | } |
1221 | |
1241 | |
1222 | apply (); |
1242 | apply (); |
|
|
1243 | |
|
|
1244 | XSync (target->dpy, False); |
|
|
1245 | valid_since = ev::now (); |
1223 | |
1246 | |
1224 | TIMING_TEST_PRINT_RESULT (tp); |
1247 | TIMING_TEST_PRINT_RESULT (tp); |
1225 | |
1248 | |
1226 | return true; |
1249 | return true; |
1227 | } |
1250 | } |
… | |
… | |
1240 | } |
1263 | } |
1241 | return false; |
1264 | return false; |
1242 | } |
1265 | } |
1243 | |
1266 | |
1244 | void |
1267 | void |
1245 | bgPixmap_t::apply() |
1268 | bgPixmap_t::apply () |
1246 | { |
1269 | { |
1247 | if (target) |
1270 | if (target) |
1248 | { |
1271 | { |
1249 | flags &= ~isVtOrigin; |
1272 | flags &= ~isVtOrigin; |
1250 | if (pixmap != None) |
1273 | if (pixmap != None) |