# include <sys/un.h>
#endif
+#if XFT
+# include <X11/extensions/Xrender.h>
+#endif
+
const char *const xa_names[] =
{
"TEXT",
{
set (disp);
+#if XFT
XVisualInfo vinfo;
if (XMatchVisualInfo (xdisp, display->screen, bitdepth, TrueColor, &vinfo))
visual = vinfo.visual;
cmap = XCreateColormap (xdisp, disp->root, visual, AllocNone);
}
+#endif
}
void
rxvt_color::set (rxvt_screen *screen, rxvt_rgba rgba)
{
#if XFT
- XRenderColor d;
-
- d.red = rgba.r;
- d.green = rgba.g;
- d.blue = rgba.b;
- d.alpha = rgba.a;
+ XRenderPictFormat *format;
- if (XftColorAllocValue (screen->xdisp, screen->visual, screen->cmap, &d, &c))
+ // FUCKING Xft gets it wrong, of course, so work around it
+ // transparency users should eat shit and die, and then
+ // XRenderQueryPictIndexValues themselves plenty.
+ if (screen->visual->c_class == TrueColor
+ && (format = XRenderFindVisualFormat (screen->xdisp, screen->visual)))
{
- // FUCKING Xft gets it wrong, of course, fix it for the common case
- // transparency users should eat shit and die, and then
- // XRenderQueryPictIndexValues themselves plenty.
- if (screen->depth == 32 && screen->visual->c_class == TrueColor)
- if ((screen->visual->red_mask | screen->visual->green_mask | screen->visual->blue_mask) == 0x00ffffffUL)
- c.pixel = c.pixel & 0x00ffffffUL | ((rgba.a >> 8) << 24);
- else if ((screen->visual->red_mask | screen->visual->green_mask | screen->visual->blue_mask) == 0xffffff00UL)
- c.pixel = c.pixel & 0xffffff00UL | (rgba.a >> 8);
+ // the fun lies in doing everything manually...
+ c.color.red = rgba.r;
+ c.color.green = rgba.g;
+ c.color.blue = rgba.b;
+ c.color.alpha = rgba.a;
+
+ c.pixel = (rgba.r >> (16 - popcount (format->direct.redMask )) << format->direct.red)
+ | (rgba.g >> (16 - popcount (format->direct.greenMask)) << format->direct.green)
+ | (rgba.b >> (16 - popcount (format->direct.blueMask )) << format->direct.blue)
+ | (rgba.a >> (16 - popcount (format->direct.alphaMask)) << format->direct.alpha);
return true;
}
+ else
+ {
+ XRenderColor d;
+
+ d.red = rgba.r;
+ d.green = rgba.g;
+ d.blue = rgba.b;
+ d.alpha = rgba.a;
+
+ return XftColorAllocValue (screen->xdisp, screen->visual, screen->cmap, &d, &c);
+ }
return false;
#else
#define PP_STRINGIFY_(a) #a
#define PP_STRINGIFY(a) PP_STRINGIFY_(a)
+// actually, some gcc-3.x versions work, too
+#define HAVE_GCC_BUILTINS (__GNUC__ >= 4)
+#define HAVE_GCC_BUILTINS 0
+
extern class byteorder {
static unsigned int e; // at least 32 bits
public:
return (int(a) * int(p) + int(b) * int(100 - p)) / 100;
}
+// some bit functions, xft fuck me plenty
+#if HAVE_GCC_BUILTINS
+static inline int ctz (unsigned int x) { return __builtin_ctz (x); }
+static inline int popcount (unsigned int x) { return __builtin_popcount (x); }
+#else
+// count trailing zero bits and count # of one bits
+int ctz (unsigned int x);
+int popcount (unsigned int x);
+#endif
+
// in range including end
#define IN_RANGE_INC(val,beg,end) \
((unsigned int)(val) - (unsigned int)(beg) <= (unsigned int)(end) - (unsigned int)(beg))