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.41 by sf-exg, Sat Aug 21 16:07:15 2010 UTC vs.
Revision 1.62 by sf-exg, Sun Oct 3 21:44:13 2010 UTC

52 * adjustment and may optionally be followed by a colon and one or more 52 * adjustment and may optionally be followed by a colon and one or more
53 * colon-delimited pixmap operations. 53 * colon-delimited pixmap operations.
54 * The following table shows the valid geometry strings and their 54 * The following table shows the valid geometry strings and their
55 * effects on the background image : 55 * effects on the background image :
56 * 56 *
57 * WxH+X+Y Set scaling to W% by H%, and position to X% by Y%. 57 * WxH+X+Y Set scaling to W% by H%, and position to X% by Y%.
58 * W and H are percentages of the terminal window size. 58 * W and H are percentages of the terminal window size.
59 * X and Y are also percentages; e.g., +50+50 centers 59 * X and Y are also percentages; e.g., +50+50 centers
60 * the image in the window. 60 * the image in the window.
61 * WxH+X Assumes Y == X 61 * WxH+X Assumes Y == X
62 * WxH Assumes Y == X == 50 (centers the image) 62 * WxH Assumes Y == X == 50 (centers the image)
63 * W+X+Y Assumes H == W 63 * W+X+Y Assumes H == W
64 * W+X Assumes H == W and Y == X 64 * W+X Assumes H == W and Y == X
65 * W Assumes H == W and Y == X == 50 65 * W Assumes H == W and Y == X == 50
66 * 66 *
67 * Adjusting position only : 67 * Adjusting position only :
68 * =+X+Y Set position to X% by Y% (absolute). 68 * =+X+Y Set position to X% by Y% (absolute).
69 * =+X Set position to X% by X%. 69 * =+X Set position to X% by X%.
70 * +X+Y Adjust position horizontally X% and vertically Y% 70 * +X+Y Adjust position horizontally X% and vertically Y%
71 * from current position (relative). 71 * from current position (relative).
72 * +X Adjust position horizontally X% and vertically X% 72 * +X Adjust position horizontally X% and vertically X%
73 * from current position. 73 * from current position.
74 * 74 *
75 * Adjusting scale only : 75 * Adjusting scale only :
76 * Wx0 Multiply horizontal scaling factor by W% 76 * Wx0 Multiply horizontal scaling factor by W%
77 * 0xH Multiply vertical scaling factor by H% 77 * 0xH Multiply vertical scaling factor by H%
78 * 0x0 No scaling (show image at normal size). 78 * 0x0 No scaling (show image at normal size).
79 * 79 *
80 * Pixmap Operations : (should be prepended by a colon) 80 * Pixmap Operations : (should be prepended by a colon)
81 * tile Tile image. Scaling/position modifiers above will affect 81 * tile Tile image. Scaling/position modifiers above will affect
82 * the tile size and origin. 82 * the tile size and origin.
83 * propscale When scaling, scale proportionally. That is, maintain the 83 * propscale When scaling, scale proportionally. That is, maintain the
84 * proper aspect ratio for the image. Any portion of the 84 * proper aspect ratio for the image. Any portion of the
85 * background not covered by the image is filled with the 85 * background not covered by the image is filled with the
86 * current background color. 86 * current background color.
87 * hscale Scale horizontally, tile vertically ? 87 * hscale Scale horizontally, tile vertically ?
88 * vscale Tile horizontally, scale vertically ? 88 * vscale Tile horizontally, scale vertically ?
96 // this is basically redundant as bgPixmap_t is only used in 96 // this is basically redundant as bgPixmap_t is only used in
97 // zero_initialised-derived structs 97 // zero_initialised-derived structs
98#ifdef HAVE_AFTERIMAGE 98#ifdef HAVE_AFTERIMAGE
99 original_asim = NULL; 99 original_asim = NULL;
100#endif 100#endif
101#ifdef HAVE_PIXBUF
102 pixbuf = NULL;
103#endif
101#ifdef BG_IMAGE_FROM_FILE 104#ifdef BG_IMAGE_FROM_FILE
105 have_image = false;
102 h_scale = v_scale = 0; 106 h_scale = v_scale = 0;
103 h_align = v_align = 0; 107 h_align = v_align = 0;
104#endif 108#endif
105 flags = 0; 109 flags = 0;
106 pixmap = None; 110 pixmap = None;
114#ifdef HAVE_AFTERIMAGE 118#ifdef HAVE_AFTERIMAGE
115 if (original_asim) 119 if (original_asim)
116 safe_asimage_destroy (original_asim); 120 safe_asimage_destroy (original_asim);
117#endif 121#endif
118 122
123#ifdef HAVE_PIXBUF
124 if (pixbuf)
125 g_object_unref (pixbuf);
126#endif
127
119 if (pixmap && target) 128 if (pixmap && target)
120 XFreePixmap (target->dpy, pixmap); 129 XFreePixmap (target->dpy, pixmap);
121} 130}
122 131
123bool 132bool
127 if (flags & isTransparent) 136 if (flags & isTransparent)
128 return true; 137 return true;
129# endif 138# endif
130 139
131# ifdef BG_IMAGE_FROM_FILE 140# ifdef BG_IMAGE_FROM_FILE
132# ifdef HAVE_AFTERIMAGE 141 if (have_image)
133 if (original_asim)
134# endif
135 { 142 {
136 if (h_scale != 0 || v_scale != 0 143 if (flags & sizeSensitive)
137 || h_align != 0 || v_align != 0)
138 return true; 144 return true;
139 } 145 }
140# endif 146# endif
141 147
142 return false; 148 return false;
149 if (flags & isTransparent) 155 if (flags & isTransparent)
150 return true; 156 return true;
151# endif 157# endif
152 158
153# ifdef BG_IMAGE_FROM_FILE 159# ifdef BG_IMAGE_FROM_FILE
154# ifdef HAVE_AFTERIMAGE 160 if (have_image)
155 if (original_asim)
156# endif
157 { 161 {
158 if (h_align == rootAlign || v_align == rootAlign) 162 if (h_align == rootAlign || v_align == rootAlign)
159 return true; 163 return true;
160 } 164 }
161# endif 165# endif
223 227
224static inline int 228static inline int
225make_align_position (int align, int window_size, int image_size) 229make_align_position (int align, int window_size, int image_size)
226{ 230{
227 int diff = window_size - image_size; 231 int diff = window_size - image_size;
228 int smaller = MIN (image_size,window_size); 232 int smaller = min (image_size, window_size);
229 233
230 if (align >= 0 && align <= 50) 234 if (align >= 0 && align <= 50)
231 return diff * align / 100; 235 return diff * align / 100;
232 else if (align > 50 && align <= 100) 236 else if (align > 50 && align <= 100)
233 return window_size - image_size - diff * (100 - align) / 100; 237 return window_size - image_size - diff * (100 - align) / 100;
242make_clip_rectangle (int pos, int size, int target_size, int &dst_pos, int &dst_size) 246make_clip_rectangle (int pos, int size, int target_size, int &dst_pos, int &dst_size)
243{ 247{
244 int src_pos = 0; 248 int src_pos = 0;
245 dst_pos = 0; 249 dst_pos = 0;
246 dst_size = size; 250 dst_size = size;
247 if (pos < 0 && size > target_size) 251 if (pos < 0)
248 { 252 {
249 src_pos = -pos; 253 src_pos = -pos;
250 dst_size += pos; 254 dst_size += pos;
251 } 255 }
252 else if (pos > 0) 256 else if (pos > 0)
383 w = h = noScale; 387 w = h = noScale;
384 geom_flags |= WidthValue|HeightValue; 388 geom_flags |= WidthValue|HeightValue;
385 } 389 }
386 else if (CHECK_GEOM_OPS ("propscale")) 390 else if (CHECK_GEOM_OPS ("propscale"))
387 { 391 {
388 if (w == 0 && h == 0)
389 {
390 w = windowScale;
391 geom_flags |= WidthValue;
392 }
393 new_flags |= propScale; 392 new_flags |= propScale;
394 } 393 }
395 else if (CHECK_GEOM_OPS ("hscale")) 394 else if (CHECK_GEOM_OPS ("hscale"))
396 { 395 {
397 if (w == 0) w = windowScale; 396 if (w == 0) w = windowScale;
441 { 440 {
442 flags = new_flags; 441 flags = new_flags;
443 changed++; 442 changed++;
444 } 443 }
445 444
446//fprintf (stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n", 445 //fprintf (stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n",
447// flags, h_scale, v_scale, h_align, v_align); 446 // flags, h_scale, v_scale, h_align, v_align);
448 return (changed > 0); 447 return (changed > 0);
448}
449
450void
451bgPixmap_t::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y)
452{
453 int target_width = target->szHint.width;
454 int target_height = target->szHint.height;
455
456 if (flags & propScale)
457 {
458 float scale = (float)target_width / image_width;
459 min_it (scale, (float)target_height / image_height);
460 w = image_width * scale + 0.5;
461 h = image_height * scale + 0.5;
462 }
463 else
464 {
465 w = h_scale * target_width / 100;
466 h = v_scale * target_height / 100;
467 }
468
469 if (h_align == rootAlign || v_align == rootAlign)
470 {
471 target->get_window_origin (x, y);
472 x = -x;
473 y = -y;
474 }
475
476 if (h_align != rootAlign)
477 x = make_align_position (h_align, target_width, w > 0 ? w : image_width);
478
479 if (v_align != rootAlign)
480 y = make_align_position (v_align, target_height, h > 0 ? h : image_height);
481
482 flags &= ~sizeSensitive;
483 if (h_scale != 0 || v_scale != 0
484 || h_align != 0 || v_align != 0
485 || image_width > target_width || image_height > target_height)
486 flags |= sizeSensitive;
449} 487}
450 488
451# ifdef HAVE_AFTERIMAGE 489# ifdef HAVE_AFTERIMAGE
452bool 490bool
453bgPixmap_t::render_asim (ASImage *background, ARGB32 background_tint) 491bgPixmap_t::render_image (unsigned long background_flags)
454{ 492{
455 if (target == NULL) 493 if (target == NULL)
456 return false; 494 return false;
457 495
458 target->init_asv (); 496 target->init_asv ();
497
498 ASImage *background = NULL;
499 ARGB32 background_tint = TINT_LEAVE_SAME;
500
501# ifdef ENABLE_TRANSPARENCY
502 if (background_flags)
503 background = pixmap2ximage (target->asv, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, 100);
504
505 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded))
506 {
507 ShadingInfo as_shade;
508 as_shade.shading = (shade == 0) ? 100 : shade;
509
510 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
511 if (flags & tintSet)
512 tint.get (c);
513 as_shade.tintColor.red = c.r;
514 as_shade.tintColor.green = c.g;
515 as_shade.tintColor.blue = c.b;
516
517 background_tint = shading2tint32 (&as_shade);
518 }
519
520 if (!(background_flags & transpPmapBlured) && (flags & blurNeeded) && background != NULL)
521 {
522 ASImage *tmp = blur_asimage_gauss (target->asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF,
523 (original_asim == NULL || tint == TINT_LEAVE_SAME) ? ASA_XImage : ASA_ASImage,
524 100, ASIMAGE_QUALITY_DEFAULT);
525 if (tmp)
526 {
527 destroy_asimage (&background);
528 background = tmp;
529 }
530 }
531# endif
459 532
460 ASImage *result = 0; 533 ASImage *result = 0;
461 534
462 int target_width = target->szHint.width; 535 int target_width = target->szHint.width;
463 int target_height = target->szHint.height; 536 int target_height = target->szHint.height;
464 int new_pmap_width = target_width; 537 int new_pmap_width = target_width;
465 int new_pmap_height = target_height; 538 int new_pmap_height = target_height;
466 539
467 int x = 0; 540 int x = 0;
468 int y = 0; 541 int y = 0;
469 int w = h_scale * target_width / 100; 542 int w = 0;
470 int h = v_scale * target_height / 100; 543 int h = 0;
471 544
472 TIMING_TEST_START (asim); 545 TIMING_TEST_START (asim);
473 546
474 if (original_asim) 547 if (original_asim)
475 { 548 get_image_geometry (original_asim->width, original_asim->height, w, h, x, y);
476 if (h_align == rootAlign || v_align == rootAlign)
477 {
478 target->get_window_origin(x, y);
479 x = -x;
480 y = -y;
481 }
482
483 if (h_align != rootAlign)
484 x = make_align_position (h_align, target_width, w > 0 ? w : (int)original_asim->width);
485
486 if (v_align != rootAlign)
487 y = make_align_position (v_align, target_height, h > 0 ? h : (int)original_asim->height);
488 }
489 549
490 if (!original_asim 550 if (!original_asim
491 || x >= target_width 551 || x >= target_width
492 || y >= target_height 552 || y >= target_height
493 || (w > 0 && x + w <= 0) 553 || (w > 0 && x + w <= 0)
525 100, ASIMAGE_QUALITY_DEFAULT); 585 100, ASIMAGE_QUALITY_DEFAULT);
526 } 586 }
527 587
528 if (background == NULL) 588 if (background == NULL)
529 { 589 {
530 /* if tiling - pixmap has to be sized exactly as the image,
531 but there is no need to make it bigger than the window! */
532 if (h_scale == 0)
533 new_pmap_width = min (result->width, target_width);
534 if (v_scale == 0)
535 new_pmap_height = min (result->height, target_height);
536 /* we also need to tile our image in one or both directions */
537 if (h_scale == 0 || v_scale == 0) 590 if (h_scale == 0 || v_scale == 0)
538 { 591 {
592 /* if tiling - pixmap has to be sized exactly as the image,
593 but there is no need to make it bigger than the window! */
594 new_pmap_width = min (result->width, target_width);
595 new_pmap_height = min (result->height, target_height);
596
597 /* we also need to tile our image in both directions */
539 ASImage *tmp = tile_asimage (target->asv, result, 598 ASImage *tmp = tile_asimage (target->asv, result,
540 (h_scale > 0) ? 0 : (int)result->width - x, 599 (int)result->width - x,
541 (v_scale > 0) ? 0 : (int)result->height - y, 600 (int)result->height - y,
542 new_pmap_width, 601 new_pmap_width,
543 new_pmap_height, 602 new_pmap_height,
544 TINT_LEAVE_SAME, ASA_XImage, 603 TINT_LEAVE_SAME, ASA_XImage,
545 100, ASIMAGE_QUALITY_DEFAULT); 604 100, ASIMAGE_QUALITY_DEFAULT);
546 if (tmp) 605 if (tmp)
554 } 613 }
555 else 614 else
556 { 615 {
557 /* if blending background and image - pixmap has to be sized same as target window */ 616 /* if blending background and image - pixmap has to be sized same as target window */
558 ASImageLayer *layers = create_image_layers (2); 617 ASImageLayer *layers = create_image_layers (2);
559 ASImage *merged_im = NULL;
560 618
561 layers[0].im = background; 619 layers[0].im = background;
562 layers[0].clip_width = target_width; 620 layers[0].clip_width = target_width;
563 layers[0].clip_height = target_height; 621 layers[0].clip_height = target_height;
564 layers[0].tint = background_tint; 622 layers[0].tint = background_tint;
611 free (layers); 669 free (layers);
612 } 670 }
613 } 671 }
614 TIMING_TEST_PRINT_RESULT (asim); 672 TIMING_TEST_PRINT_RESULT (asim);
615 673
616 if (pixmap) 674 bool ret = false;
617 {
618 if (result == NULL
619 || pmap_width != new_pmap_width
620 || pmap_height != new_pmap_height
621 || pmap_depth != target->depth)
622 {
623 XFreePixmap (target->dpy, pixmap);
624 pixmap = None;
625 }
626 }
627 675
628 if (result) 676 if (result)
629 { 677 {
630 XGCValues gcv; 678 XGCValues gcv;
631 GC gc; 679 GC gc;
680
681 if (pixmap)
682 {
683 if (pmap_width != new_pmap_width
684 || pmap_height != new_pmap_height
685 || pmap_depth != target->depth)
686 {
687 XFreePixmap (target->dpy, pixmap);
688 pixmap = None;
689 }
690 }
632 691
633 /* create Pixmap */ 692 /* create Pixmap */
634 if (pixmap == None) 693 if (pixmap == None)
635 { 694 {
636 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); 695 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth);
637 pmap_width = new_pmap_width; 696 pmap_width = new_pmap_width;
638 pmap_height = new_pmap_height; 697 pmap_height = new_pmap_height;
639 pmap_depth = target->depth; 698 pmap_depth = target->depth;
640 } 699 }
641 /* fill with background color ( if result's not completely overlapping it)*/ 700 /* fill with background color (if result's not completely overlapping it) */
642 gcv.foreground = target->pix_colors[Color_bg]; 701 gcv.foreground = target->pix_colors[Color_bg];
643 gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv); 702 gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv);
644 703
645 int src_x = 0, src_y = 0, dst_x = 0, dst_y = 0; 704 int src_x = 0, src_y = 0, dst_x = 0, dst_y = 0;
646 int dst_width = result->width, dst_height = result->height; 705 int dst_width = result->width, dst_height = result->height;
647 if (background == NULL) 706 if (background == NULL)
648 { 707 {
708 if (!(h_scale == 0 || v_scale == 0))
709 {
649 if (h_scale > 0) src_x = make_clip_rectangle (x, result->width , new_pmap_width , dst_x, dst_width ); 710 src_x = make_clip_rectangle (x, result->width , new_pmap_width , dst_x, dst_width );
650 if (v_scale > 0) src_y = make_clip_rectangle (y, result->height, new_pmap_height, dst_y, dst_height); 711 src_y = make_clip_rectangle (y, result->height, new_pmap_height, dst_y, dst_height);
712 }
651 713
652 if (dst_x > 0 || dst_y > 0 714 if (dst_x > 0 || dst_y > 0
653 || dst_x + dst_width < new_pmap_width 715 || dst_x + dst_width < new_pmap_width
654 || dst_y + dst_height < new_pmap_height) 716 || dst_y + dst_height < new_pmap_height)
655 XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); 717 XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height);
662 if (result != background && result != original_asim) 724 if (result != background && result != original_asim)
663 destroy_asimage (&result); 725 destroy_asimage (&result);
664 726
665 XFreeGC (target->dpy, gc); 727 XFreeGC (target->dpy, gc);
666 TIMING_TEST_PRINT_RESULT (asim); 728 TIMING_TEST_PRINT_RESULT (asim);
667 }
668 729
730 ret = true;
731 }
732
733 if (background)
734 destroy_asimage (&background);
735
669 return true; 736 return ret;
670} 737}
671# endif /* HAVE_AFTERIMAGE */ 738# endif /* HAVE_AFTERIMAGE */
739
740# ifdef HAVE_PIXBUF
741bool
742bgPixmap_t::render_image (unsigned long background_flags)
743{
744 if (target == NULL)
745 return false;
746
747 if (!pixbuf)
748 return false;
749
750 // TODO: add alpha blending
751 if (background_flags)
752 return false;
753
754 GdkPixbuf *result;
755
756 int image_width = gdk_pixbuf_get_width (pixbuf);
757 int image_height = gdk_pixbuf_get_height (pixbuf);
758
759 int target_width = target->szHint.width;
760 int target_height = target->szHint.height;
761 int new_pmap_width = target_width;
762 int new_pmap_height = target_height;
763
764 int x = 0;
765 int y = 0;
766 int w = 0;
767 int h = 0;
768
769 get_image_geometry (image_width, image_height, w, h, x, y);
770
771 if (x >= target_width
772 || y >= target_height
773 || (w > 0 && x + w <= 0)
774 || (h > 0 && y + h <= 0))
775 return false;
776
777 result = pixbuf;
778
779 if ((w > 0 && w != image_width)
780 || (h > 0 && h != image_height))
781 {
782 result = gdk_pixbuf_scale_simple (pixbuf,
783 w > 0 ? w : image_width,
784 h > 0 ? h : image_height,
785 GDK_INTERP_BILINEAR);
786 }
787
788 bool ret = false;
789
790 if (result)
791 {
792 XGCValues gcv;
793 GC gc;
794
795 image_width = gdk_pixbuf_get_width (result);
796 image_height = gdk_pixbuf_get_height (result);
797
798 if (h_scale == 0 || v_scale == 0)
799 {
800 new_pmap_width = min (image_width, target_width);
801 new_pmap_height = min (image_height, target_height);
802 }
803
804 if (pixmap)
805 {
806 if (pmap_width != new_pmap_width
807 || pmap_height != new_pmap_height
808 || pmap_depth != target->depth)
809 {
810 XFreePixmap (target->dpy, pixmap);
811 pixmap = None;
812 }
813 }
814
815 if (pixmap == None)
816 {
817 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth);
818 pmap_width = new_pmap_width;
819 pmap_height = new_pmap_height;
820 pmap_depth = target->depth;
821 }
822
823 gcv.foreground = target->pix_colors[Color_bg];
824 gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv);
825
826 if (h_scale == 0 || v_scale == 0)
827 {
828 Pixmap tile = XCreatePixmap (target->dpy, target->vt, image_width, image_height, target->depth);
829 gdk_pixbuf_xlib_render_to_drawable (result, tile, gc,
830 0, 0,
831 0, 0,
832 image_width, image_height,
833 XLIB_RGB_DITHER_NONE,
834 0, 0);
835
836 gcv.tile = tile;
837 gcv.fill_style = FillTiled;
838 gcv.ts_x_origin = x;
839 gcv.ts_y_origin = y;
840 XChangeGC (target->dpy, gc, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv);
841
842 XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height);
843 XFreePixmap (target->dpy, tile);
844 }
845 else
846 {
847 int src_x, src_y, dst_x, dst_y;
848 int dst_width, dst_height;
849
850 src_x = make_clip_rectangle (x, image_width , new_pmap_width , dst_x, dst_width );
851 src_y = make_clip_rectangle (y, image_height, new_pmap_height, dst_y, dst_height);
852
853 if (dst_x > 0 || dst_y > 0
854 || dst_x + dst_width < new_pmap_width
855 || dst_y + dst_height < new_pmap_height)
856 XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height);
857
858 if (dst_x < new_pmap_width && dst_y < new_pmap_height)
859 gdk_pixbuf_xlib_render_to_drawable (result, pixmap, gc,
860 src_x, src_y,
861 dst_x, dst_y,
862 dst_width, dst_height,
863 XLIB_RGB_DITHER_NONE,
864 0, 0);
865 }
866
867 if (result != pixbuf)
868 g_object_unref (result);
869
870 XFreeGC (target->dpy, gc);
871
872 ret = true;
873 }
874
875 return ret;
876}
877# endif /* HAVE_PIXBUF */
672 878
673bool 879bool
674bgPixmap_t::set_file (const char *file) 880bgPixmap_t::set_file (const char *file)
675{ 881{
676 assert (file); 882 assert (file);
677 883
678 if (*file) 884 if (*file)
679 { 885 {
886 if (const char *p = strchr (file, ';'))
887 {
888 size_t len = p - file;
889 char *f = rxvt_temp_buf<char> (len + 1);
890 memcpy (f, file, len);
891 f[len] = '\0';
892 file = f;
893 }
894
680# ifdef HAVE_AFTERIMAGE 895# ifdef HAVE_AFTERIMAGE
681 if (!target->asimman) 896 if (!target->asimman)
682 target->asimman = create_generic_imageman (target->rs[Rs_path]); 897 target->asimman = create_generic_imageman (target->rs[Rs_path]);
683
684 if (const char *p = strchr (file, ';'))
685 {
686 size_t len = p - file;
687 char *f = (char *)malloc (len + 1);
688 memcpy (f, file, len);
689 f[len] = '\0';
690 original_asim = get_asimage (target->asimman, f, 0xFFFFFFFF, 100);
691 free (f);
692 }
693 else
694 original_asim = get_asimage (target->asimman, file, 0xFFFFFFFF, 100); 898 original_asim = get_asimage (target->asimman, file, 0xFFFFFFFF, 100);
899 if (original_asim)
900 have_image = true;
901 return have_image;
902# endif
695 903
696 return original_asim; 904# ifdef HAVE_PIXBUF
905 pixbuf = gdk_pixbuf_new_from_file (file, NULL);
906 if (pixbuf)
907 have_image = true;
908 return have_image;
697# endif 909# endif
698 } 910 }
699 911
700 return false; 912 return false;
701} 913}
721 int changed = 0; 933 int changed = 0;
722 unsigned int hr, vr; 934 unsigned int hr, vr;
723 int junk; 935 int junk;
724 int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); 936 int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr);
725 937
726 if (!(geom_flags&WidthValue)) 938 if (!(geom_flags & WidthValue))
727 hr = 1; 939 hr = 1;
728 if (!(geom_flags&HeightValue)) 940 if (!(geom_flags & HeightValue))
729 vr = hr; 941 vr = hr;
730 942
731 if (h_blurRadius != hr) 943 if (h_blurRadius != hr)
732 { 944 {
733 ++changed; 945 ++changed;
743 if (v_blurRadius == 0 && h_blurRadius == 0) 955 if (v_blurRadius == 0 && h_blurRadius == 0)
744 flags &= ~blurNeeded; 956 flags &= ~blurNeeded;
745 else 957 else
746 flags |= blurNeeded; 958 flags |= blurNeeded;
747 959
748 return (changed>0); 960 return (changed > 0);
749} 961}
750 962
751static inline unsigned long 963static inline unsigned long
752compute_tint_shade_flags (rxvt_color *tint, int shade) 964compute_tint_shade_flags (rxvt_color *tint, int shade)
753{ 965{
770 flags |= bgPixmap_t::tintNeeded; 982 flags |= bgPixmap_t::tintNeeded;
771 else if (tint) 983 else if (tint)
772 { 984 {
773 if ((c.r > 0x000700 || c.g > 0x000700 || c.b > 0x000700) 985 if ((c.r > 0x000700 || c.g > 0x000700 || c.b > 0x000700)
774 && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700)) 986 && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700))
775 { 987 {
776 flags |= bgPixmap_t::tintNeeded; 988 flags |= bgPixmap_t::tintNeeded;
777 } 989 }
778 } 990 }
779 991
780 if (flags & bgPixmap_t::tintNeeded) 992 if (flags & bgPixmap_t::tintNeeded)
781 { 993 {
782 if (flags & bgPixmap_t::tintWholesome) 994 if (flags & bgPixmap_t::tintWholesome)
811{ 1023{
812 unsigned long new_flags = compute_tint_shade_flags (NULL, shade); 1024 unsigned long new_flags = compute_tint_shade_flags (NULL, shade);
813 1025
814 if (new_flags != (flags & tintFlags)) 1026 if (new_flags != (flags & tintFlags))
815 { 1027 {
816 flags = (flags&~tintFlags)|new_flags; 1028 flags = (flags & ~tintFlags) | new_flags;
817 return true; 1029 return true;
818 } 1030 }
819 1031
820 return false; 1032 return false;
821} 1033}
822 1034
907 1119
908 attr.background_pixmap = ParentRelative; 1120 attr.background_pixmap = ParentRelative;
909 attr.backing_store = Always; 1121 attr.backing_store = Always;
910 attr.event_mask = ExposureMask; 1122 attr.event_mask = ExposureMask;
911 attr.override_redirect = True; 1123 attr.override_redirect = True;
912 src = XCreateWindow (dpy, root, sx, sy, window_width, window_height, 0, 1124 src = XCreateWindow (dpy, root, sx, sy, window_width, window_height, 0,
913 CopyFromParent, CopyFromParent, CopyFromParent, 1125 CopyFromParent, CopyFromParent, CopyFromParent,
914 CWBackPixmap|CWBackingStore|CWOverrideRedirect|CWEventMask, 1126 CWBackPixmap|CWBackingStore|CWOverrideRedirect|CWEventMask,
915 &attr); 1127 &attr);
916 1128
917 if (src != None) 1129 if (src != None)
941 XDestroyWindow (dpy, src); 1153 XDestroyWindow (dpy, src);
942 XUngrabServer (dpy); 1154 XUngrabServer (dpy);
943 //fprintf (stderr, "%s:%d: ev_count = %d\n", __FUNCTION__, __LINE__, ev_count); 1155 //fprintf (stderr, "%s:%d: ev_count = %d\n", __FUNCTION__, __LINE__, ev_count);
944 } 1156 }
945 1157
946 if (!success) 1158 if (!success)
947 { 1159 {
948 XFreePixmap (dpy, tiled_root_pmap); 1160 XFreePixmap (dpy, tiled_root_pmap);
949 tiled_root_pmap = None; 1161 tiled_root_pmap = None;
950 } 1162 }
951 else 1163 else
952 result |= transpPmapTiled; 1164 result |= transpPmapTiled;
953 } 1165 }
954 else 1166 else
955 { 1167 {
956 /* straightforward pixmap copy */ 1168 /* straightforward pixmap copy */
957 gcv.tile = root_pixmap; 1169 gcv.tile = root_pixmap;
1074# if DO_TIMING_TEST 1286# if DO_TIMING_TEST
1075 XSync (dpy, False); 1287 XSync (dpy, False);
1076# endif 1288# endif
1077# endif 1289# endif
1078 } 1290 }
1079 } 1291 }
1080 } /* server side rendering completed */ 1292 } /* server side rendering completed */
1081 1293
1082 if (pixmap) 1294 if (pixmap)
1083 XFreePixmap (dpy, pixmap); 1295 XFreePixmap (dpy, pixmap);
1084 1296
1134 /* we need to re-generate transparency pixmap in that case ! */ 1346 /* we need to re-generate transparency pixmap in that case ! */
1135 background_flags = make_transparency_pixmap (); 1347 background_flags = make_transparency_pixmap ();
1136 if (background_flags == 0) 1348 if (background_flags == 0)
1137 return false; 1349 return false;
1138 else if ((background_flags & transpTransformations) == (flags & transpTransformations) 1350 else if ((background_flags & transpTransformations) == (flags & transpTransformations)
1139 && pmap_depth == target->depth) 1351 && pmap_depth == target->depth)
1140 flags = flags & ~isInvalid; 1352 flags = flags & ~isInvalid;
1141 } 1353 }
1142# endif 1354# endif
1143 1355
1356# ifdef BG_IMAGE_FROM_FILE
1357 if (have_image
1358 || (background_flags & transpTransformations) != (flags & transpTransformations))
1359 {
1360 if (render_image (background_flags))
1361 flags = flags & ~isInvalid;
1362 }
1363# endif
1364
1144 XImage *result = NULL; 1365 XImage *result = NULL;
1145# ifdef HAVE_AFTERIMAGE 1366
1146 if (original_asim 1367 if (background_flags && (flags & isInvalid))
1147 || (background_flags & transpTransformations) != (flags & transpTransformations)) 1368 {
1369 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap);
1148 { 1370 }
1149 target->init_asv ();
1150 1371
1151 ASImage *background = NULL; 1372 if (result)
1152 ARGB32 as_tint = TINT_LEAVE_SAME; 1373 {
1153 if (background_flags) 1374# if !defined(HAVE_AFTERIMAGE) && !XFT
1154 background = pixmap2ximage (target->asv, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, 100); 1375 /* our own client-side tinting */
1155 1376 /* ATTENTION: We ASSUME that XFT will let us do all the tinting necessary server-side.
1156# ifdef ENABLE_TRANSPARENCY 1377 This may need to be changed in need_client_side_rendering() logic is altered !!! */
1157 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) 1378 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded))
1158 {
1159 ShadingInfo as_shade;
1160 as_shade.shading = (shade == 0) ? 100 : shade;
1161
1162 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1163 if (flags & tintSet)
1164 tint.get (c);
1165 as_shade.tintColor.red = c.r;
1166 as_shade.tintColor.green = c.g;
1167 as_shade.tintColor.blue = c.b;
1168
1169 as_tint = shading2tint32 (&as_shade);
1170 }
1171
1172 if (!(background_flags & transpPmapBlured) && (flags & blurNeeded) && background != NULL)
1173 {
1174 ASImage *tmp = blur_asimage_gauss (target->asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF,
1175 (original_asim == NULL || tint == TINT_LEAVE_SAME)?ASA_XImage:ASA_ASImage,
1176 100, ASIMAGE_QUALITY_DEFAULT);
1177 if (tmp)
1178 {
1179 destroy_asimage (&background);
1180 background = tmp;
1181 }
1182 }
1183# endif
1184
1185 if (render_asim (background, as_tint))
1186 flags = flags & ~isInvalid;
1187 if (background)
1188 destroy_asimage (&background);
1189 }
1190 else if (background_flags && pmap_depth != target->depth)
1191 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap);
1192
1193# elif !XFT /* our own client-side tinting */
1194
1195 /* ATTENTION: We ASSUME that XFT will let us do all the tinting necessary server-side.
1196 This may need to be changed in need_client_side_rendering() logic is altered !!! */
1197
1198 if (background_flags && (flags & isInvalid))
1199 {
1200 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap);
1201
1202 if (result != NULL && !(background_flags & transpPmapTinted) && (flags & tintNeeded))
1203 { 1379 {
1204 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 1380 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1205 if (flags & tintSet) 1381 if (flags & tintSet)
1206 tint.get (c); 1382 tint.get (c);
1207 ShadeXImage (target, result, shade, c.r, c.g, c.b); 1383 ShadeXImage (target, result, shade, c.r, c.g, c.b);
1208 } 1384 }
1209 } 1385# endif
1210# endif /* HAVE_AFTERIMAGE */
1211 1386
1212 if (result)
1213 {
1214 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); 1387 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL);
1215 1388
1216 if (gc) 1389 if (gc)
1217 { 1390 {
1218 if (/*pmap_depth != target->depth &&*/ pixmap != None) 1391 if (/*pmap_depth != target->depth &&*/ pixmap != None)
1247 1420
1248 XFreeGC (target->dpy, gc); 1421 XFreeGC (target->dpy, gc);
1249 flags = flags & ~isInvalid; 1422 flags = flags & ~isInvalid;
1250 } 1423 }
1251 1424
1252 XDestroyImage (result); 1425 XDestroyImage (result);
1253 } 1426 }
1254 1427
1255 if (flags & isInvalid) 1428 if (flags & isInvalid)
1256 { 1429 {
1257 if (pixmap != None) 1430 if (pixmap != None)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines