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.19 by ayin, Tue Dec 18 11:15:24 2007 UTC vs.
Revision 1.24 by ayin, Mon Jan 7 12:41:31 2008 UTC

96 h_scale = v_scale = 0; 96 h_scale = v_scale = 0;
97 h_align = v_align = 0; 97 h_align = v_align = 0;
98#endif 98#endif
99 flags = 0; 99 flags = 0;
100 pixmap = None; 100 pixmap = None;
101 valid_since = invalid_since = 0;
101} 102}
102 103
103void 104void
104bgPixmap_t::destroy () 105bgPixmap_t::destroy ()
105{ 106{
256 int x = 0, y = 0; 257 int x = 0, y = 0;
257 unsigned int w = 0, h = 0; 258 unsigned int w = 0, h = 0;
258 unsigned int n; 259 unsigned int n;
259 unsigned long new_flags = (flags & (~geometryFlags)); 260 unsigned long new_flags = (flags & (~geometryFlags));
260 char *p; 261 char *p;
261# define MAXLEN_GEOM 256 /* could be longer then regular geometry string */ 262# define MAXLEN_GEOM 256 /* could be longer than regular geometry string */
262 263
263 if (geom == NULL) 264 if (geom == NULL)
264 return false; 265 return false;
265 266
266 char str[MAXLEN_GEOM]; 267 char str[MAXLEN_GEOM];
273 if (n < MAXLEN_GEOM) 274 if (n < MAXLEN_GEOM)
274 { 275 {
275 char *ops; 276 char *ops;
276 new_flags |= geometrySet; 277 new_flags |= geometrySet;
277 278
278 strncpy (str, geom, n); 279 memcpy (str, geom, n);
279 str[n] = '\0'; 280 str[n] = '\0';
280 if (str[0] == ':') 281 if (str[0] == ':')
281 ops = &str[0]; 282 ops = &str[0];
282 else if (str[0] != 'x' && str[0] != 'X' && isalpha(str[0])) 283 else if (str[0] != 'x' && str[0] != 'X' && isalpha(str[0]))
283 ops = &str[0]; 284 ops = &str[0];
511 100, ASIMAGE_QUALITY_DEFAULT); 512 100, ASIMAGE_QUALITY_DEFAULT);
512 } 513 }
513 if (background == NULL) 514 if (background == NULL)
514 { 515 {
515 /* if tiling - pixmap has to be sized exactly as the image, 516 /* if tiling - pixmap has to be sized exactly as the image,
516 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! */
517 if (h_scale == 0) 518 if (h_scale == 0)
518 new_pmap_width = min (result->width, target_width); 519 new_pmap_width = min (result->width, target_width);
519 if (v_scale == 0) 520 if (v_scale == 0)
520 new_pmap_height = min (result->height, target_height); 521 new_pmap_height = min (result->height, target_height);
521 /* 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 */
667 original_asim = get_asimage (target->asimman, file, 0xFFFFFFFF, 100); 668 original_asim = get_asimage (target->asimman, file, 0xFFFFFFFF, 100);
668 else 669 else
669 { 670 {
670 size_t len = f - file; 671 size_t len = f - file;
671 f = (char *)malloc (len + 1); 672 f = (char *)malloc (len + 1);
672 strncpy (f, file, len); 673 memcpy (f, file, len);
673 f[len] = '\0'; 674 f[len] = '\0';
674 original_asim = get_asimage (target->asimman, f, 0xFFFFFFFF, 100); 675 original_asim = get_asimage (target->asimman, f, 0xFFFFFFFF, 100);
675 free (f); 676 free (f);
676 } 677 }
677 return (original_asim != NULL); 678 return (original_asim != NULL);
779 unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade); 780 unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade);
780 tint = new_tint; 781 tint = new_tint;
781 flags = (flags & ~tintFlags) | new_flags | tintSet; 782 flags = (flags & ~tintFlags) | new_flags | tintSet;
782 return true; 783 return true;
783 } 784 }
785
784 return false; 786 return false;
785} 787}
786 788
787bool 789bool
788bgPixmap_t::unset_tint () 790bgPixmap_t::unset_tint ()
792 if (new_flags != (flags & tintFlags)) 794 if (new_flags != (flags & tintFlags))
793 { 795 {
794 flags = (flags&~tintFlags)|new_flags; 796 flags = (flags&~tintFlags)|new_flags;
795 return true; 797 return true;
796 } 798 }
799
797 return false; 800 return false;
798} 801}
799 802
800bool 803bool
801bgPixmap_t::set_shade (const char *shade_str) 804bgPixmap_t::set_shade (const char *shade_str)
802{ 805{
803 int new_shade = (shade_str) ? atoi (shade_str) : 0; 806 int new_shade = (shade_str) ? atoi (shade_str) : 0;
804 807
805 if (new_shade < 0 && new_shade > -100) 808 if (new_shade < 0 && new_shade > -100)
806 new_shade = 200 - (100 + new_shade); 809 new_shade = 200 - (100 + new_shade);
807 else if (new_shade == 100) 810 else if (new_shade == 100)
808 new_shade = 0; 811 new_shade = 0;
809 812
810 if (new_shade != shade) 813 if (new_shade != shade)
811 { 814 {
812 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);
813 shade = new_shade; 816 shade = new_shade;
814 flags = (flags & (~tintFlags | tintSet)) | new_flags; 817 flags = (flags & (~tintFlags | tintSet)) | new_flags;
815 return true; 818 return true;
816 } 819 }
820
817 return false; 821 return false;
818} 822}
819 823
820/* make_transparency_pixmap() 824/* make_transparency_pixmap()
821 * 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
897 XGrabServer (dpy); 901 XGrabServer (dpy);
898 XMapRaised (dpy, src); 902 XMapRaised (dpy, src);
899 XSync (dpy, False); 903 XSync (dpy, False);
900 904
901 /* XSync should get window where it's properly exposed, 905 /* XSync should get window where it's properly exposed,
902 * 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 : */
903 while (XCheckWindowEvent (dpy, src, ExposureMask, &event)) 907 while (XCheckWindowEvent (dpy, src, ExposureMask, &event))
904 ++ev_count; 908 ++ev_count;
905 909
906 if (ev_count > 0); 910 if (ev_count > 0);
907 { 911 {
911 { 915 {
912 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);
913 success = true; 917 success = true;
914 } 918 }
915 } 919 }
920
916 XDestroyWindow (dpy, src); 921 XDestroyWindow (dpy, src);
917 XUngrabServer (dpy); 922 XUngrabServer (dpy);
918 //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);
919 } 924 }
920 925
1040 mask_c.blue = 0xffff - c.b; 1045 mask_c.blue = 0xffff - c.b;
1041 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1); 1046 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1);
1042 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);
1043 result |= transpPmapTinted; 1048 result |= transpPmapTinted;
1044 } 1049 }
1050
1045 XRenderFreePicture (dpy, mask_pic); 1051 XRenderFreePicture (dpy, mask_pic);
1046 XRenderFreePicture (dpy, overlay_pic); 1052 XRenderFreePicture (dpy, overlay_pic);
1047 XRenderFreePicture (dpy, back_pic); 1053 XRenderFreePicture (dpy, back_pic);
1048# if DO_TIMING_TEST 1054# if DO_TIMING_TEST
1049 XSync (dpy, False); 1055 XSync (dpy, False);
1071} 1077}
1072 1078
1073bool 1079bool
1074bgPixmap_t::set_root_pixmap () 1080bgPixmap_t::set_root_pixmap ()
1075{ 1081{
1076 Pixmap new_root_pixmap = None;
1077
1078 new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID); 1082 Pixmap new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID);
1079 if (new_root_pixmap == None) 1083 if (new_root_pixmap == None)
1080 new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID); 1084 new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID);
1081 1085
1082 if (new_root_pixmap != root_pixmap) 1086 if (new_root_pixmap != root_pixmap)
1083 { 1087 {
1084 root_pixmap = new_root_pixmap; 1088 root_pixmap = new_root_pixmap;
1085 return true; 1089 return true;
1086 } 1090 }
1091
1087 return false; 1092 return false;
1088} 1093}
1089# endif /* ENABLE_TRANSPARENCY */ 1094# endif /* ENABLE_TRANSPARENCY */
1090 1095
1091# ifndef HAVE_AFTERIMAGE 1096# ifndef HAVE_AFTERIMAGE
1092static 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);
1093# endif 1098# endif
1094
1095 1099
1096bool 1100bool
1097bgPixmap_t::render () 1101bgPixmap_t::render ()
1098{ 1102{
1099 unsigned long background_flags = 0; 1103 unsigned long background_flags = 0;
1181 ShadeXImage (target, result, shade, c.r, c.g, c.b); 1185 ShadeXImage (target, result, shade, c.r, c.g, c.b);
1182 } 1186 }
1183 } 1187 }
1184# endif /* HAVE_AFTERIMAGE */ 1188# endif /* HAVE_AFTERIMAGE */
1185 1189
1186 if (result != NULL) 1190 if (result)
1187 { 1191 {
1188 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); 1192 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL);
1193
1189 if (gc) 1194 if (gc)
1190 { 1195 {
1191 if (/*pmap_depth != target->depth &&*/ pixmap != None) 1196 if (/*pmap_depth != target->depth &&*/ pixmap != None)
1192 { 1197 {
1193 XFreePixmap (target->dpy, pixmap); 1198 XFreePixmap (target->dpy, pixmap);
1194 pixmap = None; 1199 pixmap = None;
1195 } 1200 }
1201
1196 if (pixmap == None) 1202 if (pixmap == None)
1197 { 1203 {
1198 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);
1199 pmap_width = result->width; 1205 pmap_width = result->width;
1200 pmap_height = result->height; 1206 pmap_height = result->height;
1201 pmap_depth = target->depth; 1207 pmap_depth = target->depth;
1202 } 1208 }
1209
1203 if (pmap_depth != result->depth) 1210 if (pmap_depth != result->depth)
1204 { 1211 {
1205 /* Bad Match error will ensue ! stupid X !!!! */ 1212 /* Bad Match error will ensue ! stupid X !!!! */
1206 if (result->depth == 24 && pmap_depth == 32) 1213 if (result->depth == 24 && pmap_depth == 32)
1207 result->depth = 32; 1214 result->depth = 32;
1210 else 1217 else
1211 { 1218 {
1212 /* TODO: implement image recoding */ 1219 /* TODO: implement image recoding */
1213 } 1220 }
1214 } 1221 }
1222
1215 if (pmap_depth == result->depth) 1223 if (pmap_depth == result->depth)
1216 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
1217 XFreeGC (target->dpy, gc); 1226 XFreeGC (target->dpy, gc);
1218 flags = flags & ~isInvalid; 1227 flags = flags & ~isInvalid;
1219 } 1228 }
1229
1220 XDestroyImage (result); 1230 XDestroyImage (result);
1221 } 1231 }
1222 1232
1223 if (flags & isInvalid) 1233 if (flags & isInvalid)
1224 { 1234 {
1228 pixmap = None; 1238 pixmap = None;
1229 } 1239 }
1230 } 1240 }
1231 1241
1232 apply (); 1242 apply ();
1243
1244 XSync (target->dpy, False);
1245 valid_since = ev::now ();
1233 1246
1234 TIMING_TEST_PRINT_RESULT (tp); 1247 TIMING_TEST_PRINT_RESULT (tp);
1235 1248
1236 return true; 1249 return true;
1237} 1250}
1250 } 1263 }
1251 return false; 1264 return false;
1252} 1265}
1253 1266
1254void 1267void
1255bgPixmap_t::apply() 1268bgPixmap_t::apply ()
1256{ 1269{
1257 if (target) 1270 if (target)
1258 { 1271 {
1259 flags &= ~isVtOrigin; 1272 flags &= ~isVtOrigin;
1260 if (pixmap != None) 1273 if (pixmap != None)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines