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.101 by sf-exg, Sun Oct 31 08:28:04 2010 UTC vs.
Revision 1.133 by sf-exg, Tue Jan 11 09:21:14 2011 UTC

24 24
25#include <cmath> 25#include <cmath>
26#include "../config.h" /* NECESSARY */ 26#include "../config.h" /* NECESSARY */
27#include "rxvt.h" /* NECESSARY */ 27#include "rxvt.h" /* NECESSARY */
28 28
29#if XRENDER
30# include <X11/extensions/Xrender.h>
31#endif
32
33#ifndef FilterConvolution
34#define FilterConvolution "convolution"
35#endif
36
29#define DO_TIMING_TEST 0 37#define DO_TIMING_TEST 0
30 38
31#if DO_TIMING_TEST 39#if DO_TIMING_TEST
32# include <sys/time.h> 40# include <sys/time.h>
33#define TIMING_TEST_START(id) \ 41#define TIMING_TEST_START(id) \
58 * 66 *
59 * WxH+X+Y Set scaling to W% by H%, and position to X% by Y%. 67 * WxH+X+Y Set scaling to W% by H%, and position to X% by Y%.
60 * W and H are percentages of the terminal window size. 68 * W and H are percentages of the terminal window size.
61 * X and Y are also percentages; e.g., +50+50 centers 69 * X and Y are also percentages; e.g., +50+50 centers
62 * the image in the window. 70 * the image in the window.
63 * WxH+X Assumes Y == X
64 * WxH Assumes Y == X == 50 (centers the image)
65 * W+X+Y Assumes H == W
66 * W+X Assumes H == W and Y == X
67 * W Assumes H == W and Y == X == 50
68 *
69 * Adjusting position only :
70 * =+X+Y Set position to X% by Y% (absolute).
71 * =+X Set position to X% by X%.
72 * +X+Y Adjust position horizontally X% and vertically Y%
73 * from current position (relative).
74 * +X Adjust position horizontally X% and vertically X%
75 * from current position.
76 *
77 * Adjusting scale only :
78 * Wx0 Multiply horizontal scaling factor by W%
79 * 0xH Multiply vertical scaling factor by H%
80 * 0x0 No scaling (show image at normal size).
81 * 71 *
82 * Pixmap Operations : (should be prepended by a colon) 72 * Pixmap Operations : (should be prepended by a colon)
83 * tile Tile image. Scaling/position modifiers above will affect 73 * tile Tile image. Scaling/position modifiers above will affect
84 * the tile size and origin. 74 * the tile size and origin.
85 * propscale When scaling, scale proportionally. That is, maintain the 75 * propscale When scaling, scale proportionally. That is, maintain the
113#endif 103#endif
114 flags = 0; 104 flags = 0;
115 pixmap = None; 105 pixmap = None;
116 valid_since = invalid_since = 0; 106 valid_since = invalid_since = 0;
117 target = 0; 107 target = 0;
108 target_x = target_y = 0;
118} 109}
119 110
120void 111void
121bgPixmap_t::destroy () 112bgPixmap_t::destroy ()
122{ 113{
133 if (pixmap && target) 124 if (pixmap && target)
134 XFreePixmap (target->dpy, pixmap); 125 XFreePixmap (target->dpy, pixmap);
135} 126}
136 127
137bool 128bool
129bgPixmap_t::set_position (int x, int y)
130{
131
132 if (target_x != x
133 || target_y != y)
134 {
135 target_x = x;
136 target_y = y;
137 return true;
138 }
139 return false;
140}
141
142bool
138bgPixmap_t::window_size_sensitive () 143bgPixmap_t::window_size_sensitive ()
139{ 144{
140# ifdef ENABLE_TRANSPARENCY 145# ifdef ENABLE_TRANSPARENCY
141 if (flags & isTransparent) 146 if (flags & isTransparent)
142 return true; 147 return true;
167 if (flags & rootAlign) 172 if (flags & rootAlign)
168 return true; 173 return true;
169 } 174 }
170# endif 175# endif
171 176
172 return false;
173};
174
175bool bgPixmap_t::need_client_side_rendering ()
176{
177# ifdef HAVE_AFTERIMAGE
178 if (original_asim)
179 return true;
180# endif
181 return false; 177 return false;
182} 178}
183 179
184# ifdef BG_IMAGE_FROM_FILE 180# ifdef BG_IMAGE_FROM_FILE
185static inline bool 181static inline bool
248 dst_size = target_size - dst_pos; 244 dst_size = target_size - dst_pos;
249 return src_pos; 245 return src_pos;
250} 246}
251 247
252bool 248bool
253bgPixmap_t::set_geometry (const char *geom) 249bgPixmap_t::set_geometry (const char *geom, bool update)
254{ 250{
251 bool changed = false;
255 int geom_flags = 0, changed = 0; 252 int geom_flags = 0;
256 int x = 0, y = 0; 253 int x = 0, y = 0;
257 unsigned int w = 0, h = 0; 254 unsigned int w = 0, h = 0;
258 unsigned int n; 255 unsigned int n;
259 unsigned long new_flags = (flags & (~geometryFlags)); 256 unsigned long new_flags = (flags & (~geometryFlags));
260 const char *p; 257 const char *ops;
261# define MAXLEN_GEOM 256 /* could be longer than regular geometry string */
262 258
263 if (geom == NULL) 259 if (geom == NULL)
264 return false; 260 return false;
265 261
266 char str[MAXLEN_GEOM]; 262 char str[256];
267 263
268 while (isspace(*geom)) ++geom;
269 if ((p = strchr (geom, ';')) == NULL)
270 p = strchr (geom, '\0'); 264 ops = strchr (geom, ':');
271 265 if (ops == NULL)
266 n = strlen (geom);
267 else
272 n = (p - geom); 268 n = ops - geom;
273 if (n < MAXLEN_GEOM)
274 {
275 char *ops;
276 new_flags |= geometrySet;
277 269
270 if (n >= sizeof (str))
271 return false;
272
278 memcpy (str, geom, n); 273 memcpy (str, geom, n);
279 str[n] = '\0'; 274 str[n] = '\0';
280 if (str[0] == ':') 275 rxvt_strtrim (str);
281 ops = &str[0];
282 else if (str[0] != 'x' && str[0] != 'X' && isalpha(str[0]))
283 ops = &str[0];
284 else
285 {
286 char *tmp;
287 ops = strchr (str, ':');
288 if (ops != NULL)
289 {
290 for (tmp = ops-1; tmp >= str && isspace(*tmp); --tmp);
291 *(++tmp) = '\0';
292 if (ops == tmp) ++ops;
293 }
294 }
295 276
296 if (ops > str || ops == NULL) 277 if (str[0])
297 { 278 {
298 /* we have geometry string - let's handle it prior to applying ops */ 279 /* we have geometry string - let's handle it prior to applying ops */
299 geom_flags = XParseGeometry (str, &x, &y, &w, &h); 280 geom_flags = XParseGeometry (str, &x, &y, &w, &h);
300
301 if ((geom_flags & XValue) && !(geom_flags & YValue))
302 {
303 y = x;
304 geom_flags |= YValue;
305 }
306
307 if (flags & geometrySet)
308 {
309 /* new geometry is an adjustment to the old one ! */
310 if ((geom_flags & WidthValue) && (geom_flags & HeightValue))
311 {
312 if (w == 0 && h != 0)
313 {
314 w = h_scale;
315 h = (v_scale * h) / 100;
316 }
317 else if (h == 0 && w != 0)
318 {
319 w = (h_scale * w) / 100;
320 h = v_scale;
321 }
322 }
323 if (geom_flags & XValue)
324 {
325 if (str[0] != '=')
326 {
327 y += v_align;
328 x += h_align;
329 }
330 }
331 }
332 else /* setting up geometry from scratch */
333 {
334 if (!(geom_flags & XValue))
335 {
336 /* use default geometry - centered */
337 x = y = defaultAlign;
338 }
339 else if (!(geom_flags & YValue))
340 y = x;
341
342 if ((geom_flags & (WidthValue|HeightValue)) == 0)
343 {
344 /* use default geometry - scaled */
345 w = h = defaultScale;
346 }
347 else if (geom_flags & WidthValue)
348 {
349 if (!(geom_flags & HeightValue))
350 h = w;
351 }
352 else
353 w = h;
354 }
355 } /* done parsing geometry string */ 281 } /* done parsing geometry string */
356 else if (!(flags & geometrySet)) 282
357 { 283 if (!update)
358 /* default geometry - scaled and centered */ 284 {
285 if (!(geom_flags & XValue))
359 x = y = defaultAlign; 286 x = y = defaultAlign;
287 else if (!(geom_flags & YValue))
288 y = x;
289
290 if (!(geom_flags & (WidthValue|HeightValue)))
360 w = h = defaultScale; 291 w = h = defaultScale;
361 } 292 else if (!(geom_flags & HeightValue))
293 h = w;
294 else if (!(geom_flags & WidthValue))
295 w = h;
362 296
363 if (!(flags & geometrySet))
364 geom_flags |= WidthValue|HeightValue|XValue|YValue; 297 geom_flags |= WidthValue|HeightValue|XValue|YValue;
298 }
365 299
366 if (ops) 300 if (ops)
367 { 301 {
368 while (*ops) 302 char **arr = rxvt_strsplit (':', ops + 1);
303
304 for (int i = 0; arr[i]; i++)
369 { 305 {
370 while (*ops == ':' || isspace(*ops)) ++ops; 306 if (!strcasecmp (arr[i], "tile"))
371
372# define CHECK_GEOM_OPS(op_str) (strncasecmp (ops, (op_str), sizeof (op_str) - 1) == 0)
373 if (CHECK_GEOM_OPS ("tile"))
374 { 307 {
375 w = h = noScale; 308 w = h = noScale;
376 geom_flags |= WidthValue|HeightValue; 309 geom_flags |= WidthValue|HeightValue;
377 } 310 }
378 else if (CHECK_GEOM_OPS ("propscale")) 311 else if (!strcasecmp (arr[i], "propscale"))
379 { 312 {
380 new_flags |= propScale; 313 new_flags |= propScale;
381 } 314 }
382 else if (CHECK_GEOM_OPS ("hscale")) 315 else if (!strcasecmp (arr[i], "hscale"))
383 { 316 {
384 if (w == 0) w = windowScale; 317 if (w == 0) w = windowScale;
385 318
386 h = noScale; 319 h = noScale;
387 geom_flags |= WidthValue|HeightValue; 320 geom_flags |= WidthValue|HeightValue;
388 } 321 }
389 else if (CHECK_GEOM_OPS ("vscale")) 322 else if (!strcasecmp (arr[i], "vscale"))
390 { 323 {
391 if (h == 0) h = windowScale; 324 if (h == 0) h = windowScale;
392 325
393 w = noScale; 326 w = noScale;
394 geom_flags |= WidthValue|HeightValue; 327 geom_flags |= WidthValue|HeightValue;
395 } 328 }
396 else if (CHECK_GEOM_OPS ("scale")) 329 else if (!strcasecmp (arr[i], "scale"))
397 { 330 {
398 if (h == 0) h = windowScale; 331 if (h == 0) h = windowScale;
399 if (w == 0) w = windowScale; 332 if (w == 0) w = windowScale;
400 333
401 geom_flags |= WidthValue|HeightValue; 334 geom_flags |= WidthValue|HeightValue;
402 } 335 }
403 else if (CHECK_GEOM_OPS ("auto")) 336 else if (!strcasecmp (arr[i], "auto"))
404 { 337 {
405 w = h = windowScale; 338 w = h = windowScale;
406 x = y = centerAlign; 339 x = y = centerAlign;
407 geom_flags |= WidthValue|HeightValue|XValue|YValue; 340 geom_flags |= WidthValue|HeightValue|XValue|YValue;
408 } 341 }
409 else if (CHECK_GEOM_OPS ("root")) 342 else if (!strcasecmp (arr[i], "root"))
410 { 343 {
411 new_flags |= rootAlign; 344 new_flags |= rootAlign;
412 w = h = noScale; 345 w = h = noScale;
413 geom_flags |= WidthValue|HeightValue; 346 geom_flags |= WidthValue|HeightValue;
414 } 347 }
415# undef CHECK_GEOM_OPS
416
417 while (*ops != ':' && *ops != '\0') ++ops;
418 } /* done parsing ops */ 348 } /* done parsing ops */
419 }
420 349
350 rxvt_free_strsplit (arr);
351 }
352
421 if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) ++changed; 353 if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) changed = true;
422 if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) ++changed; 354 if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) changed = true;
423 if (check_set_align_value (geom_flags, XValue, h_align, x)) ++changed; 355 if (check_set_align_value (geom_flags, XValue, h_align, x)) changed = true;
424 if (check_set_align_value (geom_flags, YValue, v_align, y)) ++changed; 356 if (check_set_align_value (geom_flags, YValue, v_align, y)) changed = true;
425 }
426 357
427 if (new_flags != flags) 358 if (new_flags != flags)
428 { 359 {
429 flags = new_flags; 360 flags = new_flags;
430 changed++; 361 changed = true;
431 } 362 }
432 363
433 return (changed > 0); 364 return changed;
434} 365}
435 366
436void 367void
437bgPixmap_t::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y) 368bgPixmap_t::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y)
438{ 369{
455 if (!w) w = image_width; 386 if (!w) w = image_width;
456 if (!h) h = image_height; 387 if (!h) h = image_height;
457 388
458 if (flags & rootAlign) 389 if (flags & rootAlign)
459 { 390 {
460 target->get_window_origin (x, y);
461 x = -x; 391 x = -target_x;
462 y = -y; 392 y = -target_y;
463 } 393 }
464 else 394 else
465 { 395 {
466 x = make_align_position (h_align, target_width, w); 396 x = make_align_position (h_align, target_width, w);
467 y = make_align_position (v_align, target_height, h); 397 y = make_align_position (v_align, target_height, h);
661 if (result) 591 if (result)
662 { 592 {
663 XGCValues gcv; 593 XGCValues gcv;
664 GC gc; 594 GC gc;
665 595
666 if (pixmap)
667 {
668 if (pmap_width != new_pmap_width
669 || pmap_height != new_pmap_height
670 || pmap_depth != target->depth)
671 {
672 XFreePixmap (target->dpy, pixmap);
673 pixmap = None;
674 }
675 }
676
677 /* create Pixmap */ 596 /* create Pixmap */
678 if (pixmap == None) 597 if (pixmap == None
598 || pmap_width != new_pmap_width
599 || pmap_height != new_pmap_height
600 || pmap_depth != target->depth)
679 { 601 {
602 if (pixmap)
603 XFreePixmap (target->dpy, pixmap);
680 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); 604 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth);
681 pmap_width = new_pmap_width; 605 pmap_width = new_pmap_width;
682 pmap_height = new_pmap_height; 606 pmap_height = new_pmap_height;
683 pmap_depth = target->depth; 607 pmap_depth = target->depth;
684 } 608 }
721} 645}
722# endif /* HAVE_AFTERIMAGE */ 646# endif /* HAVE_AFTERIMAGE */
723 647
724# ifdef HAVE_PIXBUF 648# ifdef HAVE_PIXBUF
725bool 649bool
650bgPixmap_t::pixbuf_to_pixmap (GdkPixbuf *pixbuf, Pixmap pixmap, GC gc,
651 int src_x, int src_y, int dst_x, int dst_y,
652 unsigned int width, unsigned int height)
653{
654 XImage *ximage;
655 char *data, *line;
656 int bytes_per_pixel;
657 int width_r, width_g, width_b;
658 int sh_r, sh_g, sh_b;
659 int rowstride;
660 int channels;
661 unsigned char *row;
662 Visual *visual = target->visual;
663 int depth = target->depth;
664
665 if (visual->c_class != TrueColor)
666 return false;
667
668 if (depth == 24 || depth == 32)
669 bytes_per_pixel = 4;
670 else if (depth == 15 || depth == 16)
671 bytes_per_pixel = 2;
672 else
673 return false;
674
675 width_r = rxvt_popcount (visual->red_mask);
676 width_g = rxvt_popcount (visual->green_mask);
677 width_b = rxvt_popcount (visual->blue_mask);
678
679 if (width_r > 8 || width_g > 8 || width_b > 8)
680 return false;
681
682 sh_r = rxvt_ctz (visual->red_mask);
683 sh_g = rxvt_ctz (visual->green_mask);
684 sh_b = rxvt_ctz (visual->blue_mask);
685
686 if (width > INT_MAX / height / bytes_per_pixel)
687 return false;
688
689 data = (char *)malloc (width * height * bytes_per_pixel);
690 if (!data)
691 return false;
692
693 ximage = XCreateImage (target->dpy, visual, depth, ZPixmap, 0, data,
694 width, height, bytes_per_pixel * 8, 0);
695 if (!ximage)
696 {
697 free (data);
698 return false;
699 }
700
701 ximage->byte_order = byteorder::big_endian () ? MSBFirst : LSBFirst;
702
703 rowstride = gdk_pixbuf_get_rowstride (pixbuf);
704 channels = gdk_pixbuf_get_n_channels (pixbuf);
705 row = gdk_pixbuf_get_pixels (pixbuf) + src_y * rowstride + src_x * channels;
706 line = data;
707
708 for (int y = 0; y < height; y++)
709 {
710 for (int x = 0; x < width; x++)
711 {
712 unsigned char *pixel = row + x * channels;
713 uint32_t value;
714
715 value = ((pixel[0] >> (8 - width_r)) << sh_r)
716 | ((pixel[1] >> (8 - width_g)) << sh_g)
717 | ((pixel[2] >> (8 - width_b)) << sh_b);
718
719 if (bytes_per_pixel == 4)
720 ((uint32_t *)line)[x] = value;
721 else
722 ((uint16_t *)line)[x] = value;
723 }
724
725 row += rowstride;
726 line += ximage->bytes_per_line;
727 }
728
729 XPutImage (target->dpy, pixmap, gc, ximage, 0, 0, dst_x, dst_y, width, height);
730 XDestroyImage (ximage);
731 return true;
732}
733
734bool
726bgPixmap_t::render_image (unsigned long background_flags) 735bgPixmap_t::render_image (unsigned long background_flags)
727{ 736{
728 if (target == NULL) 737 if (target == NULL)
729 return false; 738 return false;
730 739
731 if (!pixbuf) 740 if (!pixbuf)
732 return false; 741 return false;
733 742
734#if !XRENDER
735 if (background_flags) 743 if (background_flags
744 && !(flags & HAS_RENDER))
736 return false; 745 return false;
737#endif
738 746
739 GdkPixbuf *result; 747 GdkPixbuf *result;
740 748
741 int image_width = gdk_pixbuf_get_width (pixbuf); 749 int image_width = gdk_pixbuf_get_width (pixbuf);
742 int image_height = gdk_pixbuf_get_height (pixbuf); 750 int image_height = gdk_pixbuf_get_height (pixbuf);
793 new_pmap_width = min (image_width, target_width); 801 new_pmap_width = min (image_width, target_width);
794 new_pmap_height = min (image_height, target_height); 802 new_pmap_height = min (image_height, target_height);
795 } 803 }
796 } 804 }
797 805
798 if (pixmap)
799 {
800 if (pmap_width != new_pmap_width
801 || pmap_height != new_pmap_height
802 || pmap_depth != target->depth)
803 {
804 XFreePixmap (target->dpy, pixmap);
805 pixmap = None;
806 }
807 }
808
809 if (pixmap == None) 806 if (pixmap == None
807 || pmap_width != new_pmap_width
808 || pmap_height != new_pmap_height
809 || pmap_depth != target->depth)
810 { 810 {
811 if (pixmap)
812 XFreePixmap (target->dpy, pixmap);
811 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); 813 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth);
812 pmap_width = new_pmap_width; 814 pmap_width = new_pmap_width;
813 pmap_height = new_pmap_height; 815 pmap_height = new_pmap_height;
814 pmap_depth = target->depth; 816 pmap_depth = target->depth;
815 } 817 }
818 gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv); 820 gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv);
819 821
820 if (h_scale == 0 || v_scale == 0) 822 if (h_scale == 0 || v_scale == 0)
821 { 823 {
822 Pixmap tile = XCreatePixmap (target->dpy, target->vt, image_width, image_height, target->depth); 824 Pixmap tile = XCreatePixmap (target->dpy, target->vt, image_width, image_height, target->depth);
823 gdk_pixbuf_xlib_render_to_drawable (result, tile, gc, 825 pixbuf_to_pixmap (result, tile, gc,
824 0, 0, 826 0, 0,
825 0, 0, 827 0, 0,
826 image_width, image_height, 828 image_width, image_height);
827 XLIB_RGB_DITHER_NONE,
828 0, 0);
829 829
830 gcv.tile = tile; 830 gcv.tile = tile;
831 gcv.fill_style = FillTiled; 831 gcv.fill_style = FillTiled;
832 gcv.ts_x_origin = x; 832 gcv.ts_x_origin = x;
833 gcv.ts_y_origin = y; 833 gcv.ts_y_origin = y;
848 || dst_x + dst_width < new_pmap_width 848 || dst_x + dst_width < new_pmap_width
849 || dst_y + dst_height < new_pmap_height) 849 || dst_y + dst_height < new_pmap_height)
850 XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); 850 XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height);
851 851
852 if (dst_x < new_pmap_width && dst_y < new_pmap_height) 852 if (dst_x < new_pmap_width && dst_y < new_pmap_height)
853 gdk_pixbuf_xlib_render_to_drawable (result, pixmap, gc, 853 pixbuf_to_pixmap (result, pixmap, gc,
854 src_x, src_y, 854 src_x, src_y,
855 dst_x, dst_y, 855 dst_x, dst_y,
856 dst_width, dst_height, 856 dst_width, dst_height);
857 XLIB_RGB_DITHER_NONE,
858 0, 0);
859 } 857 }
860 858
861#if XRENDER 859#if XRENDER
862 if (background_flags) 860 if (background_flags)
863 { 861 {
864 Display *dpy = target->dpy; 862 Display *dpy = target->dpy;
865 XRenderPictureAttributes pa; 863 XRenderPictureAttributes pa;
866 864
867 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, target->display->screen)); 865 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, target->visual);
868 Picture src = XRenderCreatePicture (dpy, root_pmap, src_format, 0, &pa); 866 Picture src = XRenderCreatePicture (dpy, root_pmap, src_format, 0, &pa);
869 867
870 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, target->visual); 868 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, target->visual);
871 Picture dst = XRenderCreatePicture (dpy, pixmap, dst_format, 0, &pa); 869 Picture dst = XRenderCreatePicture (dpy, pixmap, dst_format, 0, &pa);
872 870
909# endif /* HAVE_PIXBUF */ 907# endif /* HAVE_PIXBUF */
910 908
911bool 909bool
912bgPixmap_t::set_file (const char *file) 910bgPixmap_t::set_file (const char *file)
913{ 911{
914 assert (file); 912 if (!file || !*file)
913 return false;
915 914
916 if (*file)
917 {
918 if (const char *p = strchr (file, ';')) 915 if (const char *p = strchr (file, ';'))
919 { 916 {
920 size_t len = p - file; 917 size_t len = p - file;
921 char *f = rxvt_temp_buf<char> (len + 1); 918 char *f = rxvt_temp_buf<char> (len + 1);
922 memcpy (f, file, len); 919 memcpy (f, file, len);
923 f[len] = '\0'; 920 f[len] = '\0';
924 file = f; 921 file = f;
925 } 922 }
926 923
927# ifdef HAVE_AFTERIMAGE 924# ifdef HAVE_AFTERIMAGE
928 if (!target->asimman) 925 if (!target->asimman)
929 target->asimman = create_generic_imageman (target->rs[Rs_path]); 926 target->asimman = create_generic_imageman (target->rs[Rs_path]);
930 ASImage *image = get_asimage (target->asimman, file, 0xFFFFFFFF, 100); 927 ASImage *image = get_asimage (target->asimman, file, 0xFFFFFFFF, 100);
931 if (image) 928 if (image)
932 { 929 {
933 if (original_asim) 930 if (original_asim)
934 safe_asimage_destroy (original_asim); 931 safe_asimage_destroy (original_asim);
935 original_asim = image; 932 original_asim = image;
933 flags |= CLIENT_RENDER;
936 have_image = true; 934 have_image = true;
937 return true; 935 return true;
938 } 936 }
939# endif 937# endif
940 938
941# ifdef HAVE_PIXBUF 939# ifdef HAVE_PIXBUF
942 GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); 940 GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL);
943 if (image) 941 if (image)
944 { 942 {
945 if (pixbuf) 943 if (pixbuf)
946 g_object_unref (pixbuf); 944 g_object_unref (pixbuf);
947 pixbuf = image; 945 pixbuf = image;
948 have_image = true; 946 have_image = true;
949 return true; 947 return true;
950 } 948 }
951# endif 949# endif
952 }
953 950
954 return false; 951 return false;
955} 952}
956 953
957# endif /* BG_IMAGE_FROM_FILE */ 954# endif /* BG_IMAGE_FROM_FILE */
970} 967}
971 968
972bool 969bool
973bgPixmap_t::set_blur_radius (const char *geom) 970bgPixmap_t::set_blur_radius (const char *geom)
974{ 971{
975 int changed = 0; 972 bool changed = false;
976 unsigned int hr, vr; 973 unsigned int hr, vr;
977 int junk; 974 int junk;
978 int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); 975 int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr);
979 976
980 if (!(geom_flags & WidthValue)) 977 if (!(geom_flags & WidthValue))
985 min_it (hr, 128); 982 min_it (hr, 128);
986 min_it (vr, 128); 983 min_it (vr, 128);
987 984
988 if (h_blurRadius != hr) 985 if (h_blurRadius != hr)
989 { 986 {
990 ++changed; 987 changed = true;
991 h_blurRadius = hr; 988 h_blurRadius = hr;
992 } 989 }
993 990
994 if (v_blurRadius != vr) 991 if (v_blurRadius != vr)
995 { 992 {
996 ++changed; 993 changed = true;
997 v_blurRadius = vr; 994 v_blurRadius = vr;
998 } 995 }
999 996
1000 if (v_blurRadius == 0 && h_blurRadius == 0) 997 if (v_blurRadius == 0 && h_blurRadius == 0)
1001 flags &= ~blurNeeded; 998 flags &= ~blurNeeded;
1002 else 999 else
1003 flags |= blurNeeded; 1000 flags |= blurNeeded;
1004 1001
1005#if XRENDER
1006 XFilters *filters = XRenderQueryFilters (target->dpy, target->display->root);
1007 if (filters)
1008 {
1009 for (int i = 0; i < filters->nfilter; i++)
1010 if (!strcmp (filters->filter[i], FilterConvolution))
1011 flags |= bgPixmap_t::blurServerSide;
1012
1013 XFree (filters);
1014 }
1015#endif
1016
1017 return (changed > 0); 1002 return changed;
1018} 1003}
1019 1004
1020static inline unsigned long 1005static inline unsigned long
1021compute_tint_shade_flags (rxvt_color *tint, int shade) 1006compute_tint_shade_flags (rxvt_color *tint, int shade)
1022{ 1007{
1025 bool has_shade = shade != 100; 1010 bool has_shade = shade != 100;
1026 1011
1027 if (tint) 1012 if (tint)
1028 { 1013 {
1029 tint->get (c); 1014 tint->get (c);
1030# define IS_COMPONENT_WHOLESOME(cmp) ((cmp) <= 0x000700 || (cmp) >= 0x00f700) 1015 if (!has_shade
1031 if (!has_shade && IS_COMPONENT_WHOLESOME (c.r) 1016 && (c.r <= 0x00ff || c.r >= 0xff00)
1032 && IS_COMPONENT_WHOLESOME (c.g) 1017 && (c.g <= 0x00ff || c.g >= 0xff00)
1033 && IS_COMPONENT_WHOLESOME (c.b)) 1018 && (c.b <= 0x00ff || c.b >= 0xff00))
1034 flags |= bgPixmap_t::tintWholesome; 1019 flags |= bgPixmap_t::tintWholesome;
1035# undef IS_COMPONENT_WHOLESOME
1036 } 1020 }
1037 1021
1038 if (has_shade) 1022 if (has_shade || tint)
1039 flags |= bgPixmap_t::tintNeeded; 1023 flags |= bgPixmap_t::tintNeeded;
1040 else if (tint)
1041 {
1042 if ((c.r > 0x000700 || c.g > 0x000700 || c.b > 0x000700)
1043 && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700))
1044 {
1045 flags |= bgPixmap_t::tintNeeded;
1046 }
1047 }
1048
1049 if (flags & bgPixmap_t::tintNeeded)
1050 {
1051 if (flags & bgPixmap_t::tintWholesome)
1052 flags |= bgPixmap_t::tintServerSide;
1053 else
1054 {
1055#if XRENDER
1056 flags |= bgPixmap_t::tintServerSide;
1057#endif
1058 }
1059 }
1060 1024
1061 return flags; 1025 return flags;
1062} 1026}
1063 1027
1064bool 1028bool
1067 if (!(flags & tintSet) || tint != new_tint) 1031 if (!(flags & tintSet) || tint != new_tint)
1068 { 1032 {
1069 unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade); 1033 unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade);
1070 tint = new_tint; 1034 tint = new_tint;
1071 flags = (flags & ~tintFlags) | new_flags | tintSet; 1035 flags = (flags & ~tintFlags) | new_flags | tintSet;
1072 return true;
1073 }
1074
1075 return false;
1076}
1077
1078bool
1079bgPixmap_t::unset_tint ()
1080{
1081 unsigned long new_flags = compute_tint_shade_flags (NULL, shade);
1082
1083 if (new_flags != (flags & tintFlags))
1084 {
1085 flags = (flags & ~tintFlags) | new_flags;
1086 return true; 1036 return true;
1087 } 1037 }
1088 1038
1089 return false; 1039 return false;
1090} 1040}
1235 c.g = (c.g * shade) / 100; 1185 c.g = (c.g * shade) / 100;
1236 c.b = (c.b * shade) / 100; 1186 c.b = (c.b * shade) / 100;
1237 } 1187 }
1238 else 1188 else
1239 { 1189 {
1240 c.r = ((0xffff - c.r) * (200 - shade)) / 100; 1190 c.r = (c.r * (200 - shade)) / 100;
1241 c.g = ((0xffff - c.g) * (200 - shade)) / 100; 1191 c.g = (c.g * (200 - shade)) / 100;
1242 c.b = ((0xffff - c.b) * (200 - shade)) / 100; 1192 c.b = (c.b * (200 - shade)) / 100;
1243 } 1193 }
1244 1194
1245 XRenderPictFormat *solid_format = XRenderFindStandardFormat (dpy, PictStandardARGB32); 1195 XRenderPictFormat *solid_format = XRenderFindStandardFormat (dpy, PictStandardARGB32);
1246 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 1196 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
1247 XRenderPictureAttributes pa; 1197 XRenderPictureAttributes pa;
1261 1211
1262 if (mask_pic && overlay_pic && back_pic) 1212 if (mask_pic && overlay_pic && back_pic)
1263 { 1213 {
1264 XRenderColor mask_c; 1214 XRenderColor mask_c;
1265 1215
1266 memset (&mask_c, (shade > 100) ? 0xFF : 0x0, sizeof (mask_c)); 1216 mask_c.red = mask_c.green = mask_c.blue = 0;
1267 mask_c.alpha = 0xffff; 1217 mask_c.alpha = 0xffff;
1268 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); 1218 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1);
1269 1219
1270 mask_c.alpha = 0; 1220 mask_c.alpha = 0;
1271 mask_c.red = 0xffff - c.r; 1221 mask_c.red = 0xffff - c.r;
1272 mask_c.green = 0xffff - c.g; 1222 mask_c.green = 0xffff - c.g;
1273 mask_c.blue = 0xffff - c.b; 1223 mask_c.blue = 0xffff - c.b;
1274 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1); 1224 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1);
1275 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, width, height); 1225 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, width, height);
1226
1227 if (shade > 100)
1228 {
1229 mask_c.red = mask_c.green = mask_c.blue = 0xffff * (shade - 100) / 100;
1230 mask_c.alpha = 0;
1231 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1);
1232
1233 XRenderComposite (dpy, PictOpOver, overlay_pic, None, back_pic, 0, 0, 0, 0, 0, 0, width, height);
1234 }
1235
1276 ret = true; 1236 ret = true;
1277 } 1237 }
1278 1238
1279 XRenderFreePicture (dpy, mask_pic); 1239 XRenderFreePicture (dpy, mask_pic);
1280 XRenderFreePicture (dpy, overlay_pic); 1240 XRenderFreePicture (dpy, overlay_pic);
1299 return 0; 1259 return 0;
1300 1260
1301 /* root dimensions may change from call to call - but Display structure should 1261 /* root dimensions may change from call to call - but Display structure should
1302 * be always up-to-date, so let's use it : 1262 * be always up-to-date, so let's use it :
1303 */ 1263 */
1304 Window root = target->display->root;
1305 int screen = target->display->screen; 1264 int screen = target->display->screen;
1306 Display *dpy = target->dpy; 1265 Display *dpy = target->dpy;
1266 int root_depth = DefaultDepth (dpy, screen);
1307 int root_width = DisplayWidth (dpy, screen); 1267 int root_width = DisplayWidth (dpy, screen);
1308 int root_height = DisplayHeight (dpy, screen); 1268 int root_height = DisplayHeight (dpy, screen);
1269 unsigned int root_pmap_width, root_pmap_height;
1309 int window_width = target->szHint.width; 1270 int window_width = target->szHint.width;
1310 int window_height = target->szHint.height; 1271 int window_height = target->szHint.height;
1311 int sx, sy; 1272 int sx, sy;
1312 XGCValues gcv; 1273 XGCValues gcv;
1313 GC gc; 1274 GC gc;
1314 1275
1315 target->get_window_origin (sx, sy); 1276 sx = target_x;
1277 sy = target_y;
1316 1278
1317 /* check if we are outside of the visible part of the virtual screen : */ 1279 /* check if we are outside of the visible part of the virtual screen : */
1318 if (sx + window_width <= 0 || sy + window_height <= 0 1280 if (sx + window_width <= 0 || sy + window_height <= 0
1319 || sx >= root_width || sy >= root_height) 1281 || sx >= root_width || sy >= root_height)
1320 return 0; 1282 return 0;
1321 1283
1284 // validate root pixmap and get its size
1285 if (root_pixmap != None)
1286 {
1287 Window wdummy;
1288 int idummy;
1289 unsigned int udummy;
1290
1291 target->allowedxerror = -1;
1292
1293 if (!XGetGeometry (dpy, root_pixmap, &wdummy, &idummy, &idummy, &root_pmap_width, &root_pmap_height, &udummy, &udummy))
1294 root_pixmap = None;
1295
1296 target->allowedxerror = 0;
1297 }
1298
1299 Pixmap recoded_root_pmap = root_pixmap;
1300
1301 if (root_pixmap != None && root_depth != target->depth)
1302 {
1303#if XRENDER
1304 if (flags & HAS_RENDER)
1305 {
1306 XRenderPictureAttributes pa;
1307
1308 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen));
1309 Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, &pa);
1310
1311 recoded_root_pmap = XCreatePixmap (dpy, target->vt, root_pmap_width, root_pmap_height, target->depth);
1312 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, target->visual);
1313 Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, &pa);
1314
1315 if (src && dst)
1316 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, root_pmap_width, root_pmap_height);
1317 else
1318 {
1319 XFreePixmap (dpy, recoded_root_pmap);
1320 root_pixmap = None;
1321 }
1322
1323 XRenderFreePicture (dpy, src);
1324 XRenderFreePicture (dpy, dst);
1325 }
1326 else
1327#endif
1328 root_pixmap = None;
1329 }
1330
1322 if (root_pixmap == None) 1331 if (root_pixmap == None)
1323 return 0; 1332 return 0;
1324 1333
1325 Pixmap tiled_root_pmap = XCreatePixmap (dpy, root, window_width, window_height, root_depth); 1334 Pixmap tiled_root_pmap = XCreatePixmap (dpy, target->vt, window_width, window_height, target->depth);
1326 1335
1327 if (tiled_root_pmap == None) /* something really bad happened - abort */ 1336 if (tiled_root_pmap == None) /* something really bad happened - abort */
1328 return 0; 1337 return 0;
1329 1338
1330 /* straightforward pixmap copy */ 1339 /* straightforward pixmap copy */
1331 gcv.tile = root_pixmap;
1332 gcv.fill_style = FillTiled;
1333
1334 while (sx < 0) sx += (int)root_width; 1340 while (sx < 0) sx += (int)root_width;
1335 while (sy < 0) sy += (int)root_height; 1341 while (sy < 0) sy += (int)root_height;
1336 1342
1343 gcv.tile = recoded_root_pmap;
1344 gcv.fill_style = FillTiled;
1337 gcv.ts_x_origin = -sx; 1345 gcv.ts_x_origin = -sx;
1338 gcv.ts_y_origin = -sy; 1346 gcv.ts_y_origin = -sy;
1339 gc = XCreateGC (dpy, root, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); 1347 gc = XCreateGC (dpy, target->vt, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv);
1340 1348
1341 if (gc) 1349 if (gc)
1342 { 1350 {
1343 XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height); 1351 XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height);
1344 result |= transpPmapTiled; 1352 result |= transpPmapTiled;
1345 XFreeGC (dpy, gc); 1353 XFreeGC (dpy, gc);
1346 }
1347 1354
1348 if (tiled_root_pmap != None) 1355 if (!(flags & CLIENT_RENDER))
1349 {
1350 if (!need_client_side_rendering ())
1351 {
1352 if (flags & (blurNeeded | blurServerSide))
1353 { 1356 {
1357 if ((flags & blurNeeded)
1358 && (flags & HAS_RENDER_CONV))
1359 {
1354 if (blur_pixmap (tiled_root_pmap, DefaultVisual (dpy, screen), window_width, window_height)) 1360 if (blur_pixmap (tiled_root_pmap, target->visual, window_width, window_height))
1355 result |= transpPmapBlurred; 1361 result |= transpPmapBlurred;
1356 } 1362 }
1357 if (flags & (tintNeeded | tintServerSide)) 1363 if ((flags & tintNeeded)
1364 && (flags & (tintWholesome | HAS_RENDER)))
1358 { 1365 {
1359 if (tint_pixmap (tiled_root_pmap, DefaultVisual (dpy, screen), window_width, window_height)) 1366 if (tint_pixmap (tiled_root_pmap, target->visual, window_width, window_height))
1360 result |= transpPmapTinted; 1367 result |= transpPmapTinted;
1361 } 1368 }
1362 } /* server side rendering completed */ 1369 } /* server side rendering completed */
1363 1370
1364 if (pixmap) 1371 if (pixmap)
1365 XFreePixmap (dpy, pixmap); 1372 XFreePixmap (dpy, pixmap);
1366 1373
1367 pixmap = tiled_root_pmap; 1374 pixmap = tiled_root_pmap;
1368 pmap_width = window_width; 1375 pmap_width = window_width;
1369 pmap_height = window_height; 1376 pmap_height = window_height;
1370 pmap_depth = root_depth; 1377 pmap_depth = target->depth;
1371 } 1378 }
1379 else
1380 XFreePixmap (dpy, tiled_root_pmap);
1381
1382 if (recoded_root_pmap != root_pixmap)
1383 XFreePixmap (dpy, recoded_root_pmap);
1372 1384
1373 return result; 1385 return result;
1374} 1386}
1375 1387
1376void 1388void
1377bgPixmap_t::set_root_pixmap () 1389bgPixmap_t::set_root_pixmap ()
1378{ 1390{
1379 Pixmap new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID); 1391 Pixmap new_root_pixmap = target->get_pixmap_property (target->xa[XA_XROOTPMAP_ID]);
1380 if (new_root_pixmap == None) 1392 if (new_root_pixmap == None)
1381 new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID); 1393 new_root_pixmap = target->get_pixmap_property (target->xa[XA_ESETROOT_PMAP_ID]);
1382 1394
1383 root_pixmap = new_root_pixmap; 1395 root_pixmap = new_root_pixmap;
1384
1385 // validate root pixmap
1386 if (root_pixmap != None)
1387 {
1388 unsigned int width, height;
1389 Window wdummy;
1390 int idummy;
1391 unsigned int udummy;
1392
1393 target->allowedxerror = -1;
1394
1395 if (!XGetGeometry (target->dpy, root_pixmap, &wdummy, &idummy, &idummy, &width, &height, &udummy, &udummy))
1396 root_pixmap = None;
1397
1398 target->allowedxerror = 0;
1399 }
1400} 1396}
1401# endif /* ENABLE_TRANSPARENCY */ 1397# endif /* ENABLE_TRANSPARENCY */
1402 1398
1403# ifndef HAVE_AFTERIMAGE 1399#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1404static void ShadeXImage(Visual *visual, XImage *srcImage, int shade, int rm, int gm, int bm); 1400static void shade_ximage (Visual *visual, XImage *ximage, int shade, const rgba &c);
1405# endif 1401# endif
1406 1402
1407bool 1403bool
1408bgPixmap_t::render () 1404bgPixmap_t::render ()
1409{ 1405{
1418 { 1414 {
1419 /* we need to re-generate transparency pixmap in that case ! */ 1415 /* we need to re-generate transparency pixmap in that case ! */
1420 background_flags = make_transparency_pixmap (); 1416 background_flags = make_transparency_pixmap ();
1421 if (background_flags == 0) 1417 if (background_flags == 0)
1422 return false; 1418 return false;
1423 else if ((background_flags & transpTransformations) == (flags & transpTransformations) 1419 else if ((background_flags & transpTransformations) == (flags & transpTransformations))
1424 && pmap_depth == target->depth)
1425 flags = flags & ~isInvalid; 1420 flags &= ~isInvalid;
1426 } 1421 }
1427# endif 1422# endif
1428 1423
1429# ifdef BG_IMAGE_FROM_FILE 1424# ifdef BG_IMAGE_FROM_FILE
1430 if (have_image 1425 if (have_image
1431 || (background_flags & transpTransformations) != (flags & transpTransformations)) 1426 || (background_flags & transpTransformations) != (flags & transpTransformations))
1432 { 1427 {
1433 if (render_image (background_flags)) 1428 if (render_image (background_flags))
1434 flags = flags & ~isInvalid; 1429 flags &= ~isInvalid;
1435 } 1430 }
1436# endif 1431# endif
1437 1432
1433# if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1438 XImage *result = NULL; 1434 XImage *result = NULL;
1439 1435
1440 if (background_flags && (flags & isInvalid)) 1436 if (background_flags && (flags & isInvalid))
1441 { 1437 {
1442 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); 1438 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap);
1443 } 1439 }
1444 1440
1445 if (result) 1441 if (result)
1446 { 1442 {
1447# if !defined(HAVE_AFTERIMAGE) && !XRENDER
1448 /* our own client-side tinting */ 1443 /* our own client-side tinting */
1449 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) 1444 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded))
1450 { 1445 {
1451 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 1446 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1452 if (flags & tintSet) 1447 if (flags & tintSet)
1453 tint.get (c); 1448 tint.get (c);
1454 ShadeXImage (DefaultVisual (target->dpy, target->display->screen), result, shade, c.r, c.g, c.b); 1449 shade_ximage (DefaultVisual (target->dpy, target->display->screen), result, shade, c);
1455 } 1450 }
1456# endif
1457 1451
1458 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); 1452 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL);
1459 1453
1460 if (gc) 1454 if (gc)
1461 { 1455 {
1462 if (/*pmap_depth != target->depth &&*/ pixmap != None)
1463 {
1464 XFreePixmap (target->dpy, pixmap);
1465 pixmap = None;
1466 }
1467
1468 if (pixmap == None)
1469 {
1470 pixmap = XCreatePixmap (target->dpy, target->vt, result->width, result->height, target->depth);
1471 pmap_width = result->width;
1472 pmap_height = result->height;
1473 pmap_depth = target->depth;
1474 }
1475
1476 if (pmap_depth != result->depth)
1477 {
1478 /* Bad Match error will ensue ! stupid X !!!! */
1479 if (result->depth == 24 && pmap_depth == 32)
1480 result->depth = 32;
1481 else if (result->depth == 32 && pmap_depth == 24)
1482 result->depth = 24;
1483 else
1484 {
1485 /* TODO: implement image recoding */
1486 }
1487 }
1488
1489 if (pmap_depth == result->depth)
1490 XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height); 1456 XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height);
1491 1457
1492 XFreeGC (target->dpy, gc); 1458 XFreeGC (target->dpy, gc);
1493 flags = flags & ~isInvalid; 1459 flags &= ~isInvalid;
1494 } 1460 }
1495 1461
1496 XDestroyImage (result); 1462 XDestroyImage (result);
1497 } 1463 }
1464# endif
1498 1465
1499 if (flags & isInvalid) 1466 if (flags & isInvalid)
1500 { 1467 {
1501 if (pixmap != None) 1468 if (pixmap != None)
1502 { 1469 {
1510 valid_since = ev::now (); 1477 valid_since = ev::now ();
1511 1478
1512 return true; 1479 return true;
1513} 1480}
1514 1481
1515bool 1482void
1516bgPixmap_t::set_target (rxvt_term *new_target) 1483bgPixmap_t::set_target (rxvt_term *new_target)
1517{ 1484{
1518 if (new_target)
1519 if (target != new_target)
1520 {
1521 target = new_target; 1485 target = new_target;
1522# ifdef ENABLE_TRANSPARENCY 1486
1523 root_depth = DefaultDepthOfScreen (ScreenOfDisplay (target->dpy, target->display->screen)); 1487 flags &= ~(HAS_RENDER | HAS_RENDER_CONV);
1488#if XRENDER
1489 int major, minor;
1490 if (XRenderQueryVersion (target->dpy, &major, &minor))
1491 flags |= HAS_RENDER;
1492 XFilters *filters = XRenderQueryFilters (target->dpy, target->vt);
1493 if (filters)
1494 {
1495 for (int i = 0; i < filters->nfilter; i++)
1496 if (!strcmp (filters->filter[i], FilterConvolution))
1497 flags |= HAS_RENDER_CONV;
1498
1499 XFree (filters);
1500 }
1524# endif 1501#endif
1525 return true;
1526 }
1527
1528 return false;
1529} 1502}
1530 1503
1531void 1504void
1532bgPixmap_t::apply () 1505bgPixmap_t::apply ()
1533{ 1506{
1534 if (target) 1507 if (target == NULL)
1535 { 1508 return;
1509
1536 if (pixmap != None) 1510 if (pixmap != None)
1537 { 1511 {
1538 /* set target's background to pixmap */ 1512 /* set target's background to pixmap */
1539# ifdef ENABLE_TRANSPARENCY 1513# ifdef ENABLE_TRANSPARENCY
1540 if (flags & isTransparent) 1514 if (flags & isTransparent)
1541 { 1515 {
1542 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap); 1516 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap);
1543 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative); 1517 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative);
1544 1518
1545 if (target->scrollBar.win) 1519 if (target->scrollBar.win)
1546 XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative); 1520 XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative);
1547 } 1521 }
1548 else 1522 else
1549# endif 1523# endif
1550 { 1524 {
1551 /* force old pixmap dereference in case it was transparent before :*/ 1525 /* force old pixmap dereference in case it was transparent before :*/
1552 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
1553 XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap);
1554 /* do we also need to set scrollbar's background here ? */
1555
1556 if (target->scrollBar.win)
1557 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1558 }
1559 }
1560 else
1561 {
1562 /* set target background to a pixel */
1563 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); 1526 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
1564 XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); 1527 XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap);
1565 /* do we also need to set scrollbar's background here ? */ 1528 /* do we also need to set scrollbar's background here ? */
1529
1566 if (target->scrollBar.win) 1530 if (target->scrollBar.win)
1567 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); 1531 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1568 } 1532 }
1533 }
1534 else
1535 {
1536 /* set target background to a pixel */
1537 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
1538 XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]);
1539 /* do we also need to set scrollbar's background here ? */
1540 if (target->scrollBar.win)
1541 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1542 }
1569 1543
1570 /* don't want Expose on the parent or vt. It is better to use 1544 /* don't want Expose on the parent or vt. It is better to use
1571 scr_touch or we get a great deal of flicker otherwise: */ 1545 scr_touch or we get a great deal of flicker otherwise: */
1572 XClearWindow (target->dpy, target->parent[0]); 1546 XClearWindow (target->dpy, target->parent[0]);
1573 1547
1574 if (target->scrollBar.state && target->scrollBar.win) 1548 if (target->scrollBar.state && target->scrollBar.win)
1575 { 1549 {
1576 target->scrollBar.state = STATE_IDLE; 1550 target->scrollBar.state = STATE_IDLE;
1577 target->scrollBar.show (0); 1551 target->scrollBar.show (0);
1578 } 1552 }
1579 1553
1580 target->want_refresh = 1; 1554 target->want_refresh = 1;
1581 flags |= hasChanged; 1555 flags |= hasChanged;
1582 }
1583} 1556}
1584 1557
1585#endif /* HAVE_BG_PIXMAP */ 1558#endif /* HAVE_BG_PIXMAP */
1586 1559
1587#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) && !XRENDER 1560#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1588/* taken from aterm-0.4.2 */ 1561/* taken from aterm-0.4.2 */
1589 1562
1590static void 1563static void
1591ShadeXImage(Visual *visual, XImage *srcImage, int shade, int rm, int gm, int bm) 1564shade_ximage (Visual *visual, XImage *ximage, int shade, const rgba &c)
1592{ 1565{
1593 int sh_r, sh_g, sh_b; 1566 int sh_r, sh_g, sh_b;
1594 uint32_t mask_r, mask_g, mask_b; 1567 uint32_t mask_r, mask_g, mask_b;
1595 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; 1568 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b;
1596 unsigned int lower_lim_r, lower_lim_g, lower_lim_b; 1569 rgba low;
1597 unsigned int upper_lim_r, upper_lim_g, upper_lim_b; 1570 rgba high;
1598 int i; 1571 int i;
1599 int host_byte_order = byteorder.big_endian () ? MSBFirst : LSBFirst; 1572 int host_byte_order = byteorder::big_endian () ? MSBFirst : LSBFirst;
1600 1573
1601 if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return; 1574 if (visual->c_class != TrueColor || ximage->format != ZPixmap) return;
1602 1575
1603 /* for convenience */ 1576 /* for convenience */
1604 mask_r = visual->red_mask; 1577 mask_r = visual->red_mask;
1605 mask_g = visual->green_mask; 1578 mask_g = visual->green_mask;
1606 mask_b = visual->blue_mask; 1579 mask_b = visual->blue_mask;
1607 1580
1608 /* boring lookup table pre-initialization */ 1581 /* boring lookup table pre-initialization */
1609 switch (srcImage->depth) 1582 switch (ximage->depth)
1610 { 1583 {
1611 case 15: 1584 case 15:
1612 if ((mask_r != 0x7c00) || 1585 if ((mask_r != 0x7c00) ||
1613 (mask_g != 0x03e0) || 1586 (mask_g != 0x03e0) ||
1614 (mask_b != 0x001f)) 1587 (mask_b != 0x001f))
1667 /* prepare limits for color transformation (each channel is handled separately) */ 1640 /* prepare limits for color transformation (each channel is handled separately) */
1668 if (shade > 100) 1641 if (shade > 100)
1669 { 1642 {
1670 shade = 200 - shade; 1643 shade = 200 - shade;
1671 1644
1672 lower_lim_r = 65535-rm; 1645 high.r = c.r * shade / 100;
1673 lower_lim_g = 65535-gm; 1646 high.g = c.g * shade / 100;
1674 lower_lim_b = 65535-bm; 1647 high.b = c.b * shade / 100;
1675 1648
1676 lower_lim_r = 65535-(unsigned int)(((uint32_t)lower_lim_r)*((uint32_t)shade)/100); 1649 low.r = 65535 * (100 - shade) / 100;
1677 lower_lim_g = 65535-(unsigned int)(((uint32_t)lower_lim_g)*((uint32_t)shade)/100); 1650 low.g = 65535 * (100 - shade) / 100;
1678 lower_lim_b = 65535-(unsigned int)(((uint32_t)lower_lim_b)*((uint32_t)shade)/100); 1651 low.b = 65535 * (100 - shade) / 100;
1679
1680 upper_lim_r = upper_lim_g = upper_lim_b = 65535;
1681 } 1652 }
1682 else 1653 else
1683 { 1654 {
1655 high.r = c.r * shade / 100;
1656 high.g = c.g * shade / 100;
1657 high.b = c.b * shade / 100;
1684 1658
1685 lower_lim_r = lower_lim_g = lower_lim_b = 0; 1659 low.r = low.g = low.b = 0;
1686
1687 upper_lim_r = (unsigned int)((((uint32_t)rm)*((uint32_t)shade))/100);
1688 upper_lim_g = (unsigned int)((((uint32_t)gm)*((uint32_t)shade))/100);
1689 upper_lim_b = (unsigned int)((((uint32_t)bm)*((uint32_t)shade))/100);
1690 } 1660 }
1691 1661
1692 /* fill our lookup tables */ 1662 /* fill our lookup tables */
1693 for (i = 0; i <= mask_r>>sh_r; i++) 1663 for (i = 0; i <= mask_r>>sh_r; i++)
1694 { 1664 {
1695 uint32_t tmp; 1665 uint32_t tmp;
1696 tmp = ((uint32_t)i)*((uint32_t)(upper_lim_r-lower_lim_r)); 1666 tmp = i * high.r;
1697 tmp += ((uint32_t)(mask_r>>sh_r))*((uint32_t)lower_lim_r); 1667 tmp += (mask_r>>sh_r) * low.r;
1698 lookup_r[i] = (tmp/65535)<<sh_r; 1668 lookup_r[i] = (tmp/65535)<<sh_r;
1699 } 1669 }
1700 for (i = 0; i <= mask_g>>sh_g; i++) 1670 for (i = 0; i <= mask_g>>sh_g; i++)
1701 { 1671 {
1702 uint32_t tmp; 1672 uint32_t tmp;
1703 tmp = ((uint32_t)i)*((uint32_t)(upper_lim_g-lower_lim_g)); 1673 tmp = i * high.g;
1704 tmp += ((uint32_t)(mask_g>>sh_g))*((uint32_t)lower_lim_g); 1674 tmp += (mask_g>>sh_g) * low.g;
1705 lookup_g[i] = (tmp/65535)<<sh_g; 1675 lookup_g[i] = (tmp/65535)<<sh_g;
1706 } 1676 }
1707 for (i = 0; i <= mask_b>>sh_b; i++) 1677 for (i = 0; i <= mask_b>>sh_b; i++)
1708 { 1678 {
1709 uint32_t tmp; 1679 uint32_t tmp;
1710 tmp = ((uint32_t)i)*((uint32_t)(upper_lim_b-lower_lim_b)); 1680 tmp = i * high.b;
1711 tmp += ((uint32_t)(mask_b>>sh_b))*((uint32_t)lower_lim_b); 1681 tmp += (mask_b>>sh_b) * low.b;
1712 lookup_b[i] = (tmp/65535)<<sh_b; 1682 lookup_b[i] = (tmp/65535)<<sh_b;
1713 } 1683 }
1714 1684
1715 /* apply table to input image (replacing colors by newly calculated ones) */ 1685 /* apply table to input image (replacing colors by newly calculated ones) */
1716 if (srcImage->bits_per_pixel == 32 1686 if (ximage->bits_per_pixel == 32
1717 && (srcImage->depth == 24 || srcImage->depth == 32) 1687 && (ximage->depth == 24 || ximage->depth == 32)
1718 && srcImage->byte_order == host_byte_order) 1688 && ximage->byte_order == host_byte_order)
1719 { 1689 {
1720 uint32_t *p1, *pf, *p, *pl; 1690 uint32_t *p1, *pf, *p, *pl;
1721 p1 = (uint32_t *) srcImage->data; 1691 p1 = (uint32_t *) ximage->data;
1722 pf = (uint32_t *) (srcImage->data + srcImage->height * srcImage->bytes_per_line); 1692 pf = (uint32_t *) (ximage->data + ximage->height * ximage->bytes_per_line);
1723 1693
1724 while (p1 < pf) 1694 while (p1 < pf)
1725 { 1695 {
1726 p = p1; 1696 p = p1;
1727 pl = p1 + srcImage->width; 1697 pl = p1 + ximage->width;
1728 for (; p < pl; p++) 1698 for (; p < pl; p++)
1729 { 1699 {
1730 *p = lookup_r[(*p & 0xff0000) >> 16] | 1700 *p = lookup_r[(*p & 0xff0000) >> 16] |
1731 lookup_g[(*p & 0x00ff00) >> 8] | 1701 lookup_g[(*p & 0x00ff00) >> 8] |
1732 lookup_b[(*p & 0x0000ff)] | 1702 lookup_b[(*p & 0x0000ff)] |
1733 (*p & 0xff000000); 1703 (*p & 0xff000000);
1734 } 1704 }
1735 p1 = (uint32_t *) ((char *) p1 + srcImage->bytes_per_line); 1705 p1 = (uint32_t *) ((char *) p1 + ximage->bytes_per_line);
1736 } 1706 }
1737 } 1707 }
1738 else 1708 else
1739 { 1709 {
1740 for (int y = 0; y < srcImage->height; y++) 1710 for (int y = 0; y < ximage->height; y++)
1741 for (int x = 0; x < srcImage->width; x++) 1711 for (int x = 0; x < ximage->width; x++)
1742 { 1712 {
1743 unsigned long pixel = XGetPixel (srcImage, x, y); 1713 unsigned long pixel = XGetPixel (ximage, x, y);
1744 pixel = lookup_r[(pixel & mask_r) >> sh_r] | 1714 pixel = lookup_r[(pixel & mask_r) >> sh_r] |
1745 lookup_g[(pixel & mask_g) >> sh_g] | 1715 lookup_g[(pixel & mask_g) >> sh_g] |
1746 lookup_b[(pixel & mask_b) >> sh_b]; 1716 lookup_b[(pixel & mask_b) >> sh_b];
1747 XPutPixel (srcImage, x, y, pixel); 1717 XPutPixel (ximage, x, y, pixel);
1748 } 1718 }
1749 } 1719 }
1750 1720
1751 free (lookup); 1721 free (lookup);
1752} 1722}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines