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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines