ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/background.C
(Generate patch)

Comparing rxvt-unicode/src/background.C (file contents):
Revision 1.15 by sasha, Mon Nov 19 15:50:46 2007 UTC vs.
Revision 1.22 by sasha, Fri Jan 4 21:25:57 2008 UTC

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
102void 104void
103bgPixmap_t::destroy () 105bgPixmap_t::destroy ()
104{ 106{
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))
348 else 353 else
349 w = h; 354 w = h;
350 } 355 }
351 } /* done parsing geometry string */ 356 } /* done parsing geometry string */
352 else if (!(flags & geometrySet)) 357 else if (!(flags & geometrySet))
358 {
353 { /* default geometry - scaled and centered */ 359 /* default geometry - scaled and centered */
354 x = y = defaultAlign; 360 x = y = defaultAlign;
355 w = h = defaultScale; 361 w = h = defaultScale;
356 } 362 }
357 363
358 if (!(flags & geometrySet)) 364 if (!(flags & geometrySet))
430 if (new_flags != flags) 436 if (new_flags != flags)
431 { 437 {
432 flags = new_flags; 438 flags = new_flags;
433 changed++; 439 changed++;
434 } 440 }
435//fprintf( stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n", 441//fprintf (stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n",
436// flags, h_scale, v_scale, h_align, v_align); 442// flags, h_scale, v_scale, h_align, v_align);
437 return (changed > 0); 443 return (changed > 0);
438} 444}
439 445
440# ifdef HAVE_AFTERIMAGE 446# ifdef HAVE_AFTERIMAGE
504 h > 0 ? h : original_asim->height, 510 h > 0 ? h : original_asim->height,
505 background ? ASA_ASImage : ASA_XImage, 511 background ? ASA_ASImage : ASA_XImage,
506 100, ASIMAGE_QUALITY_DEFAULT); 512 100, ASIMAGE_QUALITY_DEFAULT);
507 } 513 }
508 if (background == NULL) 514 if (background == NULL)
515 {
509 {/* if tiling - pixmap has to be sized exactly as the image, 516 /* if tiling - pixmap has to be sized exactly as the image,
510 but there is no need to make it bigger then the window! */ 517 but there is no need to make it bigger then the window! */
511 if (h_scale == 0) 518 if (h_scale == 0)
512 new_pmap_width = min (result->width, target_width); 519 new_pmap_width = min (result->width, target_width);
513 if (v_scale == 0) 520 if (v_scale == 0)
514 new_pmap_height = min (result->height, target_height); 521 new_pmap_height = min (result->height, target_height);
515 /* 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 */
529 result = tmp; 536 result = tmp;
530 } 537 }
531 } 538 }
532 } 539 }
533 else 540 else
541 {
534 {/* 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 */
535 ASImageLayer *layers = create_image_layers (2); 543 ASImageLayer *layers = create_image_layers (2);
536 ASImage *merged_im = NULL; 544 ASImage *merged_im = NULL;
537 545
538 layers[0].im = background; 546 layers[0].im = background;
539 layers[0].clip_width = target_width; 547 layers[0].clip_width = target_width;
540 layers[0].clip_height = target_height; 548 layers[0].clip_height = target_height;
541 layers[0].tint = background_tint; 549 layers[0].tint = background_tint;
542 layers[1].im = result; 550 layers[1].im = result;
543 if (w <= 0) 551 if (w <= 0)
552 {
544 {/* tile horizontally */ 553 /* tile horizontally */
545 while (x > 0) x -= (int)result->width; 554 while (x > 0) x -= (int)result->width;
546 layers[1].dst_x = x; 555 layers[1].dst_x = x;
547 layers[1].clip_width = result->width+target_width; 556 layers[1].clip_width = result->width+target_width;
548 } 557 }
549 else 558 else
559 {
550 {/* clip horizontally */ 560 /* clip horizontally */
551 layers[1].dst_x = x; 561 layers[1].dst_x = x;
552 layers[1].clip_width = result->width; 562 layers[1].clip_width = result->width;
553 } 563 }
554 if (h <= 0) 564 if (h <= 0)
555 { 565 {
770 unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade); 780 unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade);
771 tint = new_tint; 781 tint = new_tint;
772 flags = (flags & ~tintFlags) | new_flags | tintSet; 782 flags = (flags & ~tintFlags) | new_flags | tintSet;
773 return true; 783 return true;
774 } 784 }
785
775 return false; 786 return false;
776} 787}
777 788
778bool 789bool
779bgPixmap_t::unset_tint () 790bgPixmap_t::unset_tint ()
783 if (new_flags != (flags & tintFlags)) 794 if (new_flags != (flags & tintFlags))
784 { 795 {
785 flags = (flags&~tintFlags)|new_flags; 796 flags = (flags&~tintFlags)|new_flags;
786 return true; 797 return true;
787 } 798 }
799
788 return false; 800 return false;
789} 801}
790 802
791bool 803bool
792bgPixmap_t::set_shade (const char *shade_str) 804bgPixmap_t::set_shade (const char *shade_str)
793{ 805{
794 int new_shade = (shade_str) ? atoi (shade_str) : 0; 806 int new_shade = (shade_str) ? atoi (shade_str) : 0;
795 807
796 if (new_shade < 0 && new_shade > -100) 808 if (new_shade < 0 && new_shade > -100)
797 new_shade = 200 - (100 + new_shade); 809 new_shade = 200 - (100 + new_shade);
798 else if (new_shade == 100) 810 else if (new_shade == 100)
799 new_shade = 0; 811 new_shade = 0;
800 812
801 if (new_shade != shade) 813 if (new_shade != shade)
802 { 814 {
803 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);
804 shade = new_shade; 816 shade = new_shade;
805 flags = (flags & (~tintFlags | tintSet)) | new_flags; 817 flags = (flags & (~tintFlags | tintSet)) | new_flags;
806 return true; 818 return true;
807 } 819 }
820
808 return false; 821 return false;
809} 822}
810 823
811/* make_transparency_pixmap() 824/* make_transparency_pixmap()
812 * 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
842 if (sx + window_width <= 0 || sy + window_height <= 0 855 if (sx + window_width <= 0 || sy + window_height <= 0
843 || sx >= root_width || sy >= root_height) 856 || sx >= root_width || sy >= root_height)
844 return 0; 857 return 0;
845 858
846 if (root_pixmap != None) 859 if (root_pixmap != None)
860 {
847 {/* 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 : */
848 int junk; 862 int junk;
849 unsigned int ujunk; 863 unsigned int ujunk;
850 /* root pixmap may be bad - allow a error */ 864 /* root pixmap may be bad - allow a error */
851 target->allowedxerror = -1; 865 target->allowedxerror = -1;
852 866
861 875
862 if (tiled_root_pmap == None) /* something really bad happened - abort */ 876 if (tiled_root_pmap == None) /* something really bad happened - abort */
863 return 0; 877 return 0;
864 878
865 if (root_pixmap == None) 879 if (root_pixmap == None)
880 {
866 { /* use tricks to obtain the root background image :*/ 881 /* use tricks to obtain the root background image :*/
867 /* we want to create Overrideredirect window overlapping out window 882 /* we want to create Overrideredirect window overlapping out window
868 with background type of Parent Relative and then grab it */ 883 with background type of Parent Relative and then grab it */
869 XSetWindowAttributes attr; 884 XSetWindowAttributes attr;
870 Window src; 885 Window src;
871 bool success = false; 886 bool success = false;
886 XGrabServer (dpy); 901 XGrabServer (dpy);
887 XMapRaised (dpy, src); 902 XMapRaised (dpy, src);
888 XSync (dpy, False); 903 XSync (dpy, False);
889 904
890 /* XSync should get window where it's properly exposed, 905 /* XSync should get window where it's properly exposed,
891 * 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 : */
892 while (XCheckWindowEvent (dpy, src, ExposureMask, &event)) 907 while (XCheckWindowEvent (dpy, src, ExposureMask, &event))
893 ++ev_count; 908 ++ev_count;
894 909
895 if (ev_count > 0); 910 if (ev_count > 0);
911 {
896 { /* hooray! - we can grab the image! */ 912 /* hooray! - we can grab the image! */
897 gc = XCreateGC (dpy, root, 0, NULL); 913 gc = XCreateGC (dpy, root, 0, NULL);
898 if (gc) 914 if (gc)
899 { 915 {
900 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);
901 success = true; 917 success = true;
902 } 918 }
903 } 919 }
920
904 XDestroyWindow (dpy, src); 921 XDestroyWindow (dpy, src);
905 XUngrabServer (dpy); 922 XUngrabServer (dpy);
906 //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);
907 } 924 }
908 925
913 } 930 }
914 else 931 else
915 result |= transpPmapTiled; 932 result |= transpPmapTiled;
916 } 933 }
917 else 934 else
935 {
918 {/* strightforward pixmap copy */ 936 /* strightforward pixmap copy */
919 gcv.tile = root_pixmap; 937 gcv.tile = root_pixmap;
920 gcv.fill_style = FillTiled; 938 gcv.fill_style = FillTiled;
921 939
922 while (sx < 0) sx += (int)root_width; 940 while (sx < 0) sx += (int)root_width;
923 while (sy < 0) sy += (int)root_height; 941 while (sy < 0) sy += (int)root_height;
971 { 989 {
972 c.r = (c.r * shade) / 100; 990 c.r = (c.r * shade) / 100;
973 c.g = (c.g * shade) / 100; 991 c.g = (c.g * shade) / 100;
974 c.b = (c.b * shade) / 100; 992 c.b = (c.b * shade) / 100;
975 } 993 }
976 else if( shade > 100 && shade < 200) 994 else if (shade > 100 && shade < 200)
977 { 995 {
978 c.r = (c.r * (200 - shade)) / 100; 996 c.r = (c.r * (200 - shade)) / 100;
979 c.g = (c.g * (200 - shade)) / 100; 997 c.g = (c.g * (200 - shade)) / 100;
980 c.b = (c.b * (200 - shade)) / 100; 998 c.b = (c.b * (200 - shade)) / 100;
981 } 999 }
1027 mask_c.blue = 0xffff - c.b; 1045 mask_c.blue = 0xffff - c.b;
1028 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1); 1046 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1);
1029 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);
1030 result |= transpPmapTinted; 1048 result |= transpPmapTinted;
1031 } 1049 }
1050
1032 XRenderFreePicture (dpy, mask_pic); 1051 XRenderFreePicture (dpy, mask_pic);
1033 XRenderFreePicture (dpy, overlay_pic); 1052 XRenderFreePicture (dpy, overlay_pic);
1034 XRenderFreePicture (dpy, back_pic); 1053 XRenderFreePicture (dpy, back_pic);
1035# if DO_TIMING_TEST 1054# if DO_TIMING_TEST
1036 XSync (dpy, False); 1055 XSync (dpy, False);
1058} 1077}
1059 1078
1060bool 1079bool
1061bgPixmap_t::set_root_pixmap () 1080bgPixmap_t::set_root_pixmap ()
1062{ 1081{
1063 Pixmap new_root_pixmap = None;
1064
1065 new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID); 1082 Pixmap new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID);
1066 if (new_root_pixmap == None) 1083 if (new_root_pixmap == None)
1067 new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID); 1084 new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID);
1068 1085
1069 if (new_root_pixmap != root_pixmap) 1086 if (new_root_pixmap != root_pixmap)
1070 { 1087 {
1071 root_pixmap = new_root_pixmap; 1088 root_pixmap = new_root_pixmap;
1072 return true; 1089 return true;
1073 } 1090 }
1091
1074 return false; 1092 return false;
1075} 1093}
1076# endif /* ENABLE_TRANSPARENCY */ 1094# endif /* ENABLE_TRANSPARENCY */
1077 1095
1078# ifndef HAVE_AFTERIMAGE 1096# ifndef HAVE_AFTERIMAGE
1079static void ShadeXImage(rxvt_term *term, XImage* srcImage, int shade, int rm, int gm, int bm); 1097static void ShadeXImage(rxvt_term *term, XImage* srcImage, int shade, int rm, int gm, int bm);
1080# endif 1098# endif
1081
1082 1099
1083bool 1100bool
1084bgPixmap_t::render () 1101bgPixmap_t::render ()
1085{ 1102{
1086 unsigned long background_flags = 0; 1103 unsigned long background_flags = 0;
1168 ShadeXImage (target, result, shade, c.r, c.g, c.b); 1185 ShadeXImage (target, result, shade, c.r, c.g, c.b);
1169 } 1186 }
1170 } 1187 }
1171# endif /* HAVE_AFTERIMAGE */ 1188# endif /* HAVE_AFTERIMAGE */
1172 1189
1173 if (result != NULL) 1190 if (result)
1174 { 1191 {
1175 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); 1192 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL);
1193
1176 if (gc) 1194 if (gc)
1177 { 1195 {
1178 if (/*pmap_depth != target->depth &&*/ pixmap != None) 1196 if (/*pmap_depth != target->depth &&*/ pixmap != None)
1179 { 1197 {
1180 XFreePixmap (target->dpy, pixmap); 1198 XFreePixmap (target->dpy, pixmap);
1181 pixmap = None; 1199 pixmap = None;
1182 } 1200 }
1201
1183 if (pixmap == None) 1202 if (pixmap == None)
1184 { 1203 {
1185 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);
1186 pmap_width = result->width; 1205 pmap_width = result->width;
1187 pmap_height = result->height; 1206 pmap_height = result->height;
1188 pmap_depth = target->depth; 1207 pmap_depth = target->depth;
1189 } 1208 }
1209
1190 if (pmap_depth != result->depth) 1210 if (pmap_depth != result->depth)
1211 {
1191 { /* Bad Match error will ensue ! stupid X !!!! */ 1212 /* Bad Match error will ensue ! stupid X !!!! */
1192 if( result->depth == 24 && pmap_depth == 32) 1213 if (result->depth == 24 && pmap_depth == 32)
1193 result->depth = 32; 1214 result->depth = 32;
1194 else if( result->depth == 32 && pmap_depth == 24) 1215 else if (result->depth == 32 && pmap_depth == 24)
1195 result->depth = 24; 1216 result->depth = 24;
1196 else 1217 else
1197 { 1218 {
1198 /* TODO: implement image recoding */ 1219 /* TODO: implement image recoding */
1199 } 1220 }
1200 } 1221 }
1222
1201 if (pmap_depth == result->depth) 1223 if (pmap_depth == result->depth)
1202 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
1203 XFreeGC (target->dpy, gc); 1226 XFreeGC (target->dpy, gc);
1204 flags = flags & ~isInvalid; 1227 flags = flags & ~isInvalid;
1205 } 1228 }
1229
1206 XDestroyImage (result); 1230 XDestroyImage (result);
1207 } 1231 }
1208 1232
1209 if (flags & isInvalid) 1233 if (flags & isInvalid)
1210 { 1234 {
1214 pixmap = None; 1238 pixmap = None;
1215 } 1239 }
1216 } 1240 }
1217 1241
1218 apply (); 1242 apply ();
1243
1244 XSync (target->dpy, False);
1245 valid_since = ev::now ();
1219 1246
1220 TIMING_TEST_PRINT_RESULT (tp); 1247 TIMING_TEST_PRINT_RESULT (tp);
1221 1248
1222 return true; 1249 return true;
1223} 1250}
1236 } 1263 }
1237 return false; 1264 return false;
1238} 1265}
1239 1266
1240void 1267void
1241bgPixmap_t::apply() 1268bgPixmap_t::apply ()
1242{ 1269{
1243 if (target) 1270 if (target)
1244 { 1271 {
1245 flags &= ~isVtOrigin; 1272 flags &= ~isVtOrigin;
1246 if (pixmap != None) 1273 if (pixmap != None)
1274 {
1247 { /* set target's background to pixmap */ 1275 /* set target's background to pixmap */
1248# ifdef ENABLE_TRANSPARENCY 1276# ifdef ENABLE_TRANSPARENCY
1249 if (flags & isTransparent) 1277 if (flags & isTransparent)
1250 { 1278 {
1251 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap); 1279 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap);
1252 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative); 1280 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative);
1268 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); 1296 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1269# endif 1297# endif
1270 } 1298 }
1271 } 1299 }
1272 else 1300 else
1301 {
1273 { /* set target background to a pixel */ 1302 /* set target background to a pixel */
1274 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); 1303 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
1275 XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); 1304 XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]);
1276 /* do we also need to set scrollbar's background here ? */ 1305 /* do we also need to set scrollbar's background here ? */
1277# if HAVE_SCROLLBARS 1306# if HAVE_SCROLLBARS
1278 if (target->scrollBar.win) 1307 if (target->scrollBar.win)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines