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

Comparing rxvt-unicode/src/rxvttoolkit.C (file contents):
Revision 1.27 by root, Wed Jan 25 21:09:21 2006 UTC vs.
Revision 1.37 by root, Mon Jan 30 17:49:48 2006 UTC

32#ifndef NO_SLOW_LINK_SUPPORT 32#ifndef NO_SLOW_LINK_SUPPORT
33# include <sys/socket.h> 33# include <sys/socket.h>
34# include <sys/un.h> 34# include <sys/un.h>
35#endif 35#endif
36 36
37#if XFT
38# include <X11/extensions/Xrender.h>
39#endif
40
37const char *const xa_names[] = 41const char *const xa_names[] =
38 { 42{
39 "TEXT", 43 "TEXT",
40 "COMPOUND_TEXT", 44 "COMPOUND_TEXT",
41 "UTF8_STRING", 45 "UTF8_STRING",
42 "MULTIPLE", 46 "MULTIPLE",
43 "TARGETS", 47 "TARGETS",
44 "TIMESTAMP", 48 "TIMESTAMP",
45 "VT_SELECTION", 49 "VT_SELECTION",
46 "INCR", 50 "INCR",
47 "WM_PROTOCOLS", 51 "WM_PROTOCOLS",
48 "WM_DELETE_WINDOW", 52 "WM_DELETE_WINDOW",
49 "CLIPBOARD", 53 "CLIPBOARD",
54 "AVERAGE_WIDTH",
55 "WEIGHT_NAME",
56 "SLANT",
57 "CHARSET_REGISTRY",
58 "CHARSET_ENCODING",
50#if ENABLE_FRILLS 59#if ENABLE_FRILLS
51 "_MOTIF_WM_HINTS", 60 "_MOTIF_WM_HINTS",
52#endif 61#endif
53#if ENABLE_EWMH 62#if ENABLE_EWMH
54 "_NET_WM_PID", 63 "_NET_WM_PID",
55 "_NET_WM_NAME", 64 "_NET_WM_NAME",
56 "_NET_WM_ICON_NAME", 65 "_NET_WM_ICON_NAME",
57 "_NET_WM_PING", 66 "_NET_WM_PING",
58#endif 67#endif
59#if USE_XIM 68#if USE_XIM
60 "WM_LOCALE_NAME", 69 "WM_LOCALE_NAME",
61 "XIM_SERVERS", 70 "XIM_SERVERS",
62#endif 71#endif
63#ifdef TRANSPARENT 72#ifdef TRANSPARENT
64 "_XROOTPMAP_ID", 73 "_XROOTPMAP_ID",
65 "ESETROOT_PMAP_ID", 74 "ESETROOT_PMAP_ID",
66#endif 75#endif
67#if ENABLE_XEMBED 76#if ENABLE_XEMBED
68 "_XEMBED", 77 "_XEMBED",
69 "_XEMBED_INFO", 78 "_XEMBED_INFO",
70#endif 79#endif
71 }; 80#if !ENABLE_MINIMAL
81 "SCREEN_RESOURCES",
82 "XDCCC_LINEAR_RGB_CORRECTION",
83 "XDCCC_LINEAR_RGB_MATRICES",
84 "WM_COLORMAP_WINDOWS",
85 "WM_STATE",
86#endif
87};
72 88
73///////////////////////////////////////////////////////////////////////////// 89/////////////////////////////////////////////////////////////////////////////
74 90
75refcounted::refcounted (const char *id) 91refcounted::refcounted (const char *id)
76{ 92{
191 visual = DefaultVisualOfScreen (screen); 207 visual = DefaultVisualOfScreen (screen);
192 cmap = DefaultColormapOfScreen (screen); 208 cmap = DefaultColormapOfScreen (screen);
193} 209}
194 210
195void 211void
196rxvt_screen::set (rxvt_display *disp, int depth) 212rxvt_screen::set (rxvt_display *disp, int bitdepth)
197{ 213{
198 set (disp); 214 set (disp);
199 215
216#if XFT
200 XVisualInfo vinfo; 217 XVisualInfo vinfo;
201 218
202 if (XMatchVisualInfo (xdisp, display->screen, depth, TrueColor, &vinfo)) 219 if (XMatchVisualInfo (xdisp, display->screen, bitdepth, TrueColor, &vinfo))
203 { 220 {
204 this->depth = depth; 221 depth = bitdepth;
205 this->visual = vinfo.visual; 222 visual = vinfo.visual;
206 this->cmap = XCreateColormap (xdisp, disp->root, visual, AllocNone); 223 cmap = XCreateColormap (xdisp, disp->root, visual, AllocNone);
207 } 224 }
225#endif
208} 226}
209 227
210void 228void
211rxvt_screen::clear () 229rxvt_screen::clear ()
212{ 230{
534refcache<rxvt_display> displays; 552refcache<rxvt_display> displays;
535 553
536///////////////////////////////////////////////////////////////////////////// 554/////////////////////////////////////////////////////////////////////////////
537 555
538bool 556bool
539rxvt_color::set (rxvt_screen *screen, Pixel p) 557rxvt_color::set (rxvt_screen *screen, const char *name)
540{ 558{
541#if XFT 559#if XFT
542 XColor xc; 560 int l = strlen (name);
561 rxvt_rgba r;
562 char eos;
563 int mult;
543 564
544 xc.pixel = p; 565 // shortcutting this saves countless server RTTs for the built-in colours
545 if (!XQueryColor (screen->xdisp, screen->cmap, &xc)) 566 if (l == 3+3*3 && 3 == sscanf (name, "rgb:%hx/%hx/%hx/%hx%c", &r.r, &r.g, &r.b, &r.a, &eos))
546 return false; 567 {
568 r.a = rxvt_rgba::MAX_CC;
569 mult = rxvt_rgba::MAX_CC / 0x00ff;
570 }
547 571
548 XRenderColor d; 572 // parse a number of non-standard ARGB colour specifications
573 else if ( l == 1+4*1 && 4 == sscanf (name, "#%1hx%1hx%1hx%1hx%c", &r.a, &r.r, &r.g, &r.b, &eos))
574 mult = rxvt_rgba::MAX_CC / 0x000f;
575 else if (l == 1+4*2 && 4 == sscanf (name, "#%2hx%2hx%2hx%2hx%c", &r.a, &r.r, &r.g, &r.b, &eos))
576 mult = rxvt_rgba::MAX_CC / 0x00ff;
577 else if (l == 1+4*4 && 4 == sscanf (name, "#%4hx%4hx%4hx%4hx%c", &r.a, &r.r, &r.g, &r.b, &eos))
578 mult = rxvt_rgba::MAX_CC / 0xffff;
579 else if (l == 4+5*4 && 4 == sscanf (name, "rgba:%hx/%hx/%hx/%hx%c", &r.r, &r.g, &r.b, &r.a, &eos))
580 mult = rxvt_rgba::MAX_CC / 0xffff;
549 581
550 d.red = xc.red; 582 // slow case: server round trip
551 d.green = xc.green; 583 else
552 d.blue = xc.blue;
553 d.alpha = 0xffff;
554
555 return
556 XftColorAllocValue (screen->xdisp,
557 screen->visual,
558 screen->cmap,
559 &d, &c);
560#else
561 this->p = p;
562#endif
563
564 return true;
565}
566
567bool
568rxvt_color::set (rxvt_screen *screen, const char *name)
569{
570#if XFT
571 return XftColorAllocName (screen->xdisp, screen->visual, screen->cmap, name, &c); 584 return XftColorAllocName (screen->xdisp, screen->visual, screen->cmap, name, &c);
585
586 r.r *= mult; r.g *= mult; r.b *= mult; r.a *= mult;
587
588 return set (screen, r);
572#else 589#else
573 XColor xc; 590 XColor xc;
574 591
575 if (XParseColor (screen->xdisp, screen->cmap, name, &xc)) 592 if (XParseColor (screen->xdisp, screen->cmap, name, &xc))
576 return set (screen, xc.red, xc.green, xc.blue); 593 return set (screen, rxvt_rgba (xc.red, xc.green, xc.blue));
577 594
578 return false; 595 return false;
579#endif 596#endif
580} 597}
581 598
582bool 599bool
583rxvt_color::set (rxvt_screen *screen, unsigned short cr, unsigned short cg, unsigned short cb) 600rxvt_color::set (rxvt_screen *screen, rxvt_rgba rgba)
584{ 601{
585 XColor xc; 602#if XFT
603 XRenderPictFormat *format;
586 604
587 xc.red = cr; 605 // FUCKING Xft gets it wrong, of course, so work around it
588 xc.green = cg; 606 // transparency users should eat shit and die, and then
589 xc.blue = cb; 607 // XRenderQueryPictIndexValues themselves plenty.
590 xc.flags = DoRed | DoGreen | DoBlue; 608 if ((screen->visual->c_class == TrueColor || screen->visual->c_class == DirectColor)
609 && (format = XRenderFindVisualFormat (screen->xdisp, screen->visual)))
610 {
611 // the fun lies in doing everything manually...
612 c.color.red = rgba.r;
613 c.color.green = rgba.g;
614 c.color.blue = rgba.b;
615 c.color.alpha = rgba.a;
591 616
592 if (XAllocColor (screen->xdisp, screen->cmap, &xc)) 617 c.pixel = ((rgba.r * format->direct.redMask / rxvt_rgba::MAX_CC) << format->direct.red )
593 return set (screen, xc.pixel); 618 | ((rgba.g * format->direct.greenMask / rxvt_rgba::MAX_CC) << format->direct.green)
619 | ((rgba.b * format->direct.blueMask / rxvt_rgba::MAX_CC) << format->direct.blue )
620 | ((rgba.a * format->direct.alphaMask / rxvt_rgba::MAX_CC) << format->direct.alpha);
621
622 return true;
623 }
624 else
625 {
626 XRenderColor d;
627
628 d.red = rgba.r;
629 d.green = rgba.g;
630 d.blue = rgba.b;
631 d.alpha = rgba.a;
632
633 return XftColorAllocValue (screen->xdisp, screen->visual, screen->cmap, &d, &c);
634 }
594 635
595 return false; 636 return false;
637#else
638 if (screen->visual->c_class == TrueColor || screen->visual->c_class == DirectColor)
639 {
640 p = (rgba.r * (screen->visual->red_mask >> ctz (screen->visual->red_mask ))
641 / rxvt_rgba::MAX_CC) << ctz (screen->visual->red_mask )
642 | (rgba.g * (screen->visual->green_mask >> ctz (screen->visual->green_mask))
643 / rxvt_rgba::MAX_CC) << ctz (screen->visual->green_mask)
644 | (rgba.b * (screen->visual->blue_mask >> ctz (screen->visual->blue_mask ))
645 / rxvt_rgba::MAX_CC) << ctz (screen->visual->blue_mask );
646
647 return true;
648 }
649 else
650 {
651 XColor xc;
652
653 xc.red = rgba.r;
654 xc.green = rgba.g;
655 xc.blue = rgba.b;
656 xc.flags = DoRed | DoGreen | DoBlue;
657
658 if (XAllocColor (screen->xdisp, screen->cmap, &xc))
659 {
660 p = xc.pixel;
661 return true;
662 }
663 }
664
665 return false;
666#endif
596} 667}
597 668
598void 669void
599rxvt_color::get (rxvt_screen *screen, unsigned short &cr, unsigned short &cg, unsigned short &cb) 670rxvt_color::get (rxvt_screen *screen, rxvt_rgba &rgba)
600{ 671{
601#if XFT 672#if XFT
602 cr = c.color.red; 673 rgba.r = c.color.red;
603 cg = c.color.green; 674 rgba.g = c.color.green;
604 cb = c.color.blue; 675 rgba.b = c.color.blue;
676 rgba.a = c.color.alpha;
605#else 677#else
606 XColor c; 678 XColor c;
607 679
608 c.pixel = p; 680 c.pixel = p;
609 XQueryColor (screen->xdisp, screen->cmap, &c); 681 XQueryColor (screen->xdisp, screen->cmap, &c);
610 682
611 cr = c.red; 683 rgba.r = c.red;
612 cg = c.green; 684 rgba.g = c.green;
613 cb = c.blue; 685 rgba.b = c.blue;
686 rgba.a = rxvt_rgba::MAX_CC;
614#endif 687#endif
615} 688}
616 689
617void 690void
618rxvt_color::free (rxvt_screen *screen) 691rxvt_color::free (rxvt_screen *screen)
625} 698}
626 699
627rxvt_color 700rxvt_color
628rxvt_color::fade (rxvt_screen *screen, int percent) 701rxvt_color::fade (rxvt_screen *screen, int percent)
629{ 702{
630 percent = 100 - percent;
631
632 unsigned short cr, cg, cb;
633 rxvt_color faded; 703 rxvt_color faded;
634 704
705 rxvt_rgba c;
635 get (screen, cr, cg, cb); 706 get (screen, c);
707
708 c.r = lerp (0, c.r, percent);
709 c.g = lerp (0, c.g, percent);
710 c.b = lerp (0, c.b, percent);
711
712 faded.set (screen, c);
713
714 return faded;
715}
716
717rxvt_color
718rxvt_color::fade (rxvt_screen *screen, int percent, rxvt_color &fadeto)
719{
720 rxvt_rgba c, fc;
721 rxvt_color faded;
722
723 get (screen, c);
724 fadeto.get (screen, fc);
636 725
637 faded.set ( 726 faded.set (
638 screen, 727 screen,
639 cr * percent / 100, 728 rxvt_rgba (
640 cg * percent / 100, 729 lerp (fc.r, c.r, percent),
641 cb * percent / 100 730 lerp (fc.g, c.g, percent),
731 lerp (fc.b, c.b, percent),
732 lerp (fc.a, c.a, percent)
733 )
642 ); 734 );
643 735
644 return faded; 736 return faded;
645} 737}
646 738
647#define LERP(a,b,p) (a * p + b * (100 - p)) / 100
648
649rxvt_color
650rxvt_color::fade (rxvt_screen *screen, int percent, rxvt_color &fadeto)
651{
652 percent = 100 - percent;
653
654 unsigned short cr, cg, cb;
655 unsigned short fcr, fcg, fcb;
656 rxvt_color faded;
657
658 get (screen, cr, cg, cb);
659 fadeto.get (screen, fcr, fcg, fcb);
660
661 faded.set (
662 screen,
663 LERP (cr, fcr, percent),
664 LERP (cg, fcg, percent),
665 LERP (cb, fcb, percent)
666 );
667
668 return faded;
669}
670

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines