… | |
… | |
37 | #if XFT |
37 | #if XFT |
38 | # include <X11/extensions/Xrender.h> |
38 | # include <X11/extensions/Xrender.h> |
39 | #endif |
39 | #endif |
40 | |
40 | |
41 | const char *const xa_names[] = |
41 | const char *const xa_names[] = |
42 | { |
42 | { |
43 | "TEXT", |
43 | "TEXT", |
44 | "COMPOUND_TEXT", |
44 | "COMPOUND_TEXT", |
45 | "UTF8_STRING", |
45 | "UTF8_STRING", |
46 | "MULTIPLE", |
46 | "MULTIPLE", |
47 | "TARGETS", |
47 | "TARGETS", |
48 | "TIMESTAMP", |
48 | "TIMESTAMP", |
49 | "VT_SELECTION", |
49 | "VT_SELECTION", |
50 | "INCR", |
50 | "INCR", |
51 | "WM_PROTOCOLS", |
51 | "WM_PROTOCOLS", |
52 | "WM_DELETE_WINDOW", |
52 | "WM_DELETE_WINDOW", |
53 | "CLIPBOARD", |
53 | "CLIPBOARD", |
|
|
54 | "AVERAGE_WIDTH", |
|
|
55 | "WEIGHT_NAME", |
|
|
56 | "SLANT", |
|
|
57 | "CHARSET_REGISTRY", |
|
|
58 | "CHARSET_ENCODING", |
54 | #if ENABLE_FRILLS |
59 | #if ENABLE_FRILLS |
55 | "_MOTIF_WM_HINTS", |
60 | "_MOTIF_WM_HINTS", |
56 | #endif |
61 | #endif |
57 | #if ENABLE_EWMH |
62 | #if ENABLE_EWMH |
58 | "_NET_WM_PID", |
63 | "_NET_WM_PID", |
59 | "_NET_WM_NAME", |
64 | "_NET_WM_NAME", |
60 | "_NET_WM_ICON_NAME", |
65 | "_NET_WM_ICON_NAME", |
61 | "_NET_WM_PING", |
66 | "_NET_WM_PING", |
62 | #endif |
67 | #endif |
63 | #if USE_XIM |
68 | #if USE_XIM |
64 | "WM_LOCALE_NAME", |
69 | "WM_LOCALE_NAME", |
65 | "XIM_SERVERS", |
70 | "XIM_SERVERS", |
66 | #endif |
71 | #endif |
67 | #ifdef TRANSPARENT |
72 | #ifdef TRANSPARENT |
68 | "_XROOTPMAP_ID", |
73 | "_XROOTPMAP_ID", |
69 | "ESETROOT_PMAP_ID", |
74 | "ESETROOT_PMAP_ID", |
70 | #endif |
75 | #endif |
71 | #if ENABLE_XEMBED |
76 | #if ENABLE_XEMBED |
72 | "_XEMBED", |
77 | "_XEMBED", |
73 | "_XEMBED_INFO", |
78 | "_XEMBED_INFO", |
74 | #endif |
79 | #endif |
75 | }; |
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 | }; |
76 | |
88 | |
77 | ///////////////////////////////////////////////////////////////////////////// |
89 | ///////////////////////////////////////////////////////////////////////////// |
78 | |
90 | |
79 | refcounted::refcounted (const char *id) |
91 | refcounted::refcounted (const char *id) |
80 | { |
92 | { |
… | |
… | |
548 | int l = strlen (name); |
560 | int l = strlen (name); |
549 | rxvt_rgba r; |
561 | rxvt_rgba r; |
550 | char eos; |
562 | char eos; |
551 | int mult; |
563 | int mult; |
552 | |
564 | |
|
|
565 | // shortcutting this saves countless server RTTs for the built-in colours |
|
|
566 | if (l == 3+3*3 && 3 == sscanf (name, "rgb:%hx/%hx/%hx/%hx%c", &r.r, &r.g, &r.b, &r.a, &eos)) |
|
|
567 | { |
|
|
568 | r.a = rxvt_rgba::MAX_CC; |
|
|
569 | mult = rxvt_rgba::MAX_CC / 0x00ff; |
|
|
570 | } |
|
|
571 | |
|
|
572 | // parse a number of non-standard ARGB colour specifications |
553 | if ( l == 1+4*1 && 4 == sscanf (name, "#%1hx%1hx%1hx%1hx%c", &r.a, &r.r, &r.g, &r.b, &eos)) |
573 | else if ( l == 1+4*1 && 4 == sscanf (name, "#%1hx%1hx%1hx%1hx%c", &r.a, &r.r, &r.g, &r.b, &eos)) |
554 | mult = rxvt_rgba::MAX_CC / 0x000f; |
574 | mult = rxvt_rgba::MAX_CC / 0x000f; |
555 | else if (l == 1+4*2 && 4 == sscanf (name, "#%2hx%2hx%2hx%2hx%c", &r.a, &r.r, &r.g, &r.b, &eos)) |
575 | else if (l == 1+4*2 && 4 == sscanf (name, "#%2hx%2hx%2hx%2hx%c", &r.a, &r.r, &r.g, &r.b, &eos)) |
556 | mult = rxvt_rgba::MAX_CC / 0x00ff; |
576 | mult = rxvt_rgba::MAX_CC / 0x00ff; |
557 | else if (l == 1+4*4 && 4 == sscanf (name, "#%4hx%4hx%4hx%4hx%c", &r.a, &r.r, &r.g, &r.b, &eos)) |
577 | else if (l == 1+4*4 && 4 == sscanf (name, "#%4hx%4hx%4hx%4hx%c", &r.a, &r.r, &r.g, &r.b, &eos)) |
558 | mult = rxvt_rgba::MAX_CC / 0xffff; |
578 | mult = rxvt_rgba::MAX_CC / 0xffff; |
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)) |
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)) |
560 | mult = rxvt_rgba::MAX_CC / 0xffff; |
580 | mult = rxvt_rgba::MAX_CC / 0xffff; |
|
|
581 | |
|
|
582 | // slow case: server round trip |
561 | else |
583 | else |
562 | return XftColorAllocName (screen->xdisp, screen->visual, screen->cmap, name, &c); |
584 | return XftColorAllocName (screen->xdisp, screen->visual, screen->cmap, name, &c); |
563 | |
585 | |
564 | r.r *= mult; r.g *= mult; r.b *= mult; r.a *= mult; |
586 | r.r *= mult; r.g *= mult; r.b *= mult; r.a *= mult; |
|
|
587 | |
565 | return set (screen, r); |
588 | return set (screen, r); |
566 | #else |
589 | #else |
567 | XColor xc; |
590 | XColor xc; |
568 | |
591 | |
569 | if (XParseColor (screen->xdisp, screen->cmap, name, &xc)) |
592 | if (XParseColor (screen->xdisp, screen->cmap, name, &xc)) |
… | |
… | |
589 | c.color.red = rgba.r; |
612 | c.color.red = rgba.r; |
590 | c.color.green = rgba.g; |
613 | c.color.green = rgba.g; |
591 | c.color.blue = rgba.b; |
614 | c.color.blue = rgba.b; |
592 | c.color.alpha = rgba.a; |
615 | c.color.alpha = rgba.a; |
593 | |
616 | |
594 | c.pixel = ((rgba.r * format->direct.redMask / rxvt_rgba::MAX_CC) << format->direct.red) |
617 | c.pixel = ((rgba.r * format->direct.redMask / rxvt_rgba::MAX_CC) << format->direct.red ) |
595 | | ((rgba.g * format->direct.greenMask / rxvt_rgba::MAX_CC) << format->direct.green) |
618 | | ((rgba.g * format->direct.greenMask / rxvt_rgba::MAX_CC) << format->direct.green) |
596 | | ((rgba.b * format->direct.blueMask / rxvt_rgba::MAX_CC) << format->direct.blue) |
619 | | ((rgba.b * format->direct.blueMask / rxvt_rgba::MAX_CC) << format->direct.blue ) |
597 | | ((rgba.a * format->direct.alphaMask / rxvt_rgba::MAX_CC) << format->direct.alpha); |
620 | | ((rgba.a * format->direct.alphaMask / rxvt_rgba::MAX_CC) << format->direct.alpha); |
598 | |
621 | |
599 | return true; |
622 | return true; |
600 | } |
623 | } |
601 | else |
624 | else |
… | |
… | |
610 | return XftColorAllocValue (screen->xdisp, screen->visual, screen->cmap, &d, &c); |
633 | return XftColorAllocValue (screen->xdisp, screen->visual, screen->cmap, &d, &c); |
611 | } |
634 | } |
612 | |
635 | |
613 | return false; |
636 | return false; |
614 | #else |
637 | #else |
615 | XColor xc; |
638 | if (screen->visual->c_class == TrueColor) |
616 | |
|
|
617 | xc.red = rgba.r; |
|
|
618 | xc.green = rgba.g; |
|
|
619 | xc.blue = rgba.b; |
|
|
620 | xc.flags = DoRed | DoGreen | DoBlue; |
|
|
621 | |
|
|
622 | if (XAllocColor (screen->xdisp, screen->cmap, &xc)) |
|
|
623 | { |
639 | { |
624 | p = xc.pixel; |
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 | |
625 | return true; |
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 | } |
626 | } |
663 | } |
627 | |
664 | |
628 | return false; |
665 | return false; |
629 | #endif |
666 | #endif |
630 | } |
667 | } |