*** empty log message ***
authorroot <root>
Sun, 29 Jan 2006 22:27:04 +0000 (22:27 +0000)
committerroot <root>
Sun, 29 Jan 2006 22:27:04 +0000 (22:27 +0000)
src/rxvttoolkit.C
src/rxvtutil.h

index ce9f41473f899fe8941c63625d962a20740221cb..aa4356c1d8d8fcb853a77ba8ab05ed85cf1abded 100644 (file)
 # include <sys/un.h>
 #endif
 
+#if XFT
+# include <X11/extensions/Xrender.h>
+#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
index 644a2979cc707ad32d5e673b08edd43a16b06913..bdbdb9f71c533a53e1944afdff30e522b37913cc 100644 (file)
@@ -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))