… | |
… | |
673 | } |
673 | } |
674 | |
674 | |
675 | bool |
675 | bool |
676 | rxvt_color::alloc (rxvt_screen *screen, const rgba &color) |
676 | rxvt_color::alloc (rxvt_screen *screen, const rgba &color) |
677 | { |
677 | { |
|
|
678 | //TODO: only supports 24 bit truecolour |
|
|
679 | int alpha = color.a >= 0xff00 ? 0xffff : color.a; |
|
|
680 | |
678 | #if XFT |
681 | #if XFT |
679 | XRenderPictFormat *format; |
682 | XRenderPictFormat *format; |
680 | |
683 | |
681 | // FUCKING Xft gets it wrong, of course, so work around it. |
684 | // FUCKING Xft gets it wrong, of course, so work around it. |
682 | // Transparency users should eat shit and die, and then |
685 | // Transparency users should eat shit and die, and then |
… | |
… | |
686 | { |
689 | { |
687 | // the fun lies in doing everything manually... |
690 | // the fun lies in doing everything manually... |
688 | c.color.red = color.r; |
691 | c.color.red = color.r; |
689 | c.color.green = color.g; |
692 | c.color.green = color.g; |
690 | c.color.blue = color.b; |
693 | c.color.blue = color.b; |
691 | c.color.alpha = color.a; |
694 | c.color.alpha = alpha; |
692 | |
695 | |
693 | c.pixel = insert_component (color.r, format->direct.redMask , format->direct.red ) |
696 | c.pixel = insert_component (color.r, format->direct.redMask , format->direct.red ) |
694 | | insert_component (color.g, format->direct.greenMask, format->direct.green) |
697 | | insert_component (color.g, format->direct.greenMask, format->direct.green) |
695 | | insert_component (color.b, format->direct.blueMask , format->direct.blue ) |
698 | | insert_component (color.b, format->direct.blueMask , format->direct.blue ) |
696 | | insert_component (color.a, format->direct.alphaMask, format->direct.alpha); |
699 | | insert_component (alpha , format->direct.alphaMask, format->direct.alpha); |
697 | |
700 | |
698 | return true; |
701 | return true; |
699 | } |
702 | } |
700 | else |
703 | else |
701 | { |
704 | { |
702 | XRenderColor d; |
705 | XRenderColor d; |
703 | |
706 | |
704 | d.red = color.r; |
707 | d.red = color.r; |
705 | d.green = color.g; |
708 | d.green = color.g; |
706 | d.blue = color.b; |
709 | d.blue = color.b; |
707 | d.alpha = color.a; |
710 | d.alpha = alpha; |
708 | |
711 | |
709 | return XftColorAllocValue (screen->dpy, screen->visual, screen->cmap, &d, &c); |
712 | return XftColorAllocValue (screen->dpy, screen->visual, screen->cmap, &d, &c); |
710 | } |
713 | } |
711 | #else |
714 | #else |
712 | c.red = color.r; |
715 | c.red = color.r; |
… | |
… | |
749 | c.a = rgba::MAX_CC; |
752 | c.a = rgba::MAX_CC; |
750 | |
753 | |
751 | // parse the non-standard "#aarrggbb" format |
754 | // parse the non-standard "#aarrggbb" format |
752 | if (name[0] == '#' && strlen (name) == 1+2+2+2+2 && 4 == sscanf (name+1, "%2hx%2hx%2hx%2hx%c", &c.a, &c.r, &c.g, &c.b, &eos)) |
755 | if (name[0] == '#' && strlen (name) == 1+2+2+2+2 && 4 == sscanf (name+1, "%2hx%2hx%2hx%2hx%c", &c.a, &c.r, &c.g, &c.b, &eos)) |
753 | { |
756 | { |
754 | if (c.r) |
757 | c.r <<= 8; |
755 | c.r = (c.r << 8) | 0x0ff; |
758 | c.g <<= 8; |
756 | if (c.g) |
759 | c.b <<= 8; |
757 | c.g = (c.g << 8) | 0x0ff; |
760 | c.a <<= 8; |
758 | if (c.b) |
|
|
759 | c.b = (c.b << 8) | 0x0ff; |
|
|
760 | if (c.a) |
|
|
761 | c.a = (c.a << 8) | 0x0ff; |
|
|
762 | } |
761 | } |
763 | // parse the non-standard "rgba:rrrr/gggg/bbbb/aaaa" format |
762 | // parse the non-standard "rgba:rrrr/gggg/bbbb/aaaa" format |
764 | else if (strlen (name) != 4+5*4 || 4 != sscanf (name, "rgba:%4hx/%4hx/%4hx/%4hx%c", &c.r, &c.g, &c.b, &c.a, &eos)) |
763 | else if (strlen (name) != 4+5*4 || 4 != sscanf (name, "rgba:%4hx/%4hx/%4hx/%4hx%c", &c.r, &c.g, &c.b, &c.a, &eos)) |
765 | { |
764 | { |
766 | XColor xc; |
765 | XColor xc; |