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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines