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.64 by sasha, Thu Aug 9 22:08:21 2007 UTC vs.
Revision 1.65 by sasha, Fri Aug 10 22:10:36 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 */
614bool 683bool
615bgPixmap_t::make_transparency_pixmap() 684bgPixmap_t::make_transparency_pixmap ()
616{ 685{
617 if (target == NULL) 686 if (target == NULL)
618 return false; 687 return false;
619 688
620 /* root dimentions may change from call to call - but Display structure should 689 /* root dimentions may change from call to call - but Display structure should
627 int root_height = DisplayHeight (dpy, screen); 696 int root_height = DisplayHeight (dpy, screen);
628 unsigned int root_pmap_width, root_pmap_height; 697 unsigned int root_pmap_width, root_pmap_height;
629 int window_width = target->szHint.width; 698 int window_width = target->szHint.width;
630 int window_height = target->szHint.height; 699 int window_height = target->szHint.height;
631 int sx, sy; 700 int sx, sy;
701 XGCValues gcv;
632 702
633 target->get_window_origin (sx, sy); 703 target->get_window_origin (sx, sy);
634 704
635 /* check if we are outside of the visible part of the virtual screen : */ 705 /* check if we are outside of the visible part of the virtual screen : */
636 if (sx + window_width <= 0 || sy + window_height <= 0 706 if (sx + window_width <= 0 || sy + window_height <= 0
698 tiled_root_pmap = None; 768 tiled_root_pmap = None;
699 } 769 }
700 } 770 }
701 else 771 else
702 {/* strightforward pixmap copy */ 772 {/* strightforward pixmap copy */
703 XGCValues gcv;
704 gcv.tile = root_pixmap; 773 gcv.tile = root_pixmap;
705 gcv.fill_style = FillTiled; 774 gcv.fill_style = FillTiled;
706 while (sx < 0) sx += (int)window_width; 775 while (sx < 0) sx += (int)window_width;
707 while (sy < 0) sy += (int)window_height; 776 while (sy < 0) sy += (int)window_height;
708 gcv.ts_x_origin = -sx; 777 gcv.ts_x_origin = -sx;
709 gcv.ts_y_origin = -sy; 778 gcv.ts_y_origin = -sy;
710 gc = XCreateGC (dpy, root, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); 779 gc = XCreateGC (dpy, root, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv);
711 XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height); 780 XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height);
712 } 781 }
713 782
714 if (gc)
715 XFreeGC (dpy, gc);
716
717 if (tiled_root_pmap != None) 783 if (tiled_root_pmap != None)
718 { 784 {
785 if (flags & tintNeeded)
786 {
787 if ((flags & tintServerSide)
788 && h_blurRadius <= 1 && v_blurRadius <= 1
789# ifdef HAVE_AFTERIMAGE
790 && original_asim == NULL
791# endif
792 )
793 { /* In this case we can tint image server-side getting significant
794 * performance improvements, as we eliminate XImage transfer
795 */
796 gcv.foreground = Pixel (tint);
797 gcv.function = GXand;
798 gcv.fill_style = FillSolid;
799 if (gc)
800 XChangeGC (dpy, gc, GCFillStyle | GCForeground | GCFunction, &gcv);
801 else
802 gc = XCreateGC (dpy, root, GCFillStyle | GCForeground | GCFunction, &gcv);
803 XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height);
804 }
805 }
719 if (pixmap) 806 if (pixmap)
720 XFreePixmap (dpy, pixmap); 807 XFreePixmap (dpy, pixmap);
721 pixmap = tiled_root_pmap; 808 pixmap = tiled_root_pmap;
722 pmap_width = window_width; 809 pmap_width = window_width;
723 pmap_height = window_height; 810 pmap_height = window_height;
724 pmap_depth = root_depth; 811 pmap_depth = root_depth;
725 } 812 }
813
814 if (gc)
815 XFreeGC (dpy, gc);
726} 816}
727 817
818bool
819bgPixmap_t::set_root_pixmap ()
820{
821 Pixmap new_root_pixmap = None;
822
823 new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID);
824 if (new_root_pixmap == None)
825 new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID);
826
827 if (new_root_pixmap != root_pixmap)
828 {
829 root_pixmap = new_root_pixmap;
830 return true;
831 }
832 return false;
833}
728# endif /* ENABLE_TRANSPARENCY */ 834# endif /* ENABLE_TRANSPARENCY */
835
836bool
837bgPixmap_t::render_background ()
838{
839 /* TODO: temporary implementation - need to move check_parents stuff in here */
840# ifdef ENABLE_TRANSPARENCY
841 if (flags & isTransparent)
842 {
843 /* we need to re-generate transparency pixmap in that case ! */
844 target->check_our_parents ();
845 return true;
846 }
847# endif
848# ifdef HAVE_AFTERIMAGE
849 render_asim (NULL, TINT_LEAVE_SAME);
850 apply_background ();
851 return true;
852# endif
853 return false;
854}
729 855
730bool 856bool
731bgPixmap_t::set_target (rxvt_term *new_target) 857bgPixmap_t::set_target (rxvt_term *new_target)
732{ 858{
733 if (new_target) 859 if (new_target)
734 if (target != new_target) 860 if (target != new_target)
735 { 861 {
736 target = new_target; 862 target = new_target;
737# ifdef ENABLE_TRANSPARENCY 863# ifdef ENABLE_TRANSPARENCY
738 root_depth = DefaultDepthOfScreen (ScreenOfDisplay (target->dpy, target->display->screen)); 864 root_depth = DefaultDepthOfScreen (ScreenOfDisplay (target->dpy, target->display->screen));
739 root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID);
740 if (root_pixmap == None)
741 root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID);
742# endif 865# endif
743 return true; 866 return true;
744 } 867 }
745 return false; 868 return false;
746} 869}
751 if (target) 874 if (target)
752 { 875 {
753 if (pixmap != None) 876 if (pixmap != None)
754 { /* set target's background to pixmap */ 877 { /* set target's background to pixmap */
755# ifdef ENABLE_TRANSPARENCY 878# ifdef ENABLE_TRANSPARENCY
756 if (flags & bgPmap_Transparent) 879 if (flags & isTransparent)
757 { 880 {
758 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap); 881 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap);
759 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative); 882 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative);
760 if (target->scrollBar.win) 883 if (target->scrollBar.win)
761 XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative); 884 XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative);
1169 1292
1170 bgPixmap.make_transparency_pixmap(); 1293 bgPixmap.make_transparency_pixmap();
1171 1294
1172 if (whole_tint && !no_tint) 1295 if (whole_tint && !no_tint)
1173 { 1296 {
1174 /* In this case we can tint image server-side getting significant
1175 * performance improvements, as we eliminate XImage transfer
1176 */
1177 gcvalue.foreground = Pixel (pix_colors_focused [Color_tint]);
1178 gcvalue.function = GXand;
1179 gcvalue.fill_style = FillSolid;
1180 if (gc)
1181 XChangeGC (dpy, gc, GCFillStyle | GCForeground | GCFunction, &gcvalue);
1182 else
1183 gc = XCreateGC (dpy, root, GCFillStyle | GCForeground | GCFunction, &gcvalue);
1184 XFillRectangle (dpy, bgPixmap.pixmap, gc, 0, 0, szHint.width, szHint.height);
1185 } 1297 }
1186 success = True; 1298 success = True;
1187#ifdef HAVE_AFTERIMAGE 1299#ifdef HAVE_AFTERIMAGE
1188 if (rs[Rs_blurradius] || bgPixmap.original_asim != NULL || (!whole_tint && (!no_tint || shade !=100))) 1300 if (rs[Rs_blurradius] || bgPixmap.original_asim != NULL || (!whole_tint && (!no_tint || shade !=100)))
1189 { 1301 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines