--- rxvt-unicode/src/rxvttoolkit.C 2012/06/03 15:50:22 1.132 +++ rxvt-unicode/src/rxvttoolkit.C 2014/12/17 14:25:01 1.148 @@ -8,7 +8,7 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, @@ -25,6 +25,8 @@ #include #include +#include + #include #include @@ -68,7 +70,7 @@ "WM_LOCALE_NAME", "XIM_SERVERS", #endif -#ifdef ENABLE_TRANSPARENCY +#if HAVE_IMG || ENABLE_PERL "_XROOTPMAP_ID", "ESETROOT_PMAP_ID", #endif @@ -155,7 +157,7 @@ ///////////////////////////////////////////////////////////////////////////// -#ifdef USE_XIM +#if USE_XIM static void #if XIMCB_PROTO_BROKEN @@ -262,21 +264,41 @@ cmap = DefaultColormapOfScreen (screen); } +#if ENABLE_FRILLS + void -rxvt_screen::select_visual (int bitdepth) +rxvt_screen::select_visual (int id) { -#if XFT XVisualInfo vinfo; + vinfo.visualid = id; + int n; - if (XMatchVisualInfo (dpy, display->screen, bitdepth, TrueColor, &vinfo)) + if (XVisualInfo *vi = XGetVisualInfo (dpy, VisualIDMask, &vinfo, &n)) { - depth = bitdepth; - visual = vinfo.visual; - cmap = XCreateColormap (dpy, display->root, visual, AllocNone); + depth = vi->depth; + visual = vi->visual; + + XFree (vi); + + cmap = XCreateColormap (dpy, display->root, visual, AllocNone); } -#endif + else + rxvt_warn ("no visual found for requested id 0x%02x, using default visual.\n", id); +} + +void +rxvt_screen::select_depth (int bitdepth) +{ + XVisualInfo vinfo; + + if (XMatchVisualInfo (dpy, display->screen, bitdepth, TrueColor, &vinfo)) + select_visual (vinfo.visualid); + else + rxvt_warn ("no visual found for requested depth %d, using default visual.\n", bitdepth); } +#endif + void rxvt_screen::clear () { @@ -472,22 +494,19 @@ #if XRENDER int major, minor; if (XRenderQueryVersion (dpy, &major, &minor)) - { - flags |= DISPLAY_HAS_RENDER; - - if (major > 0 || (major == 0 && minor >= 11)) - flags |= DISPLAY_HAS_RENDER_MUL; + if (major > 0 || (major == 0 && minor >= 11)) + { + flags |= DISPLAY_HAS_RENDER; - XFilters *filters = XRenderQueryFilters (dpy, root); - if (filters) - { - for (int i = 0; i < filters->nfilter; i++) - if (!strcmp (filters->filter[i], FilterConvolution)) - flags |= DISPLAY_HAS_RENDER_CONV; + if (XFilters *filters = XRenderQueryFilters (dpy, root)) + { + for (int i = 0; i < filters->nfilter; i++) + if (!strcmp (filters->filter [i], FilterConvolution)) + flags |= DISPLAY_HAS_RENDER_CONV; - XFree (filters); - } - } + XFree (filters); + } + } #endif int fd = XConnectionNumber (dpy); @@ -536,14 +555,14 @@ #endif x_ev.stop (); flush_ev.stop (); -#ifdef USE_XIM +#if USE_XIM xims.clear (); #endif XrmDestroyDatabase (XrmGetDatabase (dpy)); XCloseDisplay (dpy); } -#ifdef USE_XIM +#if USE_XIM void rxvt_display::im_change_cb () { for (im_watcher **i = imw.begin (); i != imw.end (); ++i) @@ -589,7 +608,7 @@ XEvent xev; XNextEvent (dpy, &xev); -#ifdef USE_XIM +#if USE_XIM if (!XFilterEvent (&xev, None)) { if (xev.type == PropertyNotify @@ -607,7 +626,7 @@ else if (xw[i]->window == xev.xany.window) xw[i]->call (xev); } -#ifdef USE_XIM +#if USE_XIM } #endif } @@ -648,7 +667,7 @@ cur_owner = owner; } -#ifdef USE_XIM +#if USE_XIM void rxvt_display::reg (im_watcher *w) { @@ -693,6 +712,28 @@ return XInternAtom (dpy, name, False); } +Pixmap +rxvt_display::get_pixmap_property (Atom property) +{ + Pixmap pixmap = None; + + int aformat; + unsigned long nitems, bytes_after; + Atom atype; + unsigned char *prop; + int result = XGetWindowProperty (dpy, root, property, + 0L, 1L, False, XA_PIXMAP, &atype, &aformat, + &nitems, &bytes_after, &prop); + if (result == Success) + { + if (atype == XA_PIXMAP) + pixmap = *(Pixmap *)prop; + XFree (prop); + } + + return pixmap; +} + ///////////////////////////////////////////////////////////////////////////// template class refcache; @@ -716,6 +757,13 @@ #if XFT XRenderPictFormat *format; + // not needed by XftColorAlloc, but by the other paths (ours + // and fallback), so just set all components here. + c.color.red = color.r; + c.color.green = color.g; + c.color.blue = color.b; + c.color.alpha = alpha; + // FUCKING Xft gets it wrong, of course, so work around it. // Transparency users should eat shit and die, and then // XRenderQueryPictIndexValues themselves plenty. @@ -723,10 +771,6 @@ && (format = XRenderFindVisualFormat (screen->dpy, screen->visual))) { // the fun lies in doing everything manually... - c.color.red = color.r; - c.color.green = color.g; - c.color.blue = color.b; - c.color.alpha = alpha; // Xft wants premultiplied alpha, but abuses the alpha channel // as blend factor, and doesn't allow us to set the alpha channel @@ -750,6 +794,7 @@ d.blue = color.b; d.alpha = alpha; + // XftColorAlloc always returns 100% transparent pixels(!) if (XftColorAllocValue (screen->dpy, screen->visual, screen->cmap, &d, &c)) return true; } @@ -770,7 +815,7 @@ return true; #endif - c.pixel = (color.r + color.g + color.b) > 128*3 + c.pixel = (color.r * 2 + color.g * 3 + color.b) >= 0x8000 * 6 ? WhitePixelOfScreen (DefaultScreenOfDisplay (screen->dpy)) : BlackPixelOfScreen (DefaultScreenOfDisplay (screen->dpy)); @@ -838,26 +883,35 @@ // many extra optimisations. XQueryColors (screen->dpy, screen->cmap, colors, cmap_size); - int diff = 0x7fffffffUL; - XColor *best = colors; - - for (int i = 0; i < cmap_size; i++) + while (cmap_size) { - int d = (squared_diff (color.r >> 2, colors [i].red >> 2)) - + (squared_diff (color.g >> 2, colors [i].green >> 2)) - + (squared_diff (color.b >> 2, colors [i].blue >> 2)); + int diff = 0x7fffffffL; + XColor *best = colors; - if (d < diff) + for (int i = 0; i < cmap_size; i++) { - diff = d; - best = colors + i; + // simple weighted rgb distance sucks, but keeps it simple + int d = abs (color.r - colors [i].red ) * 2 + + abs (color.g - colors [i].green) * 3 + + abs (color.b - colors [i].blue ); + + if (d < diff) + { + diff = d; + best = colors + i; + } } - } - //rxvt_warn ("could not allocate %04x %04x %04x, getting %04x %04x %04x instead (%d)\n", - // color.r, color.g, color.b, best->red, best->green, best->blue, diff); + //rxvt_warn ("could not allocate %04x %04x %04x, getting %04x %04x %04x instead (%d,%d)\n", + // color.r, color.g, color.b, best->red, best->green, best->blue, diff, best - colors); - got = alloc (screen, rgba (best->red, best->green, best->blue)); + got = alloc (screen, rgba (best->red, best->green, best->blue)); + + if (got) + break; + + *best = colors [--cmap_size]; + } delete [] colors; } @@ -867,9 +921,10 @@ } void -rxvt_color::get (rgba &color) +rxvt_color::get (rgba &color) const { #if XFT + //TODO premultiplied alpha?? color.r = c.color.red; color.g = c.color.green; color.b = c.color.blue; @@ -883,7 +938,7 @@ } void -rxvt_color::get (XColor &color) +rxvt_color::get (XColor &color) const { rgba c; get (c);