--- rxvt-unicode/src/rxvttoolkit.C 2011/02/21 08:10:10 1.122 +++ rxvt-unicode/src/rxvttoolkit.C 2012/06/03 17:48:28 1.133 @@ -432,10 +432,11 @@ #ifdef LOCAL_X_IS_UNIX if (id[0] == ':') { - if (!(val = rxvt_temp_buf (5 + strlen (id) + 1))) - return false; + char *val = rxvt_temp_buf (5 + strlen (id) + 1); + strcpy (val, "unix/"); strcat (val, id); + dpy = XOpenDisplay (val); } else @@ -451,7 +452,7 @@ screen = DefaultScreen (dpy); root = DefaultRootWindow (dpy); - assert (ARRAY_LENGTH(xa_names) == NUM_XA); + assert (ecb_array_length (xa_names) == NUM_XA); XInternAtoms (dpy, (char **)xa_names, NUM_XA, False, xa); XrmSetDatabase (dpy, get_resources (false)); @@ -467,6 +468,28 @@ XUnloadFont (dpy, f); #endif + flags = 0; +#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; + + 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; + + XFree (filters); + } + } +#endif + int fd = XConnectionNumber (dpy); // try to detect whether we have a local connection. @@ -670,6 +693,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; @@ -688,7 +733,7 @@ rxvt_color::alloc (rxvt_screen *screen, const rgba &color) { //TODO: only supports 24 bit - int alpha = color.a >= 0xff00 ? 0xffff : color.a; + unsigned int alpha = color.a >= 0xff00 ? 0xffff : color.a; #if XFT XRenderPictFormat *format; @@ -705,10 +750,16 @@ c.color.blue = color.b; c.color.alpha = alpha; - c.pixel = insert_component (color.r, format->direct.redMask , format->direct.red ) - | insert_component (color.g, format->direct.greenMask, format->direct.green) - | insert_component (color.b, format->direct.blueMask , format->direct.blue ) - | insert_component (alpha , format->direct.alphaMask, format->direct.alpha); + // Xft wants premultiplied alpha, but abuses the alpha channel + // as blend factor, and doesn't allow us to set the alpha channel + c.color.red = c.color.red * alpha / 0xffff; + c.color.green = c.color.green * alpha / 0xffff; + c.color.blue = c.color.blue * alpha / 0xffff; + + c.pixel = insert_component (c.color.red , format->direct.redMask , format->direct.red ) + | insert_component (c.color.green, format->direct.greenMask, format->direct.green) + | insert_component (c.color.blue , format->direct.blueMask , format->direct.blue ) + | insert_component (alpha , format->direct.alphaMask, format->direct.alpha); return true; } @@ -721,7 +772,8 @@ d.blue = color.b; d.alpha = alpha; - return XftColorAllocValue (screen->dpy, screen->visual, screen->cmap, &d, &c); + if (XftColorAllocValue (screen->dpy, screen->visual, screen->cmap, &d, &c)) + return true; } #else c.red = color.r; @@ -730,20 +782,20 @@ if (screen->visual->c_class == TrueColor) { - c.pixel = (color.r >> (16 - rxvt_popcount (screen->visual->red_mask )) << rxvt_ctz (screen->visual->red_mask )) - | (color.g >> (16 - rxvt_popcount (screen->visual->green_mask)) << rxvt_ctz (screen->visual->green_mask)) - | (color.b >> (16 - rxvt_popcount (screen->visual->blue_mask )) << rxvt_ctz (screen->visual->blue_mask )); + c.pixel = (color.r >> (16 - ecb_popcount32 (screen->visual->red_mask )) << ecb_ctz32 (screen->visual->red_mask )) + | (color.g >> (16 - ecb_popcount32 (screen->visual->green_mask)) << ecb_ctz32 (screen->visual->green_mask)) + | (color.b >> (16 - ecb_popcount32 (screen->visual->blue_mask )) << ecb_ctz32 (screen->visual->blue_mask )); return true; } else if (XAllocColor (screen->dpy, screen->cmap, &c)) return true; - else - c.pixel = (color.r + color.g + color.b) > 128*3 - ? WhitePixelOfScreen (DefaultScreenOfDisplay (screen->dpy)) - : BlackPixelOfScreen (DefaultScreenOfDisplay (screen->dpy)); #endif + c.pixel = (color.r + color.g + color.b) > 128*3 + ? WhitePixelOfScreen (DefaultScreenOfDisplay (screen->dpy)) + : BlackPixelOfScreen (DefaultScreenOfDisplay (screen->dpy)); + return false; } @@ -907,6 +959,7 @@ incr_buf_size = incr_buf_fill = 0; selection_wait = Sel_normal; selection_type = selnum; + cb_sv = 0; } void @@ -928,6 +981,17 @@ { int selnum = selection_type; +#if ENABLE_FRILLS + if (selnum == Sel_Primary && display->selection_owner) + { + /* internal selection */ + char *str = rxvt_wcstombs (display->selection_owner->selection.text, display->selection_owner->selection.len); + finish (str, strlen (str)); + free (str); + return; + } +#endif + #if X_HAVE_UTF8_STRING selection_type = Sel_UTF8String; if (request (display->xa[XA_UTF8_STRING], selnum)) @@ -945,7 +1009,7 @@ void rxvt_selection::finish (char *data, unsigned int len) { - if (term) + if (!cb_sv) { if (data) term->paste (data, len); @@ -1162,8 +1226,7 @@ case SelectionNotify: if (selection_wait == Sel_normal - && xev.xselection.time == request_time - && xev.xselection.property == request_prop) + && xev.xselection.time == request_time) { timer_ev.stop (); handle_selection (xev.xselection.requestor, xev.xselection.property, true);