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.63 by sasha, Wed Aug 8 22:39:49 2007 UTC vs.
Revision 1.67 by sasha, Tue Aug 14 14:06:51 2007 UTC

82 if (h_scale != 0 || v_scale != 0) 82 if (h_scale != 0 || v_scale != 0)
83 return true; 83 return true;
84 } 84 }
85# endif 85# endif
86# ifdef ENABLE_TRANSPARENCY 86# ifdef ENABLE_TRANSPARENCY
87 if (flags & bgPmap_Transparent) 87 if (flags & isTransparent)
88 return true; 88 return true;
89# endif 89# endif
90 return false; 90 return false;
91} 91}
92 92
160 dst_size = target_size - dst_pos; 160 dst_size = target_size - dst_pos;
161 return src_pos; 161 return src_pos;
162} 162}
163 163
164bool 164bool
165bgPixmap_t::handle_geometry (const char *geom) 165bgPixmap_t::set_geometry (const char *geom)
166{ 166{
167 int geom_flags = 0, changed = 0; 167 int geom_flags = 0, changed = 0;
168 int x = 0, y = 0; 168 int x = 0, y = 0;
169 unsigned int w = 0, h = 0; 169 unsigned int w = 0, h = 0;
170 unsigned int n; 170 unsigned int n;
171 unsigned long new_flags = (flags&(~bgPmap_geometryFlags)); 171 unsigned long new_flags = (flags & (~geometryFlags));
172 char *p; 172 char *p;
173# define MAXLEN_GEOM 256 /* could be longer then regular geometry string */ 173# define MAXLEN_GEOM 256 /* could be longer then regular geometry string */
174 174
175 if (geom == NULL) 175 if (geom == NULL)
176 return false; 176 return false;
177 177
178 char str[MAXLEN_GEOM]; 178 char str[MAXLEN_GEOM];
179 179
180 if (!strcmp (geom, "?"))
181 {
182 if (target)
183 {
184 sprintf (str, "[%dx%d+%d+%d]", /* can't presume snprintf () ! */
185 min (h_scale, 32767), min (v_scale, 32767),
186 min (h_align, 32767), min (v_align, 32767));
187 target->process_xterm_seq (XTerm_title, str, CHAR_ST);
188 }
189 return false;
190 }
191 while (isspace(*geom)) ++geom; 180 while (isspace(*geom)) ++geom;
192 if ((p = strchr (geom, ';')) == NULL) 181 if ((p = strchr (geom, ';')) == NULL)
193 p = strchr (geom, '\0'); 182 p = strchr (geom, '\0');
194 183
195 n = (p - geom); 184 n = (p - geom);
196 if (n < MAXLEN_GEOM) 185 if (n < MAXLEN_GEOM)
197 { 186 {
198 char *ops; 187 char *ops;
199 new_flags |= bgPmap_geometrySet; 188 new_flags |= geometrySet;
200 189
201 strncpy (str, geom, n); 190 strncpy (str, geom, n);
202 str[n] = '\0'; 191 str[n] = '\0';
203 if (str[0] == ':') 192 if (str[0] == ':')
204 ops = &str[0]; 193 ops = &str[0];
225 { 214 {
226 y = x; 215 y = x;
227 geom_flags |= YValue; 216 geom_flags |= YValue;
228 } 217 }
229 218
230 if (flags & bgPmap_geometrySet) 219 if (flags & geometrySet)
231 {/* new geometry is an adjustment to the old one ! */ 220 {/* new geometry is an adjustment to the old one ! */
232 if ((geom_flags & WidthValue) && (geom_flags & HeightValue)) 221 if ((geom_flags & WidthValue) && (geom_flags & HeightValue))
233 { 222 {
234 if (w == 0 && h != 0) 223 if (w == 0 && h != 0)
235 { 224 {
253 } 242 }
254 else /* setting up geometry from scratch */ 243 else /* setting up geometry from scratch */
255 { 244 {
256 if (!(geom_flags & XValue)) 245 if (!(geom_flags & XValue))
257 {/* use default geometry - centered */ 246 {/* use default geometry - centered */
258 x = y = bgPmap_defaultAlign; 247 x = y = defaultAlign;
259 } 248 }
260 else if (!(geom_flags & YValue)) 249 else if (!(geom_flags & YValue))
261 y = x; 250 y = x;
262 251
263 if ((geom_flags & (WidthValue|HeightValue)) == 0) 252 if ((geom_flags & (WidthValue|HeightValue)) == 0)
264 {/* use default geometry - scaled */ 253 {/* use default geometry - scaled */
265 w = h = bgPmap_defaultScale; 254 w = h = defaultScale;
266 } 255 }
267 else if (geom_flags & WidthValue) 256 else if (geom_flags & WidthValue)
268 { 257 {
269 if (!(geom_flags & HeightValue)) 258 if (!(geom_flags & HeightValue))
270 h = w; 259 h = w;
271 } 260 }
272 else 261 else
273 w = h; 262 w = h;
274 } 263 }
275 } /* done parsing geometry string */ 264 } /* done parsing geometry string */
276 else if (!(flags & bgPmap_geometrySet)) 265 else if (!(flags & geometrySet))
277 { /* default geometry - scaled and centered */ 266 { /* default geometry - scaled and centered */
278 x = y = bgPmap_defaultAlign; 267 x = y = defaultAlign;
279 w = h = bgPmap_defaultScale; 268 w = h = defaultScale;
280 } 269 }
281 270
282 if (!(flags & bgPmap_geometrySet)) 271 if (!(flags & geometrySet))
283 geom_flags |= WidthValue|HeightValue|XValue|YValue; 272 geom_flags |= WidthValue|HeightValue|XValue|YValue;
284 273
285 if (ops) 274 if (ops)
286 { 275 {
287 while (*ops) 276 while (*ops)
298 if (w == 0 && h == 0) 287 if (w == 0 && h == 0)
299 { 288 {
300 w = 100; 289 w = 100;
301 geom_flags |= WidthValue; 290 geom_flags |= WidthValue;
302 } 291 }
303 new_flags |= bgPmap_propScale; 292 new_flags |= propScale;
304 } 293 }
305 else if (CHECK_GEOM_OPS("hscale")) 294 else if (CHECK_GEOM_OPS("hscale"))
306 { 295 {
307 if (w == 0) 296 if (w == 0)
308 w = 100; 297 w = 100;
538 527
539 if (result != background && result != original_asim) 528 if (result != background && result != original_asim)
540 destroy_asimage (&result); 529 destroy_asimage (&result);
541 530
542 XFreeGC (target->dpy, gc); 531 XFreeGC (target->dpy, gc);
543 if (background)
544 flags |= bgPmap_Transparent;
545 else
546 flags &= ~bgPmap_Transparent;
547 } 532 }
548 533
549 return true; 534 return true;
550} 535}
551# endif /* HAVE_AFTERIMAGE */ 536# endif /* HAVE_AFTERIMAGE */
552 537
553void 538bool
554rxvt_term::resize_pixmap () 539bgPixmap_t::set_file (const char *file)
555{ 540{
541 char *f;
556 542
557# ifdef ENABLE_TRANSPARENCY 543 assert (file != NULL);
558 if (option(Opt_transparent) && am_transparent) 544
559 { 545 if (*file != '\0')
560 /* we need to re-generate transparency pixmap in that case ! */
561 check_our_parents ();
562 return;
563 } 546 {
564# endif
565# ifdef HAVE_AFTERIMAGE 547# ifdef HAVE_AFTERIMAGE
566 bgPixmap.render_asim(NULL, TINT_LEAVE_SAME);
567 bgPixmap.apply_background();
568# endif
569}
570
571void
572rxvt_term::set_bgPixmap (const char *file)
573{
574 char *f;
575
576 assert (file != NULL);
577
578 if (bgPixmap.pixmap != None)
579 {
580 XFreePixmap (dpy, bgPixmap.pixmap);
581 bgPixmap.pixmap = None;
582 }
583
584 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]);
585 if (*file != '\0')
586 {
587# ifdef HAVE_AFTERIMAGE
588 if (asimman == NULL) 548 if (target->asimman == NULL)
589 asimman = create_generic_imageman(rs[Rs_path]); 549 target->asimman = create_generic_imageman(target->rs[Rs_path]);
590 if ((f = strchr (file, ';')) == NULL) 550 if ((f = strchr (file, ';')) == NULL)
591 bgPixmap.original_asim = get_asimage( asimman, file, 0xFFFFFFFF, 100 ); 551 original_asim = get_asimage( target->asimman, file, 0xFFFFFFFF, 100 );
592 else 552 else
593 { 553 {
594 size_t len = f - file; 554 size_t len = f - file;
595 f = (char *)malloc (len + 1); 555 f = (char *)malloc (len + 1);
596 strncpy (f, file, len); 556 strncpy (f, file, len);
597 f[len] = '\0'; 557 f[len] = '\0';
598 bgPixmap.original_asim = get_asimage( asimman, f, 0xFFFFFFFF, 100 ); 558 original_asim = get_asimage( target->asimman, f, 0xFFFFFFFF, 100 );
599 free( f ); 559 free( f );
600 } 560 }
561 return (original_asim != NULL);
601# endif 562# endif
602 } 563 }
603 resize_pixmap (); /* TODO: temporary fix - should be done by the caller! */ 564 return false;
604} 565}
605 566
606# endif /* XPM_BACKGROUND */ 567# endif /* XPM_BACKGROUND */
607 568
608# ifdef ENABLE_TRANSPARENCY 569# ifdef ENABLE_TRANSPARENCY
570bool
571bgPixmap_t::set_transparent ()
572{
573 if (!(flags & isTransparent))
574 {
575 flags |= isTransparent;
576 return true;
577 }
578}
579
580bool
581bgPixmap_t::set_blur_radius (const char *geom)
582{
583 int changed = 0;
584 unsigned int hr, vr;
585 int junk;
586 int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr);
587 if (!(geom_flags&WidthValue))
588 hr = 1;
589 if (!(geom_flags&HeightValue))
590 vr = hr;
591
592 if (h_blurRadius != hr)
593 {
594 ++changed;
595 h_blurRadius = hr;
596 }
597 if (v_blurRadius != vr)
598 {
599 ++changed;
600 v_blurRadius = vr;
601 }
602 return (changed>0);
603}
604
605static inline unsigned long
606compute_tint_shade_flags (rxvt_color *tint, int shade)
607{
608 unsigned long flags = 0;
609
610 if (shade > 0 && shade <100)
611 flags |= bgPixmap_t::tintNeeded;
612 else if (tint)
613 {
614 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
615 tint->get (c);
616
617 flags |= bgPixmap_t::tintNeeded;
618 if ((c.r > 0x000700 || c.g > 0x000700 || c.b > 0x000700)
619 && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700))
620 {
621 flags |= bgPixmap_t::tintNeeded;
622#define IS_COMPONENT_WHOLESOME(cmp) ((cmp) <= 0x000700 || (cmp) >= 0x00f700)
623 if (IS_COMPONENT_WHOLESOME (c.r)
624 && IS_COMPONENT_WHOLESOME (c.g)
625 && IS_COMPONENT_WHOLESOME (c.b))
626 flags |= bgPixmap_t::tintServerSide;
627#undef IS_COMPONENT_WHOLESOME
628 }
629 }
630 return flags;
631}
632
633bool
634bgPixmap_t::set_tint (rxvt_color &new_tint)
635{
636 if (tint != new_tint)
637 {
638 unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade);
639 tint = new_tint;
640 flags = (flags & ~tintFlags) | new_flags | tintSet;
641 return true;
642 }
643 return false;
644}
645
646bool
647bgPixmap_t::unset_tint ()
648{
649 unsigned long new_flags = compute_tint_shade_flags (NULL, shade);
650
651 if (new_flags != (flags & tintFlags))
652 {
653 flags = (flags&~tintFlags)|new_flags;
654 return true;
655 }
656 return false;
657}
658
659bool
660bgPixmap_t::set_shade (const char *shade_str)
661{
662 int new_shade = (shade_str) ? atoi (shade_str) : 0;
663
664 if (new_shade == 100)
665 new_shade = 0;
666
667 if (new_shade != shade)
668 {
669 unsigned long new_flags = compute_tint_shade_flags (&tint, new_shade);
670 shade = new_shade;
671 flags = (flags & ~tintFlags) | new_flags;
672 return true;
673 }
674 return false;
675}
676
677
609/* make_transparency_pixmap() 678/* make_transparency_pixmap()
610 * 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
611 * 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
612 * our window. 681 * our window.
613 */ 682 */
614#if 0 683unsigned long
684bgPixmap_t::make_transparency_pixmap ()
685{
686 unsigned long result = 0;
687
688 if (target == NULL)
689 return 0;
690
691 /* root dimentions may change from call to call - but Display structure should
692 * be always up-to-date, so let's use it :
693 */
694 Window root = target->display->root;
695 int screen = target->display->screen;
696 Display *dpy = target->dpy;
697 int root_width = DisplayWidth (dpy, screen);
698 int root_height = DisplayHeight (dpy, screen);
699 unsigned int root_pmap_width, root_pmap_height;
700 int window_width = target->szHint.width;
701 int window_height = target->szHint.height;
702 int sx, sy;
703 XGCValues gcv;
704
705 target->get_window_origin (sx, sy);
706
707 /* check if we are outside of the visible part of the virtual screen : */
708 if (sx + window_width <= 0 || sy + window_height <= 0
709 || sx >= root_width || sy >= root_height)
710 return 0;
711
712 if (root_pixmap != None)
713 {/* we want to validate the pixmap and get it's size at the same time : */
714 int junk;
715 unsigned int ujunk;
716 /* root pixmap may be bad - allow a error */
717 target->allowedxerror = -1;
718 if (!XGetGeometry (dpy, root_pixmap, &root, &junk, &junk, &root_pmap_width, &root_pmap_height, &ujunk, &ujunk))
719 root_pixmap = None;
720 target->allowedxerror = 0;
721 }
722
723 Pixmap tiled_root_pmap = XCreatePixmap (dpy, root, window_width, window_height, root_depth);
724 GC gc = NULL;
725
726 if (tiled_root_pmap == None) /* something really bad happened - abort */
727 return 0;
728
729 if (root_pixmap == None)
730 { /* use tricks to obtain the root background image :*/
731 /* we want to create Overrideredirect window overlapping out window
732 with background type of Parent Relative and then grab it */
733 XSetWindowAttributes attr;
734 Window src;
735 bool success = false;
736
737 attr.background_pixmap = ParentRelative;
738 attr.backing_store = Always;
739 attr.event_mask = ExposureMask;
740 attr.override_redirect = True;
741 src = XCreateWindow (dpy, root, sx, sy, window_width, window_height, 0,
742 CopyFromParent, CopyFromParent, CopyFromParent,
743 CWBackPixmap|CWBackingStore|CWOverrideRedirect|CWEventMask,
744 &attr);
745
746 if (src != None)
747 {
748 XEvent event;
749 int ev_count = 0;
750 XGrabServer (dpy);
751 XMapRaised (dpy, src);
752 XSync (dpy, False);
753 /* XSync should get window where it's properly exposed,
754 * but to be on the safe side - let's check for the actuall event to arrive : */
755 while (XCheckWindowEvent (dpy, src, ExposureMask, &event))
756 ++ev_count;
757 if (ev_count > 0);
758 { /* hooray! - we can grab the image! */
759 gc = XCreateGC (dpy, root, 0, NULL);
760 if (gc)
761 {
762 XCopyArea (dpy, src, tiled_root_pmap, gc, 0, 0, window_width, window_height, 0, 0);
763 success = true;
764 }
765 }
766 XDestroyWindow (dpy, src);
767 XUngrabServer (dpy);
768 //fprintf (stderr, "%s:%d: ev_count = %d\n", __FUNCTION__, __LINE__, ev_count);
769 }
770 if (!success)
771 {
772 XFreePixmap (dpy, tiled_root_pmap);
773 tiled_root_pmap = None;
774 }
775 else
776 result |= transpPmapTiled;
777 }
778 else
779 {/* strightforward pixmap copy */
780 gcv.tile = root_pixmap;
781 gcv.fill_style = FillTiled;
782 while (sx < 0) sx += (int)window_width;
783 while (sy < 0) sy += (int)window_height;
784 gcv.ts_x_origin = -sx;
785 gcv.ts_y_origin = -sy;
786 gc = XCreateGC (dpy, root, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv);
787 if (gc)
788 {
789 XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height);
790 result |= transpPmapTiled;
791 }
792 }
793
794 if (tiled_root_pmap != None)
795 {
796 if (flags & tintNeeded)
797 {
798 if ((flags & tintServerSide)
799 && h_blurRadius <= 1 && v_blurRadius <= 1
800# ifdef HAVE_AFTERIMAGE
801 && original_asim == NULL
802# endif
803 )
804 { /* In this case we can tint image server-side getting significant
805 * performance improvements, as we eliminate XImage transfer
806 */
807 gcv.foreground = Pixel (tint);
808 gcv.function = GXand;
809 gcv.fill_style = FillSolid;
810 if (gc)
811 XChangeGC (dpy, gc, GCFillStyle | GCForeground | GCFunction, &gcv);
812 else
813 gc = XCreateGC (dpy, root, GCFillStyle | GCForeground | GCFunction, &gcv);
814 if (gc)
815 {
816 XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height);
817 result |= transpPmapTinted;
818 }
819 }
820 }
821 if (pixmap)
822 XFreePixmap (dpy, pixmap);
823 pixmap = tiled_root_pmap;
824 pmap_width = window_width;
825 pmap_height = window_height;
826 pmap_depth = root_depth;
827 }
828
829 if (gc)
830 XFreeGC (dpy, gc);
831
832 return result;
833}
834
615bool 835bool
616bgPixmap_t::make_transparency_pixmap() 836bgPixmap_t::set_root_pixmap ()
617{ 837{
838 Pixmap new_root_pixmap = None;
839
840 new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID);
841 if (new_root_pixmap == None)
842 new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID);
843
844 if (new_root_pixmap != root_pixmap)
845 {
846 root_pixmap = new_root_pixmap;
847 return true;
848 }
849 return false;
850}
851# endif /* ENABLE_TRANSPARENCY */
852
853# ifndef HAVE_AFTERIMAGE
854static void ShadeXImage(rxvt_term *term, XImage* srcImage, int shade, int rm, int gm, int bm);
855#endif
856
857
858bool
859bgPixmap_t::render ()
860{
861 unsigned long background_flags = 0;
862
618 if (target == NULL) 863 if (target == NULL)
619 return false; 864 return false;
620 865
621 int sx, sy; 866 invalidate();
622 Window cr; 867# ifdef ENABLE_TRANSPARENCY
623 XTranslateCoordinates (target->dpy, target->parent[0], target->display->root, 868 if (flags & isTransparent)
624 0, 0, &sx, &sy, &cr); 869 {
870 /* we need to re-generate transparency pixmap in that case ! */
871 background_flags = make_transparency_pixmap ();
872 if (background_flags == 0)
873 return false;
874 else if ((background_flags & transpTransformations) == (flags & transpTransformations)
875 && pmap_depth == target->depth)
876 flags = flags & ~isInvalid;
877 }
878# endif
625 879
626 /* check if we are outside of the visible part of the virtual screen : */ 880 XImage *result = NULL;
627 if( sx + (int)szHint.width <= 0 || sy + (int)szHint.height <= 0 881# ifdef HAVE_AFTERIMAGE
628 || sx >= wrootattr.width || sy >= wrootattr.height ) 882 if (original_asim
883 || (background_flags & transpTransformations) != (flags & transpTransformations))
884 {
885 ASImage *background = NULL;
886 ARGB32 as_tint = TINT_LEAVE_SAME;
887 if (background_flags)
888 background = pixmap2ximage (target->asv, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, 100);
889
890 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded))
891 {
892 ShadingInfo as_shade;
893 as_shade.shading = (shade == 0) ? 100 : shade;
894
895 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
896 tint.get (c);
897 as_shade.tintColor.red = c.r;
898 as_shade.tintColor.green = c.g;
899 as_shade.tintColor.blue = c.b;
900
901 as_tint = shading2tint32 (&as_shade);
902 }
903 if (render_asim (background, as_tint))
904 flags = flags & ~isInvalid;
905 if (background)
906 destroy_asimage (&background);
907 }
908 else if (background_flags && pmap_depth != target->depth)
909 {
910 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap);
911 }
912# else /* our own client-side tinting */
913 if (background_flags && (flags & isInvalid))
914 {
915 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap);
916 if (result != NULL && !(background_flags & transpPmapTinted) && (flags & tintNeeded))
917 {
918 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
919 tint.get (c);
920 ShadeXImage (target, result, shade, c.r, c.g, c.b);
921 }
922 }
923# endif
924 if (result != NULL)
925 {
926 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL);
927 if (gc)
928 {
929 if (pmap_depth != target->depth && pixmap != None)
930 {
931 XFreePixmap (target->dpy, pixmap);
932 pixmap = None;
933 }
934 if (pixmap == None)
935 {
936 pixmap = XCreatePixmap (target->dpy, target->vt, result->width, result->height, target->depth);
937 pmap_width = result->width;
938 pmap_height = result->height;
939 pmap_depth = target->depth;
940 }
941 XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height);
942 XFreeGC (target->dpy, gc);
943 flags = flags & ~isInvalid;
944 }
945 XDestroyImage (result);
946 }
947
948 if (flags & isInvalid)
949 {
950 if (pixmap != None)
951 {
952 XFreePixmap (target->dpy, pixmap);
953 pixmap = None;
954 }
955// TODO : we need to get rid of that garbadge :
956 target->am_transparent = target->am_pixmap_trans = 0;
957 }
958 else
959 target->am_transparent = target->am_pixmap_trans = 1;
960
961 apply ();
962
963 return true;
964}
965
966bool
967bgPixmap_t::set_target (rxvt_term *new_target)
968{
969 if (new_target)
970 if (target != new_target)
971 {
972 target = new_target;
973# ifdef ENABLE_TRANSPARENCY
974 root_depth = DefaultDepthOfScreen (ScreenOfDisplay (target->dpy, target->display->screen));
975# endif
976 return true;
977 }
629 return false ; 978 return false;
630
631 XWindowAttributes wattr, wrootattr;
632
633 XGetWindowAttributes (dpy, display->root, &wrootattr);
634
635 /*
636 * Make the frame window set by the window manager have
637 * the root background. Some window managers put multiple nested frame
638 * windows for each client, so we have to take care about that.
639 */
640 i = (xa[XA_XROOTPMAP_ID]
641 && XGetWindowProperty (dpy, display->root, xa[XA_XROOTPMAP_ID],
642 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
643 &nitems, &bytes_after, &prop) == Success);
644
645 if (!i || prop == NULL)
646 i = (xa[XA_ESETROOT_PMAP_ID]
647 && XGetWindowProperty (dpy, display->root, xa[XA_ESETROOT_PMAP_ID],
648 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
649 &nitems, &bytes_after, &prop) == Success);
650
651 if (!i || prop == NULL)
652 rootpixmap = None;
653
654} 979}
655#endif /* 0 */
656# endif /* ENABLE_TRANSPARENCY */
657 980
658void 981void
659bgPixmap_t::apply_background() 982bgPixmap_t::apply()
660{ 983{
661 if (target) 984 if (target)
662 { 985 {
663 if (pixmap != None) 986 if (pixmap != None)
664 { /* set target's background to pixmap */ 987 { /* set target's background to pixmap */
665# ifdef ENABLE_TRANSPARENCY 988# ifdef ENABLE_TRANSPARENCY
666 if (flags & bgPmap_Transparent) 989 if (flags & isTransparent)
667 { 990 {
668 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap); 991 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap);
669 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative); 992 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative);
993# if HAVE_SCROLLBARS
670 if (target->scrollBar.win) 994 if (target->scrollBar.win)
671 XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative); 995 XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative);
996# endif
672 } 997 }
673 else 998 else
674# endif 999# endif
675 { 1000 {
676 /* force old pixmap dereference in case it was transparent before :*/ 1001 /* force old pixmap dereference in case it was transparent before :*/
677 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_bg]); 1002 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
678 XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap); 1003 XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap);
679 /* do we also need to set scrollbar's background here ? */ 1004 /* do we also need to set scrollbar's background here ? */
1005# if HAVE_SCROLLBARS
1006 if (target->scrollBar.win)
1007 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1008# endif
680 } 1009 }
681 } 1010 }
682 else 1011 else
683 { /* set target background to a pixel */ 1012 { /* set target background to a pixel */
684 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_bg]); 1013 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
685 XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); 1014 XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]);
686 /* do we also need to set scrollbar's background here ? */ 1015 /* do we also need to set scrollbar's background here ? */
1016# if HAVE_SCROLLBARS
1017 if (target->scrollBar.win)
1018 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1019# endif
687 } 1020 }
688 /* don't want Expose on the parent */ 1021 /* don't want Expose on the parent */
689 XClearArea (target->dpy, target->parent[0], 0, 0, 0, 0, False); 1022 XClearArea (target->dpy, target->parent[0], 0, 0, 0, 0, False);
690 /* do want Expose on the vt */ 1023 /* do want Expose on the vt */
691 XClearArea (target->dpy, target->parent[0], 0, 0, 0, 0, True); 1024 XClearArea (target->dpy, target->parent[0], 0, 0, 0, 0, True);
1025#if HAVE_SCROLLBARS
1026 if (target->scrollBar.win)
1027 {
1028 target->scrollBar.setIdle ();
1029 target->scrollbar_show (0);
1030 }
1031#endif
1032 target->want_refresh = target->want_full_refresh = 1;
1033 target->flush ();
692 } 1034 }
693} 1035}
694#endif /* HAVE_BG_PIXMAP */ 1036#endif /* HAVE_BG_PIXMAP */
695 1037
1038
1039void
1040rxvt_term::get_window_origin (int &x, int &y)
1041{
1042 Window cr;
1043 XTranslateCoordinates (dpy, parent[0], display->root, 0, 0, &x, &y, &cr);
1044}
1045
1046Pixmap
1047rxvt_term::get_pixmap_property (int prop_id)
1048{
1049 if (prop_id > 0 && prop_id < NUM_XA)
1050 if (xa[prop_id])
1051 {
1052 int aformat, rootdepth;
1053 unsigned long nitems, bytes_after;
1054 Atom atype;
1055 unsigned char *prop = NULL;
1056 int result = XGetWindowProperty (dpy, display->root, xa[prop_id],
1057 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
1058 &nitems, &bytes_after, &prop);
1059 if (result == Success && prop && atype == XA_PIXMAP)
1060 {
1061 return *(Pixmap *)prop;
1062 }
1063 }
1064 return None;
1065}
696 1066
697 1067
698#ifdef ENABLE_TRANSPARENCY 1068#ifdef ENABLE_TRANSPARENCY
699#ifndef HAVE_AFTERIMAGE 1069#ifndef HAVE_AFTERIMAGE
700/* taken from aterm-0.4.2 */ 1070/* taken from aterm-0.4.2 */
711 unsigned int upper_lim_r, upper_lim_g, upper_lim_b; 1081 unsigned int upper_lim_r, upper_lim_g, upper_lim_b;
712 int i; 1082 int i;
713 1083
714 Visual *visual = term->visual; 1084 Visual *visual = term->visual;
715 1085
716 if( visual->c_class != TrueColor || srcImage->format != ZPixmap ) return ; 1086 if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return ;
717 1087
1088 if (shade == 0)
1089 shade = 100;
1090
718 /* for convenience */ 1091 /* for convenience */
719 mask_r = visual->red_mask; 1092 mask_r = visual->red_mask;
720 mask_g = visual->green_mask; 1093 mask_g = visual->green_mask;
721 mask_b = visual->blue_mask; 1094 mask_b = visual->blue_mask;
722 1095
941} 1314}
942 1315
943void 1316void
944rxvt_term::check_our_parents_cb (time_watcher &w) 1317rxvt_term::check_our_parents_cb (time_watcher &w)
945{ 1318{
1319#if 0 /* replaced by a bgPixmap_t::render() - leve here temporarily for reference */
1320
946 int i, aformat, rootdepth; 1321 int i, aformat, rootdepth;
947 unsigned long nitems, bytes_after; 1322 unsigned long nitems, bytes_after;
948 Atom atype; 1323 Atom atype;
949 unsigned char *prop = NULL; 1324 unsigned char *prop = NULL;
950 Window root, oldp, *list; 1325 Window root, oldp, *list;
954 Window cr; 1329 Window cr;
955 unsigned int rootpixmap_w = 0, rootpixmap_h = 0; 1330 unsigned int rootpixmap_w = 0, rootpixmap_h = 0;
956 1331
957 if (!option (Opt_transparent)) 1332 if (!option (Opt_transparent))
958 return; /* Don't try any more */ 1333 return; /* Don't try any more */
959
960#if 0 1334#if 0
961 struct timeval stv; 1335 struct timeval stv;
962 gettimeofday (&stv,NULL); 1336 gettimeofday (&stv,NULL);
963#define PRINT_BACKGROUND_OP_TIME do{ struct timeval tv;gettimeofday (&tv,NULL); tv.tv_sec-= stv.tv_sec;\ 1337#define PRINT_BACKGROUND_OP_TIME do{ struct timeval tv;gettimeofday (&tv,NULL); tv.tv_sec-= stv.tv_sec;\
964 fprintf (stderr,"%d: elapsed %ld usec\n",__LINE__,\ 1338 fprintf (stderr,"%d: elapsed %ld usec\n",__LINE__,\
1047 whole_tint = (IS_COMPONENT_WHOLESOME(c.r) 1421 whole_tint = (IS_COMPONENT_WHOLESOME(c.r)
1048 && IS_COMPONENT_WHOLESOME(c.g) 1422 && IS_COMPONENT_WHOLESOME(c.g)
1049 && IS_COMPONENT_WHOLESOME(c.b)); 1423 && IS_COMPONENT_WHOLESOME(c.b));
1050 no_tint = (c.r >= 0x00f700 && c.g >= 0x00f700 && c.b >= 0x00f700); 1424 no_tint = (c.r >= 0x00f700 && c.g >= 0x00f700 && c.b >= 0x00f700);
1051#undef IS_COMPONENT_WHOLESOME 1425#undef IS_COMPONENT_WHOLESOME
1052 /* theer are no performance advantages to reusing same pixmap */
1053 if (bgPixmap.pixmap != None)
1054 XFreePixmap (dpy, bgPixmap.pixmap);
1055 bgPixmap.pixmap = XCreatePixmap (dpy, vt, szHint.width, szHint.height, rootdepth);
1056 bgPixmap.pmap_width = szHint.width;
1057 bgPixmap.pmap_height = szHint.height;
1058 bgPixmap.pmap_depth = rootdepth;
1059 1426
1060#if 0 /* TODO : identify cases where this will be detrimental to performance : */ 1427 bgPixmap.make_transparency_pixmap();
1061 /* we want to tile root pixmap into our own pixmap in this cases :
1062 * 1) rootpixmap does not cover our window entirely
1063 * 2) whole_tint - we can use server-side tinting or tinting disabled
1064 */
1065 if ( whole_tint || no_tint || pmap_w < sx + szHint.width || pmap_h < sy + szHint.height)
1066 {
1067 }
1068#endif
1069 gcvalue.tile = rootpixmap;
1070 gcvalue.fill_style = FillTiled;
1071 gcvalue.ts_x_origin = -sx;
1072 gcvalue.ts_y_origin = -sy;
1073 gc = XCreateGC (dpy, rootpixmap, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcvalue);
1074 XFillRectangle (dpy, bgPixmap.pixmap, gc, 0, 0, szHint.width, szHint.height);
1075 1428
1076 if (whole_tint && !no_tint) 1429 if (whole_tint && !no_tint)
1077 { 1430 {
1078 /* In this case we can tint image server-side getting significant
1079 * performance improvements, as we eliminate XImage transfer
1080 */
1081 gcvalue.foreground = Pixel (pix_colors_focused [Color_tint]);
1082 gcvalue.function = GXand;
1083 gcvalue.fill_style = FillSolid;
1084 XChangeGC (dpy, gc, GCFillStyle | GCForeground | GCFunction, &gcvalue);
1085 XFillRectangle (dpy, bgPixmap.pixmap, gc, 0, 0, szHint.width, szHint.height);
1086 } 1431 }
1087 success = True; 1432 success = True;
1088#ifdef HAVE_AFTERIMAGE 1433#ifdef HAVE_AFTERIMAGE
1089 if (rs[Rs_blurradius] || bgPixmap.original_asim != NULL || (!whole_tint && (!no_tint || shade !=100))) 1434 if (rs[Rs_blurradius] || bgPixmap.original_asim != NULL || (!whole_tint && (!no_tint || shade !=100)))
1090 { 1435 {
1153 PRINT_BACKGROUND_OP_TIME; 1498 PRINT_BACKGROUND_OP_TIME;
1154 1499
1155 if (gc != NULL) 1500 if (gc != NULL)
1156 XFreeGC (dpy, gc); 1501 XFreeGC (dpy, gc);
1157 1502
1158 bgPixmap.apply_background(); 1503 bgPixmap.apply();
1159 if (!success) 1504 if (!success)
1160 am_pixmap_trans = 0; 1505 am_pixmap_trans = 0;
1161 else 1506 else
1162 { 1507 {
1163 am_transparent = am_pixmap_trans = 1; 1508 am_transparent = am_pixmap_trans = 1;
1177 want_refresh = want_full_refresh = 1; 1522 want_refresh = want_full_refresh = 1;
1178 if (am_pixmap_trans) 1523 if (am_pixmap_trans)
1179 flush (); 1524 flush ();
1180 } 1525 }
1181 } 1526 }
1527#endif
1182} 1528}
1183#endif 1529#endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines