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.26 by root, Wed Jan 25 21:03:04 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{
181 197
182void 198void
183rxvt_screen::set (rxvt_display *disp) 199rxvt_screen::set (rxvt_display *disp)
184{ 200{
185 display = disp; 201 display = disp;
186
187 xdisp = disp->display; 202 xdisp = disp->display;
188 203
189 Screen *screen = ScreenOfDisplay (xdisp, disp->screen); 204 Screen *screen = ScreenOfDisplay (xdisp, disp->screen);
190 205
191 depth = DefaultDepthOfScreen (screen); 206 depth = DefaultDepthOfScreen (screen);
192 visual = DefaultVisualOfScreen (screen); 207 visual = DefaultVisualOfScreen (screen);
193 cmap = DefaultColormapOfScreen (screen); 208 cmap = DefaultColormapOfScreen (screen);
194} 209}
195 210
196void 211void
197rxvt_screen::set (rxvt_display *disp, int depth) 212rxvt_screen::set (rxvt_display *disp, int bitdepth)
198{ 213{
199 set (disp); 214 set (disp);
200 215
216#if XFT
201 XVisualInfo vinfo; 217 XVisualInfo vinfo;
202 218
203 if (XMatchVisualInfo (xdisp, display->screen, depth, TrueColor, &vinfo)) 219 if (XMatchVisualInfo (xdisp, display->screen, bitdepth, TrueColor, &vinfo))
204 { 220 {
205 this->depth = depth; 221 depth = bitdepth;
206 this->visual = vinfo.visual; 222 visual = vinfo.visual;
207 this->cmap = XCreateColormap (xdisp, disp->root, visual, AllocNone); 223 cmap = XCreateColormap (xdisp, disp->root, visual, AllocNone);
208 } 224 }
225#endif
209} 226}
210 227
211void 228void
212rxvt_screen::clear () 229rxvt_screen::clear ()
213{ 230{
535refcache<rxvt_display> displays; 552refcache<rxvt_display> displays;
536 553
537///////////////////////////////////////////////////////////////////////////// 554/////////////////////////////////////////////////////////////////////////////
538 555
539bool 556bool
540rxvt_color::set (rxvt_screen *screen, Pixel p) 557rxvt_color::set (rxvt_screen *screen, const char *name)
541{ 558{
542#if XFT 559#if XFT
543 XColor xc; 560 int l = strlen (name);
561 rxvt_rgba r;
562 char eos;
563 int mult;
544 564
545 xc.pixel = p; 565 // shortcutting this saves countless server RTTs for the built-in colours
546 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))
547 return false; 567 {
568 r.a = rxvt_rgba::MAX_CC;
569 mult = rxvt_rgba::MAX_CC / 0x00ff;
570 }
548 571
549 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;
550 581
551 d.red = xc.red; 582 // slow case: server round trip
552 d.green = xc.green; 583 else
553 d.blue = xc.blue;
554 d.alpha = 0xffff;
555
556 return
557 XftColorAllocValue (screen->xdisp,
558 screen->visual,
559 screen->cmap,
560 &d, &c);
561#else
562 this->p = p;
563#endif
564
565 return true;
566}
567
568bool
569rxvt_color::set (rxvt_screen *screen, const char *name)
570{
571#if XFT
572 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);
573#else 589#else
574 XColor xc; 590 XColor xc;
575 591
576 if (XParseColor (screen->xdisp, screen->cmap, name, &xc)) 592 if (XParseColor (screen->xdisp, screen->cmap, name, &xc))
577 return set (screen, xc.red, xc.green, xc.blue); 593 return set (screen, rxvt_rgba (xc.red, xc.green, xc.blue));
578 594
579 return false; 595 return false;
580#endif 596#endif
581} 597}
582 598
583bool 599bool
584rxvt_color::set (rxvt_screen *screen, unsigned short cr, unsigned short cg, unsigned short cb) 600rxvt_color::set (rxvt_screen *screen, rxvt_rgba rgba)
585{ 601{
586 XColor xc; 602#if XFT
603 XRenderPictFormat *format;
587 604
588 xc.red = cr; 605 // FUCKING Xft gets it wrong, of course, so work around it
589 xc.green = cg; 606 // transparency users should eat shit and die, and then
590 xc.blue = cb; 607 // XRenderQueryPictIndexValues themselves plenty.
591 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;
592 616
593 if (XAllocColor (screen->xdisp, screen->cmap, &xc)) 617 c.pixel = ((rgba.r * format->direct.redMask / rxvt_rgba::MAX_CC) << format->direct.red )
594 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 }
595 635
596 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
597} 667}
598 668
599void 669void
600rxvt_color::get (rxvt_screen *screen, unsigned short &cr, unsigned short &cg, unsigned short &cb) 670rxvt_color::get (rxvt_screen *screen, rxvt_rgba &rgba)
601{ 671{
602#if XFT 672#if XFT
603 cr = c.color.red; 673 rgba.r = c.color.red;
604 cg = c.color.green; 674 rgba.g = c.color.green;
605 cb = c.color.blue; 675 rgba.b = c.color.blue;
676 rgba.a = c.color.alpha;
606#else 677#else
607 XColor c; 678 XColor c;
608 679
609 c.pixel = p; 680 c.pixel = p;
610 XQueryColor (screen->xdisp, screen->cmap, &c); 681 XQueryColor (screen->xdisp, screen->cmap, &c);
611 682
612 cr = c.red; 683 rgba.r = c.red;
613 cg = c.green; 684 rgba.g = c.green;
614 cb = c.blue; 685 rgba.b = c.blue;
686 rgba.a = rxvt_rgba::MAX_CC;
615#endif 687#endif
616} 688}
617 689
618void 690void
619rxvt_color::free (rxvt_screen *screen) 691rxvt_color::free (rxvt_screen *screen)
626} 698}
627 699
628rxvt_color 700rxvt_color
629rxvt_color::fade (rxvt_screen *screen, int percent) 701rxvt_color::fade (rxvt_screen *screen, int percent)
630{ 702{
631 percent = 100 - percent;
632
633 unsigned short cr, cg, cb;
634 rxvt_color faded; 703 rxvt_color faded;
635 704
705 rxvt_rgba c;
636 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);
637 725
638 faded.set ( 726 faded.set (
639 screen, 727 screen,
640 cr * percent / 100, 728 rxvt_rgba (
641 cg * percent / 100, 729 lerp (fc.r, c.r, percent),
642 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 )
643 ); 734 );
644 735
645 return faded; 736 return faded;
646} 737}
647 738
648#define LERP(a,b,p) (a * p + b * (100 - p)) / 100
649
650rxvt_color
651rxvt_color::fade (rxvt_screen *screen, int percent, rxvt_color &fadeto)
652{
653 percent = 100 - percent;
654
655 unsigned short cr, cg, cb;
656 unsigned short fcr, fcg, fcb;
657 rxvt_color faded;
658
659 get (screen, cr, cg, cb);
660 fadeto.get (screen, fcr, fcg, fcb);
661
662 faded.set (
663 screen,
664 LERP (cr, fcr, percent),
665 LERP (cg, fcg, percent),
666 LERP (cb, fcb, percent)
667 );
668
669 return faded;
670}
671

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines