ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/xpm.C
(Generate patch)

Comparing rxvt-unicode/src/xpm.C (file contents):
Revision 1.65 by sasha, Fri Aug 10 22:10:36 2007 UTC vs.
Revision 1.66 by sasha, Mon Aug 13 22:41:34 2007 UTC

678/* make_transparency_pixmap() 678/* make_transparency_pixmap()
679 * Builds a pixmap sized the same as terminal window, with depth same as the root window 679 * Builds a pixmap sized the same as terminal window, with depth same as the root window
680 * that pixmap contains tiled portion of the root pixmap that is supposed to be covered by 680 * that pixmap contains tiled portion of the root pixmap that is supposed to be covered by
681 * our window. 681 * our window.
682 */ 682 */
683bool 683unsigned long
684bgPixmap_t::make_transparency_pixmap () 684bgPixmap_t::make_transparency_pixmap ()
685{ 685{
686 unsigned long result = 0;
687
686 if (target == NULL) 688 if (target == NULL)
687 return false; 689 return 0;
688 690
689 /* root dimentions may change from call to call - but Display structure should 691 /* root dimentions may change from call to call - but Display structure should
690 * be always up-to-date, so let's use it : 692 * be always up-to-date, so let's use it :
691 */ 693 */
692 Window root = target->display->root; 694 Window root = target->display->root;
703 target->get_window_origin (sx, sy); 705 target->get_window_origin (sx, sy);
704 706
705 /* check if we are outside of the visible part of the virtual screen : */ 707 /* check if we are outside of the visible part of the virtual screen : */
706 if (sx + window_width <= 0 || sy + window_height <= 0 708 if (sx + window_width <= 0 || sy + window_height <= 0
707 || sx >= root_width || sy >= root_height) 709 || sx >= root_width || sy >= root_height)
708 return false; 710 return 0;
709 711
710 if (root_pixmap != None) 712 if (root_pixmap != None)
711 {/* we want to validate the pixmap and get it's size at the same time : */ 713 {/* we want to validate the pixmap and get it's size at the same time : */
712 int junk; 714 int junk;
713 unsigned int ujunk; 715 unsigned int ujunk;
720 722
721 Pixmap tiled_root_pmap = XCreatePixmap (dpy, root, window_width, window_height, root_depth); 723 Pixmap tiled_root_pmap = XCreatePixmap (dpy, root, window_width, window_height, root_depth);
722 GC gc = NULL; 724 GC gc = NULL;
723 725
724 if (tiled_root_pmap == None) /* something really bad happened - abort */ 726 if (tiled_root_pmap == None) /* something really bad happened - abort */
725 return false; 727 return 0;
726 728
727 if (root_pixmap == None) 729 if (root_pixmap == None)
728 { /* use tricks to obtain the root background image :*/ 730 { /* use tricks to obtain the root background image :*/
729 /* we want to create Overrideredirect window overlapping out window 731 /* we want to create Overrideredirect window overlapping out window
730 with background type of Parent Relative and then grab it */ 732 with background type of Parent Relative and then grab it */
753 while (XCheckWindowEvent (dpy, src, ExposureMask, &event)) 755 while (XCheckWindowEvent (dpy, src, ExposureMask, &event))
754 ++ev_count; 756 ++ev_count;
755 if (ev_count > 0); 757 if (ev_count > 0);
756 { /* hooray! - we can grab the image! */ 758 { /* hooray! - we can grab the image! */
757 gc = XCreateGC (dpy, root, 0, NULL); 759 gc = XCreateGC (dpy, root, 0, NULL);
760 if (gc)
761 {
758 XCopyArea (dpy, src, tiled_root_pmap, gc, 0, 0, window_width, window_height, 0, 0); 762 XCopyArea (dpy, src, tiled_root_pmap, gc, 0, 0, window_width, window_height, 0, 0);
759 success = true; 763 success = true;
764 }
760 } 765 }
761 XDestroyWindow (dpy, src); 766 XDestroyWindow (dpy, src);
762 XUngrabServer (dpy); 767 XUngrabServer (dpy);
763 //fprintf (stderr, "%s:%d: ev_count = %d\n", __FUNCTION__, __LINE__, ev_count); 768 //fprintf (stderr, "%s:%d: ev_count = %d\n", __FUNCTION__, __LINE__, ev_count);
764 } 769 }
765 if (!success) 770 if (!success)
766 { 771 {
767 XFreePixmap (dpy, tiled_root_pmap); 772 XFreePixmap (dpy, tiled_root_pmap);
768 tiled_root_pmap = None; 773 tiled_root_pmap = None;
769 } 774 }
775 else
776 result |= transpPmapTiled;
770 } 777 }
771 else 778 else
772 {/* strightforward pixmap copy */ 779 {/* strightforward pixmap copy */
773 gcv.tile = root_pixmap; 780 gcv.tile = root_pixmap;
774 gcv.fill_style = FillTiled; 781 gcv.fill_style = FillTiled;
775 while (sx < 0) sx += (int)window_width; 782 while (sx < 0) sx += (int)window_width;
776 while (sy < 0) sy += (int)window_height; 783 while (sy < 0) sy += (int)window_height;
777 gcv.ts_x_origin = -sx; 784 gcv.ts_x_origin = -sx;
778 gcv.ts_y_origin = -sy; 785 gcv.ts_y_origin = -sy;
779 gc = XCreateGC (dpy, root, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); 786 gc = XCreateGC (dpy, root, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv);
787 if (gc)
788 {
780 XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height); 789 XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height);
790 result |= transpPmapTiled;
791 }
781 } 792 }
782 793
783 if (tiled_root_pmap != None) 794 if (tiled_root_pmap != None)
784 { 795 {
785 if (flags & tintNeeded) 796 if (flags & tintNeeded)
798 gcv.fill_style = FillSolid; 809 gcv.fill_style = FillSolid;
799 if (gc) 810 if (gc)
800 XChangeGC (dpy, gc, GCFillStyle | GCForeground | GCFunction, &gcv); 811 XChangeGC (dpy, gc, GCFillStyle | GCForeground | GCFunction, &gcv);
801 else 812 else
802 gc = XCreateGC (dpy, root, GCFillStyle | GCForeground | GCFunction, &gcv); 813 gc = XCreateGC (dpy, root, GCFillStyle | GCForeground | GCFunction, &gcv);
814 if (gc)
815 {
803 XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height); 816 XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height);
817 result |= transpPmapTinted;
818 }
804 } 819 }
805 } 820 }
806 if (pixmap) 821 if (pixmap)
807 XFreePixmap (dpy, pixmap); 822 XFreePixmap (dpy, pixmap);
808 pixmap = tiled_root_pmap; 823 pixmap = tiled_root_pmap;
811 pmap_depth = root_depth; 826 pmap_depth = root_depth;
812 } 827 }
813 828
814 if (gc) 829 if (gc)
815 XFreeGC (dpy, gc); 830 XFreeGC (dpy, gc);
831
832 return result;
816} 833}
817 834
818bool 835bool
819bgPixmap_t::set_root_pixmap () 836bgPixmap_t::set_root_pixmap ()
820{ 837{
832 return false; 849 return false;
833} 850}
834# endif /* ENABLE_TRANSPARENCY */ 851# endif /* ENABLE_TRANSPARENCY */
835 852
836bool 853bool
837bgPixmap_t::render_background () 854bgPixmap_t::render ()
838{ 855{
839 /* TODO: temporary implementation - need to move check_parents stuff in here */ 856 unsigned long background_flags = 0;
857
858 if (target == NULL)
859 return false;
860
861 invalidate();
840# ifdef ENABLE_TRANSPARENCY 862# ifdef ENABLE_TRANSPARENCY
841 if (flags & isTransparent) 863 if (flags & isTransparent)
842 { 864 {
843 /* we need to re-generate transparency pixmap in that case ! */ 865 /* we need to re-generate transparency pixmap in that case ! */
844 target->check_our_parents (); 866 background_flags = make_transparency_pixmap ();
845 return true; 867 if (background_flags == 0)
868 return false;
846 } 869 }
847# endif 870# endif
871
872 XImage *result = NULL;
848# ifdef HAVE_AFTERIMAGE 873# ifdef HAVE_AFTERIMAGE
849 render_asim (NULL, TINT_LEAVE_SAME); 874 if (original_asim
850 apply_background (); 875 || (background_flags & transpTransformations) != (flags & transpTransformations))
876 {
877 ASImage *background = NULL;
878 ARGB32 as_tint = TINT_LEAVE_SAME;
879 if (background_flags)
880 background = pixmap2ximage (target->asv, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, 100);
881
882 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded))
883 {
884 ShadingInfo as_shade;
885 as_shade.shading = (shade == 0) ? 100 : shade;
886
887 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
888 tint.get (c);
889 as_shade.tintColor.red = c.r;
890 as_shade.tintColor.green = c.g;
891 as_shade.tintColor.blue = c.b;
892
893 as_tint = shading2tint32 (&as_shade);
894 }
895 if (render_asim (background, as_tint))
896 flags = flags & ~isInvalid;
897 if (background)
898 destroy_asimage (&background);
899 }
900 else if (background_flags && pmap_depth != target->depth)
901 {
902 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap);
903 }
904# else /* our own client-side tinting */
905 if (background_flags &&
906 (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) || pmap_depth != target->depth)
907 {
908 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap);
909 success = False;
910 if (result != NULL && !(background_flags & transpPmapTinted) && (flags & tintNeeded))
911 {
912 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
913 tint.get (c);
914 ShadeXImage (this, result, shade, c.r, c.g, c.b);
915 }
916 }
917# endif
918 if (result != NULL)
919 {
920 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL);
921 if (gc)
922 {
923 if (pmap_depth != target->depth && pixmap != None)
924 {
925 XFreePixmap (target->dpy, pixmap);
926 pixmap = None;
927 }
928 if (pixmap == None)
929 {
930 pixmap = XCreatePixmap (target->dpy, target->vt, result->width, result->height, target->depth);
931 pmap_width = result->width;
932 pmap_height = result->height;
933 pmap_depth = target->depth;
934 }
935 XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height);
936 XFreeGC (target->dpy, gc);
937 flags = flags & ~isInvalid;
938 }
939 XDestroyImage (result);
940 }
941
942 if (flags & isInvalid)
943 {
944 if (pixmap != None)
945 {
946 XFreePixmap (target->dpy, pixmap);
947 pixmap = None;
948 }
949// TODO : we need to get rid of that garbadge :
950 target->am_transparent = target->am_pixmap_trans = 0;
951 }
952 else
953 target->am_transparent = target->am_pixmap_trans = 1;
954
955 apply ();
956
851 return true; 957 return true;
852# endif
853 return false;
854} 958}
855 959
856bool 960bool
857bgPixmap_t::set_target (rxvt_term *new_target) 961bgPixmap_t::set_target (rxvt_term *new_target)
858{ 962{
867 } 971 }
868 return false; 972 return false;
869} 973}
870 974
871void 975void
872bgPixmap_t::apply_background() 976bgPixmap_t::apply()
873{ 977{
874 if (target) 978 if (target)
875 { 979 {
876 if (pixmap != None) 980 if (pixmap != None)
877 { /* set target's background to pixmap */ 981 { /* set target's background to pixmap */
878# ifdef ENABLE_TRANSPARENCY 982# ifdef ENABLE_TRANSPARENCY
879 if (flags & isTransparent) 983 if (flags & isTransparent)
880 { 984 {
881 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap); 985 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap);
882 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative); 986 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative);
987# if HAVE_SCROLLBARS
883 if (target->scrollBar.win) 988 if (target->scrollBar.win)
884 XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative); 989 XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative);
990# endif
885 } 991 }
886 else 992 else
887# endif 993# endif
888 { 994 {
889 /* force old pixmap dereference in case it was transparent before :*/ 995 /* force old pixmap dereference in case it was transparent before :*/
890 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_bg]); 996 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
891 XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap); 997 XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap);
892 /* do we also need to set scrollbar's background here ? */ 998 /* do we also need to set scrollbar's background here ? */
999# if HAVE_SCROLLBARS
1000 if (target->scrollBar.win)
1001 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1002# endif
893 } 1003 }
894 } 1004 }
895 else 1005 else
896 { /* set target background to a pixel */ 1006 { /* set target background to a pixel */
897 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_bg]); 1007 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
898 XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); 1008 XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]);
899 /* do we also need to set scrollbar's background here ? */ 1009 /* do we also need to set scrollbar's background here ? */
1010# if HAVE_SCROLLBARS
1011 if (target->scrollBar.win)
1012 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1013# endif
900 } 1014 }
901 /* don't want Expose on the parent */ 1015 /* don't want Expose on the parent */
902 XClearArea (target->dpy, target->parent[0], 0, 0, 0, 0, False); 1016 XClearArea (target->dpy, target->parent[0], 0, 0, 0, 0, False);
903 /* do want Expose on the vt */ 1017 /* do want Expose on the vt */
904 XClearArea (target->dpy, target->parent[0], 0, 0, 0, 0, True); 1018 XClearArea (target->dpy, target->parent[0], 0, 0, 0, 0, True);
1019#if HAVE_SCROLLBARS
1020 if (target->scrollBar.win)
1021 {
1022 target->scrollBar.setIdle ();
1023 target->scrollbar_show (0);
1024 }
1025#endif
1026 target->want_refresh = target->want_full_refresh = 1;
1027 target->flush ();
905 } 1028 }
906} 1029}
907#endif /* HAVE_BG_PIXMAP */ 1030#endif /* HAVE_BG_PIXMAP */
908 1031
909 1032
1182} 1305}
1183 1306
1184void 1307void
1185rxvt_term::check_our_parents_cb (time_watcher &w) 1308rxvt_term::check_our_parents_cb (time_watcher &w)
1186{ 1309{
1310#if 0 /* replaced by a bgPixmap_t::render() - leve here temporarily for reference */
1311
1187 int i, aformat, rootdepth; 1312 int i, aformat, rootdepth;
1188 unsigned long nitems, bytes_after; 1313 unsigned long nitems, bytes_after;
1189 Atom atype; 1314 Atom atype;
1190 unsigned char *prop = NULL; 1315 unsigned char *prop = NULL;
1191 Window root, oldp, *list; 1316 Window root, oldp, *list;
1364 PRINT_BACKGROUND_OP_TIME; 1489 PRINT_BACKGROUND_OP_TIME;
1365 1490
1366 if (gc != NULL) 1491 if (gc != NULL)
1367 XFreeGC (dpy, gc); 1492 XFreeGC (dpy, gc);
1368 1493
1369 bgPixmap.apply_background(); 1494 bgPixmap.apply();
1370 if (!success) 1495 if (!success)
1371 am_pixmap_trans = 0; 1496 am_pixmap_trans = 0;
1372 else 1497 else
1373 { 1498 {
1374 am_transparent = am_pixmap_trans = 1; 1499 am_transparent = am_pixmap_trans = 1;
1388 want_refresh = want_full_refresh = 1; 1513 want_refresh = want_full_refresh = 1;
1389 if (am_pixmap_trans) 1514 if (am_pixmap_trans)
1390 flush (); 1515 flush ();
1391 } 1516 }
1392 } 1517 }
1518#endif
1393} 1519}
1394#endif 1520#endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines