… | |
… | |
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 | |
37 | const char *const xa_names[] = |
41 | const char *const xa_names[] = |
38 | { |
42 | { |
39 | "TEXT", |
43 | "TEXT", |
40 | "COMPOUND_TEXT", |
44 | "COMPOUND_TEXT", |
41 | "UTF8_STRING", |
45 | "UTF8_STRING", |
… | |
… | |
191 | visual = DefaultVisualOfScreen (screen); |
195 | visual = DefaultVisualOfScreen (screen); |
192 | cmap = DefaultColormapOfScreen (screen); |
196 | cmap = DefaultColormapOfScreen (screen); |
193 | } |
197 | } |
194 | |
198 | |
195 | void |
199 | void |
196 | rxvt_screen::set (rxvt_display *disp, int depth) |
200 | rxvt_screen::set (rxvt_display *disp, int bitdepth) |
197 | { |
201 | { |
198 | set (disp); |
202 | set (disp); |
199 | |
203 | |
|
|
204 | #if XFT |
200 | XVisualInfo vinfo; |
205 | XVisualInfo vinfo; |
201 | |
206 | |
202 | if (XMatchVisualInfo (xdisp, display->screen, depth, TrueColor, &vinfo)) |
207 | if (XMatchVisualInfo (xdisp, display->screen, bitdepth, TrueColor, &vinfo)) |
203 | { |
208 | { |
204 | this->depth = depth; |
209 | depth = bitdepth; |
205 | this->visual = vinfo.visual; |
210 | visual = vinfo.visual; |
206 | this->cmap = XCreateColormap (xdisp, disp->root, visual, AllocNone); |
211 | cmap = XCreateColormap (xdisp, disp->root, visual, AllocNone); |
207 | } |
212 | } |
|
|
213 | #endif |
208 | } |
214 | } |
209 | |
215 | |
210 | void |
216 | void |
211 | rxvt_screen::clear () |
217 | rxvt_screen::clear () |
212 | { |
218 | { |
… | |
… | |
534 | refcache<rxvt_display> displays; |
540 | refcache<rxvt_display> displays; |
535 | |
541 | |
536 | ///////////////////////////////////////////////////////////////////////////// |
542 | ///////////////////////////////////////////////////////////////////////////// |
537 | |
543 | |
538 | bool |
544 | bool |
539 | rxvt_color::set (rxvt_screen *screen, Pixel p) |
545 | rxvt_color::set (rxvt_screen *screen, const char *name) |
540 | { |
546 | { |
541 | #if XFT |
547 | #if XFT |
542 | XColor xc; |
548 | int l = strlen (name); |
|
|
549 | rxvt_rgba r; |
|
|
550 | char eos; |
|
|
551 | int mult; |
543 | |
552 | |
544 | 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)) |
545 | if (!XQueryColor (screen->xdisp, screen->cmap, &xc)) |
554 | mult = rxvt_rgba::MAX_CC / 0x000f; |
546 | 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)) |
547 | |
556 | mult = rxvt_rgba::MAX_CC / 0x00ff; |
548 | 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)) |
549 | |
558 | mult = rxvt_rgba::MAX_CC / 0xffff; |
550 | 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)) |
551 | d.green = xc.green; |
560 | mult = rxvt_rgba::MAX_CC / 0xffff; |
552 | d.blue = xc.blue; |
561 | else |
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 | |
|
|
567 | bool |
|
|
568 | rxvt_color::set (rxvt_screen *screen, const char *name) |
|
|
569 | { |
|
|
570 | #if XFT |
|
|
571 | 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); |
572 | #else |
566 | #else |
573 | XColor xc; |
567 | XColor xc; |
574 | |
568 | |
575 | if (XParseColor (screen->xdisp, screen->cmap, name, &xc)) |
569 | if (XParseColor (screen->xdisp, screen->cmap, name, &xc)) |
576 | return set (screen, xc.red, xc.green, xc.blue); |
570 | return set (screen, rxvt_rgba (xc.red, xc.green, xc.blue)); |
577 | |
571 | |
578 | return false; |
572 | return false; |
579 | #endif |
573 | #endif |
580 | } |
574 | } |
581 | |
575 | |
582 | bool |
576 | bool |
583 | rxvt_color::set (rxvt_screen *screen, unsigned short cr, unsigned short cg, unsigned short cb) |
577 | rxvt_color::set (rxvt_screen *screen, rxvt_rgba rgba) |
584 | { |
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 |
585 | XColor xc; |
615 | XColor xc; |
586 | |
616 | |
587 | xc.red = cr; |
617 | xc.red = rgba.r; |
588 | xc.green = cg; |
618 | xc.green = rgba.g; |
589 | xc.blue = cb; |
619 | xc.blue = rgba.b; |
590 | xc.flags = DoRed | DoGreen | DoBlue; |
620 | xc.flags = DoRed | DoGreen | DoBlue; |
591 | |
621 | |
592 | if (XAllocColor (screen->xdisp, screen->cmap, &xc)) |
622 | if (XAllocColor (screen->xdisp, screen->cmap, &xc)) |
593 | return set (screen, xc.pixel); |
623 | { |
|
|
624 | p = xc.pixel; |
|
|
625 | return true; |
|
|
626 | } |
594 | |
627 | |
595 | return false; |
628 | return false; |
|
|
629 | #endif |
596 | } |
630 | } |
597 | |
631 | |
598 | void |
632 | void |
599 | rxvt_color::get (rxvt_screen *screen, unsigned short &cr, unsigned short &cg, unsigned short &cb) |
633 | rxvt_color::get (rxvt_screen *screen, rxvt_rgba &rgba) |
600 | { |
634 | { |
601 | #if XFT |
635 | #if XFT |
602 | cr = c.color.red; |
636 | rgba.r = c.color.red; |
603 | cg = c.color.green; |
637 | rgba.g = c.color.green; |
604 | cb = c.color.blue; |
638 | rgba.b = c.color.blue; |
|
|
639 | rgba.a = c.color.alpha; |
605 | #else |
640 | #else |
606 | XColor c; |
641 | XColor c; |
607 | |
642 | |
608 | c.pixel = p; |
643 | c.pixel = p; |
609 | XQueryColor (screen->xdisp, screen->cmap, &c); |
644 | XQueryColor (screen->xdisp, screen->cmap, &c); |
610 | |
645 | |
611 | cr = c.red; |
646 | rgba.r = c.red; |
612 | cg = c.green; |
647 | rgba.g = c.green; |
613 | cb = c.blue; |
648 | rgba.b = c.blue; |
|
|
649 | rgba.a = rxvt_rgba::MAX_CC; |
614 | #endif |
650 | #endif |
615 | } |
651 | } |
616 | |
652 | |
617 | void |
653 | void |
618 | rxvt_color::free (rxvt_screen *screen) |
654 | rxvt_color::free (rxvt_screen *screen) |
… | |
… | |
625 | } |
661 | } |
626 | |
662 | |
627 | rxvt_color |
663 | rxvt_color |
628 | rxvt_color::fade (rxvt_screen *screen, int percent) |
664 | rxvt_color::fade (rxvt_screen *screen, int percent) |
629 | { |
665 | { |
630 | percent = 100 - percent; |
|
|
631 | |
|
|
632 | unsigned short cr, cg, cb; |
|
|
633 | rxvt_color faded; |
666 | rxvt_color faded; |
634 | |
667 | |
|
|
668 | rxvt_rgba c; |
635 | 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 | |
|
|
680 | rxvt_color |
|
|
681 | rxvt_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); |
636 | |
688 | |
637 | faded.set ( |
689 | faded.set ( |
638 | screen, |
690 | screen, |
639 | cr * percent / 100, |
691 | rxvt_rgba ( |
640 | cg * percent / 100, |
692 | lerp (fc.r, c.r, percent), |
641 | 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 | ) |
642 | ); |
697 | ); |
643 | |
698 | |
644 | return faded; |
699 | return faded; |
645 | } |
700 | } |
646 | |
701 | |
647 | #define LERP(a,b,p) (a * p + b * (100 - p)) / 100 |
|
|
648 | |
|
|
649 | rxvt_color |
|
|
650 | rxvt_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 | |
|
|