From: root Date: Sun, 29 Jan 2006 22:27:04 +0000 (+0000) Subject: *** empty log message *** X-Git-Url: http://git.openbox.org/?a=commitdiff_plain;h=ac52fd2c491af4716e8ccdc988d0172f44f9a487;p=dana%2Furxvt.git *** empty log message *** --- diff --git a/src/rxvttoolkit.C b/src/rxvttoolkit.C index ce9f4147..aa4356c1 100644 --- a/src/rxvttoolkit.C +++ b/src/rxvttoolkit.C @@ -34,6 +34,10 @@ # include #endif +#if XFT +# include +#endif + const char *const xa_names[] = { "TEXT", @@ -197,6 +201,7 @@ rxvt_screen::set (rxvt_display *disp, int bitdepth) { set (disp); +#if XFT XVisualInfo vinfo; if (XMatchVisualInfo (xdisp, display->screen, bitdepth, TrueColor, &vinfo)) @@ -205,6 +210,7 @@ rxvt_screen::set (rxvt_display *disp, int bitdepth) visual = vinfo.visual; cmap = XCreateColormap (xdisp, disp->root, visual, AllocNone); } +#endif } void @@ -571,26 +577,38 @@ bool 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 diff --git a/src/rxvtutil.h b/src/rxvtutil.h index 644a2979..bdbdb9f7 100644 --- a/src/rxvtutil.h +++ b/src/rxvtutil.h @@ -9,6 +9,10 @@ #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: @@ -39,6 +43,16 @@ T lerp (T a, U b, P p) 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))