… | |
… | |
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", |
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 | |
75 | refcounted::refcounted (const char *id) |
91 | refcounted::refcounted (const char *id) |
76 | { |
92 | { |
… | |
… | |
195 | void |
211 | void |
196 | rxvt_screen::set (rxvt_display *disp, int bitdepth) |
212 | rxvt_screen::set (rxvt_display *disp, int bitdepth) |
197 | { |
213 | { |
198 | set (disp); |
214 | set (disp); |
199 | |
215 | |
|
|
216 | #if XFT |
200 | XVisualInfo vinfo; |
217 | XVisualInfo vinfo; |
201 | |
218 | |
202 | if (XMatchVisualInfo (xdisp, display->screen, bitdepth, TrueColor, &vinfo)) |
219 | if (XMatchVisualInfo (xdisp, display->screen, bitdepth, TrueColor, &vinfo)) |
203 | { |
220 | { |
204 | depth = bitdepth; |
221 | depth = bitdepth; |
205 | visual = vinfo.visual; |
222 | visual = vinfo.visual; |
206 | cmap = XCreateColormap (xdisp, disp->root, visual, AllocNone); |
223 | cmap = XCreateColormap (xdisp, disp->root, visual, AllocNone); |
207 | } |
224 | } |
|
|
225 | #endif |
208 | } |
226 | } |
209 | |
227 | |
210 | void |
228 | void |
211 | rxvt_screen::clear () |
229 | rxvt_screen::clear () |
212 | { |
230 | { |
… | |
… | |
542 | int l = strlen (name); |
560 | int l = strlen (name); |
543 | rxvt_rgba r; |
561 | rxvt_rgba r; |
544 | char eos; |
562 | char eos; |
545 | int mult; |
563 | int mult; |
546 | |
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 |
547 | 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)) |
548 | mult = rxvt_rgba::MAX_CC / 0x000f; |
574 | mult = rxvt_rgba::MAX_CC / 0x000f; |
549 | 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)) |
550 | mult = rxvt_rgba::MAX_CC / 0x00ff; |
576 | mult = rxvt_rgba::MAX_CC / 0x00ff; |
551 | 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)) |
552 | mult = rxvt_rgba::MAX_CC / 0xffff; |
578 | mult = rxvt_rgba::MAX_CC / 0xffff; |
553 | 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)) |
554 | mult = rxvt_rgba::MAX_CC / 0xffff; |
580 | mult = rxvt_rgba::MAX_CC / 0xffff; |
|
|
581 | |
|
|
582 | // slow case: server round trip |
555 | else |
583 | else |
556 | return XftColorAllocName (screen->xdisp, screen->visual, screen->cmap, name, &c); |
584 | return XftColorAllocName (screen->xdisp, screen->visual, screen->cmap, name, &c); |
557 | |
585 | |
558 | 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 | |
559 | return set (screen, r); |
588 | return set (screen, r); |
560 | #else |
589 | #else |
561 | XColor xc; |
590 | XColor xc; |
562 | |
591 | |
563 | if (XParseColor (screen->xdisp, screen->cmap, name, &xc)) |
592 | if (XParseColor (screen->xdisp, screen->cmap, name, &xc)) |
… | |
… | |
569 | |
598 | |
570 | bool |
599 | bool |
571 | rxvt_color::set (rxvt_screen *screen, rxvt_rgba rgba) |
600 | rxvt_color::set (rxvt_screen *screen, rxvt_rgba rgba) |
572 | { |
601 | { |
573 | #if XFT |
602 | #if XFT |
574 | XRenderColor d; |
603 | XRenderPictFormat *format; |
575 | |
604 | |
576 | d.red = rgba.r; |
605 | // FUCKING Xft gets it wrong, of course, so work around it |
577 | d.green = rgba.g; |
|
|
578 | d.blue = rgba.b; |
|
|
579 | d.alpha = rgba.a; |
|
|
580 | |
|
|
581 | if (XftColorAllocValue (screen->xdisp, screen->visual, screen->cmap, &d, &c)) |
|
|
582 | { |
|
|
583 | // FUCKING Xft gets it wrong, of course, fix it for the common case |
|
|
584 | // transparency users should eat shit and die, and then |
606 | // transparency users should eat shit and die, and then |
585 | // XRenderQueryPictIndexValues themselves plenty. |
607 | // XRenderQueryPictIndexValues themselves plenty. |
586 | if (screen->depth == 32 && screen->visual->c_class == TrueColor) |
608 | if (screen->visual->c_class == TrueColor |
587 | if ((screen->visual->red_mask | screen->visual->green_mask | screen->visual->blue_mask) == 0x00ffffffUL) |
609 | && (format = XRenderFindVisualFormat (screen->xdisp, screen->visual))) |
588 | c.pixel = c.pixel & 0x00ffffffUL | ((rgba.a >> 8) << 24); |
610 | { |
589 | else if ((screen->visual->red_mask | screen->visual->green_mask | screen->visual->blue_mask) == 0xffffff00UL) |
611 | // the fun lies in doing everything manually... |
590 | c.pixel = c.pixel & 0xffffff00UL | (rgba.a >> 8); |
612 | c.color.red = rgba.r; |
|
|
613 | c.color.green = rgba.g; |
|
|
614 | c.color.blue = rgba.b; |
|
|
615 | c.color.alpha = rgba.a; |
|
|
616 | |
|
|
617 | c.pixel = ((rgba.r * format->direct.redMask / rxvt_rgba::MAX_CC) << format->direct.red ) |
|
|
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); |
591 | |
621 | |
592 | return true; |
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); |
593 | } |
634 | } |
594 | |
635 | |
595 | return false; |
636 | return false; |
596 | #else |
637 | #else |
597 | XColor xc; |
638 | XColor xc; |