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.31 by root, Sun Jan 29 22:27:04 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",
181 185
182void 186void
183rxvt_screen::set (rxvt_display *disp) 187rxvt_screen::set (rxvt_display *disp)
184{ 188{
185 display = disp; 189 display = disp;
186
187 xdisp = disp->display; 190 xdisp = disp->display;
188 191
189 Screen *screen = ScreenOfDisplay (xdisp, disp->screen); 192 Screen *screen = ScreenOfDisplay (xdisp, disp->screen);
190 193
191 depth = DefaultDepthOfScreen (screen); 194 depth = DefaultDepthOfScreen (screen);
192 visual = DefaultVisualOfScreen (screen); 195 visual = DefaultVisualOfScreen (screen);
193 cmap = DefaultColormapOfScreen (screen); 196 cmap = DefaultColormapOfScreen (screen);
194} 197}
195 198
196void 199void
197rxvt_screen::set (rxvt_display *disp, int depth) 200rxvt_screen::set (rxvt_display *disp, int bitdepth)
198{ 201{
199 set (disp); 202 set (disp);
200 203
204#if XFT
201 XVisualInfo vinfo; 205 XVisualInfo vinfo;
202 206
203 if (XMatchVisualInfo (xdisp, display->screen, depth, TrueColor, &vinfo)) 207 if (XMatchVisualInfo (xdisp, display->screen, bitdepth, TrueColor, &vinfo))
204 { 208 {
205 this->depth = depth; 209 depth = bitdepth;
206 this->visual = vinfo.visual; 210 visual = vinfo.visual;
207 this->cmap = XCreateColormap (xdisp, disp->root, visual, AllocNone); 211 cmap = XCreateColormap (xdisp, disp->root, visual, AllocNone);
208 } 212 }
213#endif
209} 214}
210 215
211void 216void
212rxvt_screen::clear () 217rxvt_screen::clear ()
213{ 218{
535refcache<rxvt_display> displays; 540refcache<rxvt_display> displays;
536 541
537///////////////////////////////////////////////////////////////////////////// 542/////////////////////////////////////////////////////////////////////////////
538 543
539bool 544bool
540rxvt_color::set (rxvt_screen *screen, Pixel p) 545rxvt_color::set (rxvt_screen *screen, const char *name)
541{ 546{
542#if XFT 547#if XFT
543 XColor xc; 548 int l = strlen (name);
549 rxvt_rgba r;
550 char eos;
551 int mult;
544 552
545 xc.pixel = p; 553 if ( l == 1+4*1 && 4 == sscanf (name, "#%1hx%1hx%1hx%1hx%c", &r.a, &r.r, &r.g, &r.b, &eos))
546 if (!XQueryColor (screen->xdisp, screen->cmap, &xc)) 554 mult = rxvt_rgba::MAX_CC / 0x000f;
547 return false; 555 else if (l == 1+4*2 && 4 == sscanf (name, "#%2hx%2hx%2hx%2hx%c", &r.a, &r.r, &r.g, &r.b, &eos))
548 556 mult = rxvt_rgba::MAX_CC / 0x00ff;
549 XRenderColor d; 557 else if (l == 1+4*4 && 4 == sscanf (name, "#%4hx%4hx%4hx%4hx%c", &r.a, &r.r, &r.g, &r.b, &eos))
550 558 mult = rxvt_rgba::MAX_CC / 0xffff;
551 d.red = xc.red; 559 else if (l == 4+5*4 && 4 == sscanf (name, "rgba:%hx/%hx/%hx/%hx%c", &r.r, &r.g, &r.b, &r.a, &eos))
552 d.green = xc.green; 560 mult = rxvt_rgba::MAX_CC / 0xffff;
553 d.blue = xc.blue; 561 else
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); 562 return XftColorAllocName (screen->xdisp, screen->visual, screen->cmap, name, &c);
563
564 r.r *= mult; r.g *= mult; r.b *= mult; r.a *= mult;
565 return set (screen, r);
573#else 566#else
574 XColor xc; 567 XColor xc;
575 568
576 if (XParseColor (screen->xdisp, screen->cmap, name, &xc)) 569 if (XParseColor (screen->xdisp, screen->cmap, name, &xc))
577 return set (screen, xc.red, xc.green, xc.blue); 570 return set (screen, rxvt_rgba (xc.red, xc.green, xc.blue));
578 571
579 return false; 572 return false;
580#endif 573#endif
581} 574}
582 575
583bool 576bool
584rxvt_color::set (rxvt_screen *screen, unsigned short cr, unsigned short cg, unsigned short cb) 577rxvt_color::set (rxvt_screen *screen, rxvt_rgba rgba)
585{ 578{
579#if XFT
580 XRenderPictFormat *format;
581
582 // FUCKING Xft gets it wrong, of course, so work around it
583 // transparency users should eat shit and die, and then
584 // XRenderQueryPictIndexValues themselves plenty.
585 if (screen->visual->c_class == TrueColor
586 && (format = XRenderFindVisualFormat (screen->xdisp, screen->visual)))
587 {
588 // the fun lies in doing everything manually...
589 c.color.red = rgba.r;
590 c.color.green = rgba.g;
591 c.color.blue = rgba.b;
592 c.color.alpha = rgba.a;
593
594 c.pixel = (rgba.r >> (16 - popcount (format->direct.redMask )) << format->direct.red)
595 | (rgba.g >> (16 - popcount (format->direct.greenMask)) << format->direct.green)
596 | (rgba.b >> (16 - popcount (format->direct.blueMask )) << format->direct.blue)
597 | (rgba.a >> (16 - popcount (format->direct.alphaMask)) << format->direct.alpha);
598
599 return true;
600 }
601 else
602 {
603 XRenderColor d;
604
605 d.red = rgba.r;
606 d.green = rgba.g;
607 d.blue = rgba.b;
608 d.alpha = rgba.a;
609
610 return XftColorAllocValue (screen->xdisp, screen->visual, screen->cmap, &d, &c);
611 }
612
613 return false;
614#else
586 XColor xc; 615 XColor xc;
587 616
588 xc.red = cr; 617 xc.red = rgba.r;
589 xc.green = cg; 618 xc.green = rgba.g;
590 xc.blue = cb; 619 xc.blue = rgba.b;
591 xc.flags = DoRed | DoGreen | DoBlue; 620 xc.flags = DoRed | DoGreen | DoBlue;
592 621
593 if (XAllocColor (screen->xdisp, screen->cmap, &xc)) 622 if (XAllocColor (screen->xdisp, screen->cmap, &xc))
594 return set (screen, xc.pixel); 623 {
624 p = xc.pixel;
625 return true;
626 }
595 627
596 return false; 628 return false;
629#endif
597} 630}
598 631
599void 632void
600rxvt_color::get (rxvt_screen *screen, unsigned short &cr, unsigned short &cg, unsigned short &cb) 633rxvt_color::get (rxvt_screen *screen, rxvt_rgba &rgba)
601{ 634{
602#if XFT 635#if XFT
603 cr = c.color.red; 636 rgba.r = c.color.red;
604 cg = c.color.green; 637 rgba.g = c.color.green;
605 cb = c.color.blue; 638 rgba.b = c.color.blue;
639 rgba.a = c.color.alpha;
606#else 640#else
607 XColor c; 641 XColor c;
608 642
609 c.pixel = p; 643 c.pixel = p;
610 XQueryColor (screen->xdisp, screen->cmap, &c); 644 XQueryColor (screen->xdisp, screen->cmap, &c);
611 645
612 cr = c.red; 646 rgba.r = c.red;
613 cg = c.green; 647 rgba.g = c.green;
614 cb = c.blue; 648 rgba.b = c.blue;
649 rgba.a = rxvt_rgba::MAX_CC;
615#endif 650#endif
616} 651}
617 652
618void 653void
619rxvt_color::free (rxvt_screen *screen) 654rxvt_color::free (rxvt_screen *screen)
626} 661}
627 662
628rxvt_color 663rxvt_color
629rxvt_color::fade (rxvt_screen *screen, int percent) 664rxvt_color::fade (rxvt_screen *screen, int percent)
630{ 665{
631 percent = 100 - percent;
632
633 unsigned short cr, cg, cb;
634 rxvt_color faded; 666 rxvt_color faded;
635 667
668 rxvt_rgba c;
636 get (screen, cr, cg, cb); 669 get (screen, c);
670
671 c.r = lerp (0, c.r, percent);
672 c.g = lerp (0, c.g, percent);
673 c.b = lerp (0, c.b, percent);
674
675 faded.set (screen, c);
676
677 return faded;
678}
679
680rxvt_color
681rxvt_color::fade (rxvt_screen *screen, int percent, rxvt_color &fadeto)
682{
683 rxvt_rgba c, fc;
684 rxvt_color faded;
685
686 get (screen, c);
687 fadeto.get (screen, fc);
637 688
638 faded.set ( 689 faded.set (
639 screen, 690 screen,
640 cr * percent / 100, 691 rxvt_rgba (
641 cg * percent / 100, 692 lerp (fc.r, c.r, percent),
642 cb * percent / 100 693 lerp (fc.g, c.g, percent),
694 lerp (fc.b, c.b, percent),
695 lerp (fc.a, c.a, percent)
696 )
643 ); 697 );
644 698
645 return faded; 699 return faded;
646} 700}
647 701
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