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.14 by root, Mon Nov 19 15:33:34 2007 UTC vs.
Revision 1.20 by root, Mon Dec 24 06:51:37 2007 UTC

1/*----------------------------------------------------------------------* 1/*----------------------------------------------------------------------*
2 * File: background.C - former xpm.C 2 * File: background.C - former xpm.C
3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
4 * 4 *
5 * All portions of code are copyright by their respective author/s. 5 * All portions of code are copyright by their respective author/s.
6 * Copyright (c) 1997 Carsten Haitzler <raster@zip.com.au>
7 * Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de>
8 * Copyright (c) 1998-2001 Geoff Wing <gcw@pobox.com>
9 * Copyright (c) 2005-2006 Marc Lehmann <pcg@goof.com> 6 * Copyright (c) 2005-2006 Marc Lehmann <pcg@goof.com>
10 * Copyright (c) 2007 Sasha Vasko <sasha@aftercode.net> 7 * Copyright (c) 2007 Sasha Vasko <sasha@aftercode.net>
11 * 8 *
12 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by 10 * it under the terms of the GNU General Public License as published by
28#include "rxvt.h" /* NECESSARY */ 25#include "rxvt.h" /* NECESSARY */
29 26
30#define DO_TIMING_TEST 0 27#define DO_TIMING_TEST 0
31 28
32#if DO_TIMING_TEST 29#if DO_TIMING_TEST
30# include <sys/time.h>
33#define TIMING_TEST_START(id) \ 31#define TIMING_TEST_START(id) \
34 struct timeval timing_test_##id##_stv;\ 32 struct timeval timing_test_##id##_stv;\
35 gettimeofday (&timing_test_##id##_stv, NULL); 33 gettimeofday (&timing_test_##id##_stv, NULL);
36 34
37#define TIMING_TEST_PRINT_RESULT(id) \ 35#define TIMING_TEST_PRINT_RESULT(id) \
305 y = x; 303 y = x;
306 geom_flags |= YValue; 304 geom_flags |= YValue;
307 } 305 }
308 306
309 if (flags & geometrySet) 307 if (flags & geometrySet)
308 {
310 {/* new geometry is an adjustment to the old one ! */ 309 /* new geometry is an adjustment to the old one ! */
311 if ((geom_flags & WidthValue) && (geom_flags & HeightValue)) 310 if ((geom_flags & WidthValue) && (geom_flags & HeightValue))
312 { 311 {
313 if (w == 0 && h != 0) 312 if (w == 0 && h != 0)
314 { 313 {
315 w = h_scale; 314 w = h_scale;
331 } 330 }
332 } 331 }
333 else /* setting up geometry from scratch */ 332 else /* setting up geometry from scratch */
334 { 333 {
335 if (!(geom_flags & XValue)) 334 if (!(geom_flags & XValue))
335 {
336 {/* use default geometry - centered */ 336 /* use default geometry - centered */
337 x = y = defaultAlign; 337 x = y = defaultAlign;
338 } 338 }
339 else if (!(geom_flags & YValue)) 339 else if (!(geom_flags & YValue))
340 y = x; 340 y = x;
341 341
342 if ((geom_flags & (WidthValue|HeightValue)) == 0) 342 if ((geom_flags & (WidthValue|HeightValue)) == 0)
343 {
343 {/* use default geometry - scaled */ 344 /* use default geometry - scaled */
344 w = h = defaultScale; 345 w = h = defaultScale;
345 } 346 }
346 else if (geom_flags & WidthValue) 347 else if (geom_flags & WidthValue)
347 { 348 {
348 if (!(geom_flags & HeightValue)) 349 if (!(geom_flags & HeightValue))
351 else 352 else
352 w = h; 353 w = h;
353 } 354 }
354 } /* done parsing geometry string */ 355 } /* done parsing geometry string */
355 else if (!(flags & geometrySet)) 356 else if (!(flags & geometrySet))
357 {
356 { /* default geometry - scaled and centered */ 358 /* default geometry - scaled and centered */
357 x = y = defaultAlign; 359 x = y = defaultAlign;
358 w = h = defaultScale; 360 w = h = defaultScale;
359 } 361 }
360 362
361 if (!(flags & geometrySet)) 363 if (!(flags & geometrySet))
433 if (new_flags != flags) 435 if (new_flags != flags)
434 { 436 {
435 flags = new_flags; 437 flags = new_flags;
436 changed++; 438 changed++;
437 } 439 }
438//fprintf( stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n", 440//fprintf (stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n",
439// flags, h_scale, v_scale, h_align, v_align); 441// flags, h_scale, v_scale, h_align, v_align);
440 return (changed > 0); 442 return (changed > 0);
441} 443}
442 444
443# ifdef HAVE_AFTERIMAGE 445# ifdef HAVE_AFTERIMAGE
507 h > 0 ? h : original_asim->height, 509 h > 0 ? h : original_asim->height,
508 background ? ASA_ASImage : ASA_XImage, 510 background ? ASA_ASImage : ASA_XImage,
509 100, ASIMAGE_QUALITY_DEFAULT); 511 100, ASIMAGE_QUALITY_DEFAULT);
510 } 512 }
511 if (background == NULL) 513 if (background == NULL)
514 {
512 {/* if tiling - pixmap has to be sized exactly as the image, 515 /* if tiling - pixmap has to be sized exactly as the image,
513 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! */
514 if (h_scale == 0) 517 if (h_scale == 0)
515 new_pmap_width = min (result->width, target_width); 518 new_pmap_width = min (result->width, target_width);
516 if (v_scale == 0) 519 if (v_scale == 0)
517 new_pmap_height = min (result->height, target_height); 520 new_pmap_height = min (result->height, target_height);
518 /* 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 */
532 result = tmp; 535 result = tmp;
533 } 536 }
534 } 537 }
535 } 538 }
536 else 539 else
540 {
537 {/* 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 */
538 ASImageLayer *layers = create_image_layers (2); 542 ASImageLayer *layers = create_image_layers (2);
539 ASImage *merged_im = NULL; 543 ASImage *merged_im = NULL;
540 544
541 layers[0].im = background; 545 layers[0].im = background;
542 layers[0].clip_width = target_width; 546 layers[0].clip_width = target_width;
543 layers[0].clip_height = target_height; 547 layers[0].clip_height = target_height;
544 layers[0].tint = background_tint; 548 layers[0].tint = background_tint;
545 layers[1].im = result; 549 layers[1].im = result;
546 if (w <= 0) 550 if (w <= 0)
551 {
547 {/* tile horizontally */ 552 /* tile horizontally */
548 while (x > 0) x -= (int)result->width; 553 while (x > 0) x -= (int)result->width;
549 layers[1].dst_x = x; 554 layers[1].dst_x = x;
550 layers[1].clip_width = result->width+target_width; 555 layers[1].clip_width = result->width+target_width;
551 } 556 }
552 else 557 else
558 {
553 {/* clip horizontally */ 559 /* clip horizontally */
554 layers[1].dst_x = x; 560 layers[1].dst_x = x;
555 layers[1].clip_width = result->width; 561 layers[1].clip_width = result->width;
556 } 562 }
557 if (h <= 0) 563 if (h <= 0)
558 { 564 {
773 unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade); 779 unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade);
774 tint = new_tint; 780 tint = new_tint;
775 flags = (flags & ~tintFlags) | new_flags | tintSet; 781 flags = (flags & ~tintFlags) | new_flags | tintSet;
776 return true; 782 return true;
777 } 783 }
784
778 return false; 785 return false;
779} 786}
780 787
781bool 788bool
782bgPixmap_t::unset_tint () 789bgPixmap_t::unset_tint ()
786 if (new_flags != (flags & tintFlags)) 793 if (new_flags != (flags & tintFlags))
787 { 794 {
788 flags = (flags&~tintFlags)|new_flags; 795 flags = (flags&~tintFlags)|new_flags;
789 return true; 796 return true;
790 } 797 }
798
791 return false; 799 return false;
792} 800}
793 801
794bool 802bool
795bgPixmap_t::set_shade (const char *shade_str) 803bgPixmap_t::set_shade (const char *shade_str)
796{ 804{
797 int new_shade = (shade_str) ? atoi (shade_str) : 0; 805 int new_shade = (shade_str) ? atoi (shade_str) : 0;
798 806
799 if (new_shade < 0 && new_shade > -100) 807 if (new_shade < 0 && new_shade > -100)
800 new_shade = 200 - (100 + new_shade); 808 new_shade = 200 - (100 + new_shade);
801 else if (new_shade == 100) 809 else if (new_shade == 100)
802 new_shade = 0; 810 new_shade = 0;
803 811
804 if (new_shade != shade) 812 if (new_shade != shade)
805 { 813 {
806 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);
807 shade = new_shade; 815 shade = new_shade;
808 flags = (flags & (~tintFlags | tintSet)) | new_flags; 816 flags = (flags & (~tintFlags | tintSet)) | new_flags;
809 return true; 817 return true;
810 } 818 }
819
811 return false; 820 return false;
812} 821}
813 822
814/* make_transparency_pixmap() 823/* make_transparency_pixmap()
815 * 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
845 if (sx + window_width <= 0 || sy + window_height <= 0 854 if (sx + window_width <= 0 || sy + window_height <= 0
846 || sx >= root_width || sy >= root_height) 855 || sx >= root_width || sy >= root_height)
847 return 0; 856 return 0;
848 857
849 if (root_pixmap != None) 858 if (root_pixmap != None)
859 {
850 {/* 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 : */
851 int junk; 861 int junk;
852 unsigned int ujunk; 862 unsigned int ujunk;
853 /* root pixmap may be bad - allow a error */ 863 /* root pixmap may be bad - allow a error */
854 target->allowedxerror = -1; 864 target->allowedxerror = -1;
855 865
864 874
865 if (tiled_root_pmap == None) /* something really bad happened - abort */ 875 if (tiled_root_pmap == None) /* something really bad happened - abort */
866 return 0; 876 return 0;
867 877
868 if (root_pixmap == None) 878 if (root_pixmap == None)
879 {
869 { /* use tricks to obtain the root background image :*/ 880 /* use tricks to obtain the root background image :*/
870 /* we want to create Overrideredirect window overlapping out window 881 /* we want to create Overrideredirect window overlapping out window
871 with background type of Parent Relative and then grab it */ 882 with background type of Parent Relative and then grab it */
872 XSetWindowAttributes attr; 883 XSetWindowAttributes attr;
873 Window src; 884 Window src;
874 bool success = false; 885 bool success = false;
894 * 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 : */
895 while (XCheckWindowEvent (dpy, src, ExposureMask, &event)) 906 while (XCheckWindowEvent (dpy, src, ExposureMask, &event))
896 ++ev_count; 907 ++ev_count;
897 908
898 if (ev_count > 0); 909 if (ev_count > 0);
910 {
899 { /* hooray! - we can grab the image! */ 911 /* hooray! - we can grab the image! */
900 gc = XCreateGC (dpy, root, 0, NULL); 912 gc = XCreateGC (dpy, root, 0, NULL);
901 if (gc) 913 if (gc)
902 { 914 {
903 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);
904 success = true; 916 success = true;
905 } 917 }
906 } 918 }
919
907 XDestroyWindow (dpy, src); 920 XDestroyWindow (dpy, src);
908 XUngrabServer (dpy); 921 XUngrabServer (dpy);
909 //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);
910 } 923 }
911 924
916 } 929 }
917 else 930 else
918 result |= transpPmapTiled; 931 result |= transpPmapTiled;
919 } 932 }
920 else 933 else
934 {
921 {/* strightforward pixmap copy */ 935 /* strightforward pixmap copy */
922 gcv.tile = root_pixmap; 936 gcv.tile = root_pixmap;
923 gcv.fill_style = FillTiled; 937 gcv.fill_style = FillTiled;
924 938
925 while (sx < 0) sx += (int)root_width; 939 while (sx < 0) sx += (int)root_width;
926 while (sy < 0) sy += (int)root_height; 940 while (sy < 0) sy += (int)root_height;
974 { 988 {
975 c.r = (c.r * shade) / 100; 989 c.r = (c.r * shade) / 100;
976 c.g = (c.g * shade) / 100; 990 c.g = (c.g * shade) / 100;
977 c.b = (c.b * shade) / 100; 991 c.b = (c.b * shade) / 100;
978 } 992 }
979 else if( shade > 100 && shade < 200) 993 else if (shade > 100 && shade < 200)
980 { 994 {
981 c.r = (c.r * (200 - shade)) / 100; 995 c.r = (c.r * (200 - shade)) / 100;
982 c.g = (c.g * (200 - shade)) / 100; 996 c.g = (c.g * (200 - shade)) / 100;
983 c.b = (c.b * (200 - shade)) / 100; 997 c.b = (c.b * (200 - shade)) / 100;
984 } 998 }
1030 mask_c.blue = 0xffff - c.b; 1044 mask_c.blue = 0xffff - c.b;
1031 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1); 1045 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); 1046 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, window_width, window_height);
1033 result |= transpPmapTinted; 1047 result |= transpPmapTinted;
1034 } 1048 }
1049
1035 XRenderFreePicture (dpy, mask_pic); 1050 XRenderFreePicture (dpy, mask_pic);
1036 XRenderFreePicture (dpy, overlay_pic); 1051 XRenderFreePicture (dpy, overlay_pic);
1037 XRenderFreePicture (dpy, back_pic); 1052 XRenderFreePicture (dpy, back_pic);
1038# if DO_TIMING_TEST 1053# if DO_TIMING_TEST
1039 XSync (dpy, False); 1054 XSync (dpy, False);
1061} 1076}
1062 1077
1063bool 1078bool
1064bgPixmap_t::set_root_pixmap () 1079bgPixmap_t::set_root_pixmap ()
1065{ 1080{
1066 Pixmap new_root_pixmap = None;
1067
1068 new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID); 1081 Pixmap new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID);
1069 if (new_root_pixmap == None) 1082 if (new_root_pixmap == None)
1070 new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID); 1083 new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID);
1071 1084
1072 if (new_root_pixmap != root_pixmap) 1085 if (new_root_pixmap != root_pixmap)
1073 { 1086 {
1074 root_pixmap = new_root_pixmap; 1087 root_pixmap = new_root_pixmap;
1075 return true; 1088 return true;
1076 } 1089 }
1090
1077 return false; 1091 return false;
1078} 1092}
1079# endif /* ENABLE_TRANSPARENCY */ 1093# endif /* ENABLE_TRANSPARENCY */
1080 1094
1081# ifndef HAVE_AFTERIMAGE 1095# ifndef HAVE_AFTERIMAGE
1082static 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);
1083# endif 1097# endif
1084
1085 1098
1086bool 1099bool
1087bgPixmap_t::render () 1100bgPixmap_t::render ()
1088{ 1101{
1089 unsigned long background_flags = 0; 1102 unsigned long background_flags = 0;
1171 ShadeXImage (target, result, shade, c.r, c.g, c.b); 1184 ShadeXImage (target, result, shade, c.r, c.g, c.b);
1172 } 1185 }
1173 } 1186 }
1174# endif /* HAVE_AFTERIMAGE */ 1187# endif /* HAVE_AFTERIMAGE */
1175 1188
1176 if (result != NULL) 1189 if (result)
1177 { 1190 {
1178 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); 1191 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL);
1192
1179 if (gc) 1193 if (gc)
1180 { 1194 {
1181 if (/*pmap_depth != target->depth &&*/ pixmap != None) 1195 if (/*pmap_depth != target->depth &&*/ pixmap != None)
1182 { 1196 {
1183 XFreePixmap (target->dpy, pixmap); 1197 XFreePixmap (target->dpy, pixmap);
1184 pixmap = None; 1198 pixmap = None;
1185 } 1199 }
1200
1186 if (pixmap == None) 1201 if (pixmap == None)
1187 { 1202 {
1188 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);
1189 pmap_width = result->width; 1204 pmap_width = result->width;
1190 pmap_height = result->height; 1205 pmap_height = result->height;
1191 pmap_depth = target->depth; 1206 pmap_depth = target->depth;
1192 } 1207 }
1208
1193 if (pmap_depth != result->depth) 1209 if (pmap_depth != result->depth)
1210 {
1194 { /* Bad Match error will ensue ! stupid X !!!! */ 1211 /* Bad Match error will ensue ! stupid X !!!! */
1195 if( result->depth == 24 && pmap_depth == 32) 1212 if (result->depth == 24 && pmap_depth == 32)
1196 result->depth = 32; 1213 result->depth = 32;
1197 else if( result->depth == 32 && pmap_depth == 24) 1214 else if (result->depth == 32 && pmap_depth == 24)
1198 result->depth = 24; 1215 result->depth = 24;
1199 else 1216 else
1200 { 1217 {
1201 /* TODO: implement image recoding */ 1218 /* TODO: implement image recoding */
1202 } 1219 }
1203 } 1220 }
1221
1204 if (pmap_depth == result->depth) 1222 if (pmap_depth == result->depth)
1205 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
1206 XFreeGC (target->dpy, gc); 1225 XFreeGC (target->dpy, gc);
1207 flags = flags & ~isInvalid; 1226 flags = flags & ~isInvalid;
1208 } 1227 }
1228
1209 XDestroyImage (result); 1229 XDestroyImage (result);
1210 } 1230 }
1211 1231
1212 if (flags & isInvalid) 1232 if (flags & isInvalid)
1213 { 1233 {
1239 } 1259 }
1240 return false; 1260 return false;
1241} 1261}
1242 1262
1243void 1263void
1244bgPixmap_t::apply() 1264bgPixmap_t::apply ()
1245{ 1265{
1246 if (target) 1266 if (target)
1247 { 1267 {
1248 flags &= ~isVtOrigin; 1268 flags &= ~isVtOrigin;
1249 if (pixmap != None) 1269 if (pixmap != None)
1270 {
1250 { /* set target's background to pixmap */ 1271 /* set target's background to pixmap */
1251# ifdef ENABLE_TRANSPARENCY 1272# ifdef ENABLE_TRANSPARENCY
1252 if (flags & isTransparent) 1273 if (flags & isTransparent)
1253 { 1274 {
1254 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap); 1275 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap);
1255 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative); 1276 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative);
1271 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); 1292 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1272# endif 1293# endif
1273 } 1294 }
1274 } 1295 }
1275 else 1296 else
1297 {
1276 { /* set target background to a pixel */ 1298 /* set target background to a pixel */
1277 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); 1299 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
1278 XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); 1300 XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]);
1279 /* do we also need to set scrollbar's background here ? */ 1301 /* do we also need to set scrollbar's background here ? */
1280# if HAVE_SCROLLBARS 1302# if HAVE_SCROLLBARS
1281 if (target->scrollBar.win) 1303 if (target->scrollBar.win)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines