--- rxvt-unicode/src/rxvttoolkit.C 2006/01/31 16:43:55 1.41 +++ rxvt-unicode/src/rxvttoolkit.C 2006/02/02 14:41:00 1.49 @@ -179,7 +179,7 @@ { display = GET_R->display; //HACK: TODO - xim = XOpenIM (display->display, NULL, NULL, NULL); + xim = XOpenIM (display->display, 0, 0, 0); if (!xim) return false; @@ -188,7 +188,7 @@ ximcallback.client_data = (XPointer)this; ximcallback.callback = im_destroy_cb; - XSetIMValues (xim, XNDestroyCallback, &ximcallback, NULL); + XSetIMValues (xim, XNDestroyCallback, &ximcallback, 0); return true; } @@ -250,7 +250,7 @@ } XrmDatabase -rxvt_display::get_resources () +rxvt_display::get_resources (bool refresh) { char *homedir = (char *)getenv ("HOME"); char fname[1024]; @@ -259,9 +259,7 @@ * get resources using the X library function */ char *displayResource, *xe; - XrmDatabase database, rdb1; - - database = NULL; + XrmDatabase rdb1, database = 0; // for ordering, see for example http://www.faqs.org/faqs/Xt-FAQ/ Subject: 20 @@ -281,9 +279,42 @@ // 4. User's defaults file. /* Get any Xserver defaults */ - displayResource = XResourceManagerString (display); + if (refresh) + { + // fucking xlib keeps a copy of the rm string + Atom actual_type; + int actual_format; + unsigned long nitems, nremaining; + char *val = 0; + +#if XLIB_ILLEGAL_ACCESS + if (display->xdefaults) + XFree (display->xdefaults); +#endif + + if (XGetWindowProperty (display, root, XA_RESOURCE_MANAGER, + 0L, 100000000L, False, + XA_STRING, &actual_type, &actual_format, + &nitems, &nremaining, + (unsigned char **)&val) == Success + && actual_type == XA_STRING + && actual_format == 8) + displayResource = val; + else + { + displayResource = 0; + if (val) + XFree(val); + } - if (displayResource != NULL) +#if XLIB_ILLEGAL_ACCESS + display->xdefaults = displayResource; +#endif + } + else + displayResource = XResourceManagerString (display); + + if (displayResource) { if ((rdb1 = XrmGetStringDatabase (displayResource))) XrmMergeDatabases (rdb1, &database); @@ -296,10 +327,15 @@ XrmMergeDatabases (rdb1, &database); } +#if !XLIB_ILLEGAL_ACCESS + if (refresh && displayResource) + XFree (displayResource); +#endif + /* Get screen specific resources */ displayResource = XScreenResourceString (ScreenOfDisplay (display, screen)); - if (displayResource != NULL) + if (displayResource) { if ((rdb1 = XrmGetStringDatabase (displayResource))) /* Merge with screen-independent resources */ @@ -350,13 +386,13 @@ if (!display) return false; - screen = DefaultScreen (display); + screen = DefaultScreen (display); root = DefaultRootWindow (display); assert (sizeof (xa_names) / sizeof (char *) == NUM_XA); XInternAtoms (display, (char **)xa_names, NUM_XA, False, xa); - XrmSetDatabase (display, get_resources ()); + XrmSetDatabase (display, get_resources (false)); #ifdef POINTER_BLANK XColor blackcolour; @@ -397,9 +433,9 @@ rxvt_display::ref_next () { // TODO: somehow check wether the database files/resources changed - // before re-loading/parsing + // before affording re-loading/parsing XrmDestroyDatabase (XrmGetDatabase (display)); - XrmSetDatabase (display, get_resources ()); + XrmSetDatabase (display, get_resources (true)); } rxvt_display::~rxvt_display () @@ -510,6 +546,7 @@ } #ifdef USE_XIM + void rxvt_display::reg (im_watcher *w) { imw.push_back (w); @@ -543,10 +580,11 @@ void rxvt_display::put_xim (rxvt_xim *xim) { -#if XLIB_IS_RACEFREE +# if XLIB_IS_RACEFREE xims.put (xim); -#endif +# endif } + #endif Atom rxvt_display::atom (const char *name) @@ -562,15 +600,15 @@ ///////////////////////////////////////////////////////////////////////////// bool -rxvt_color::alloc (rxvt_screen *screen, const rxvt_rgba &color) +rxvt_color::alloc (rxvt_screen *screen, const rgba &color) { #if XFT XRenderPictFormat *format; - // FUCKING Xft gets it wrong, of course, so work around it - // transparency users should eat shit and die, and then + // 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 || screen->visual->c_class == DirectColor) + if ((screen->visual->c_class == TrueColor) && (format = XRenderFindVisualFormat (screen->xdisp, screen->visual))) { // the fun lies in doing everything manually... @@ -579,10 +617,10 @@ c.color.blue = color.b; c.color.alpha = color.a; - c.pixel = ((color.r * format->direct.redMask / rxvt_rgba::MAX_CC) << format->direct.red ) - | ((color.g * format->direct.greenMask / rxvt_rgba::MAX_CC) << format->direct.green) - | ((color.b * format->direct.blueMask / rxvt_rgba::MAX_CC) << format->direct.blue ) - | ((color.a * format->direct.alphaMask / rxvt_rgba::MAX_CC) << format->direct.alpha); + c.pixel = ((color.r * format->direct.redMask / rgba::MAX_CC) << format->direct.red ) + | ((color.g * format->direct.greenMask / rgba::MAX_CC) << format->direct.green) + | ((color.b * format->direct.blueMask / rgba::MAX_CC) << format->direct.blue ) + | ((color.a * format->direct.alphaMask / rgba::MAX_CC) << format->direct.alpha); return true; } @@ -598,35 +636,27 @@ return XftColorAllocValue (screen->xdisp, screen->visual, screen->cmap, &d, &c); } #else - if (screen->visual->c_class == TrueColor || screen->visual->c_class == DirectColor) - { - p = (color.r * (screen->visual->red_mask >> ctz (screen->visual->red_mask )) - / rxvt_rgba::MAX_CC) << ctz (screen->visual->red_mask ) - | (color.g * (screen->visual->green_mask >> ctz (screen->visual->green_mask)) - / rxvt_rgba::MAX_CC) << ctz (screen->visual->green_mask) - | (color.b * (screen->visual->blue_mask >> ctz (screen->visual->blue_mask )) - / rxvt_rgba::MAX_CC) << ctz (screen->visual->blue_mask ); + c.red = color.r; + c.green = color.g; + c.blue = color.b; + + if (screen->visual->c_class == TrueColor) + { + c.pixel = (color.r * (screen->visual->red_mask >> ctz (screen->visual->red_mask )) + / rgba::MAX_CC) << ctz (screen->visual->red_mask ) + | (color.g * (screen->visual->green_mask >> ctz (screen->visual->green_mask)) + / rgba::MAX_CC) << ctz (screen->visual->green_mask) + | (color.b * (screen->visual->blue_mask >> ctz (screen->visual->blue_mask )) + / rgba::MAX_CC) << ctz (screen->visual->blue_mask ); return true; } + else if (XAllocColor (screen->xdisp, screen->cmap, &c)) + return true; else - { - XColor xc; - - xc.red = color.r; - xc.green = color.g; - xc.blue = color.b; - - if (XAllocColor (screen->xdisp, screen->cmap, &xc)) - { - p = xc.pixel; - return true; - } - else - p = (color.r + color.g + color.b) > 128*3 + c.pixel = (color.r + color.g + color.b) > 128*3 ? WhitePixelOfScreen (DefaultScreenOfDisplay (screen->xdisp)) : BlackPixelOfScreen (DefaultScreenOfDisplay (screen->xdisp)); - } #endif return false; @@ -635,20 +665,21 @@ bool rxvt_color::set (rxvt_screen *screen, const char *name) { - rxvt_rgba c; + rgba c; char eos; int skip; + // parse the nonstandard "[alphapercent]" prefix if (1 <= sscanf (name, "[%hd]%n", &c.a, &skip)) { - c.a = lerp (0, rxvt_rgba::MAX_CC, c.a); + c.a = lerp (0, rgba::MAX_CC, c.a); name += skip; } else - c.a = rxvt_rgba::MAX_CC; + c.a = rgba::MAX_CC; - // parse the non-standard rgba format - if (strlen (name) != 4+5*4 || 4 != sscanf (name, "rgba:%hx/%hx/%hx/%hx%c", &c.r, &c.g, &c.b, &c.a, &eos)) + // parse the non-standard "rgba:rrrr/gggg/bbbb/aaaa" format + if (strlen (name) != 4+5*4 || 4 != sscanf (name, "rgba:%4hx/%4hx/%4hx/%4hx%c", &c.r, &c.g, &c.b, &c.a, &eos)) { XColor xc, xc_exact; @@ -672,7 +703,7 @@ } bool -rxvt_color::set (rxvt_screen *screen, const rxvt_rgba &color) +rxvt_color::set (rxvt_screen *screen, const rgba &color) { bool got = alloc (screen, color); @@ -688,6 +719,8 @@ for (int i = 0; i < cmap_size; i++) colors [i].pixel = i; + // many kilobytes transfer per colour, but pseudocolor isn't worth + // many extra optimisations. XQueryColors (screen->xdisp, screen->cmap, colors, cmap_size); int diff = 0x7fffffffUL; @@ -709,7 +742,7 @@ //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); - got = alloc (screen, rxvt_rgba (best->red, best->green, best->blue)); + got = alloc (screen, rgba (best->red, best->green, best->blue)); delete colors; } @@ -719,7 +752,7 @@ } void -rxvt_color::get (rxvt_screen *screen, rxvt_rgba &color) +rxvt_color::get (rgba &color) { #if XFT color.r = c.color.red; @@ -727,45 +760,49 @@ color.b = c.color.blue; color.a = c.color.alpha; #else - XColor c; - - c.pixel = p; - XQueryColor (screen->xdisp, screen->cmap, &c); - color.r = c.red; color.g = c.green; color.b = c.blue; - color.a = rxvt_rgba::MAX_CC; + color.a = rgba::MAX_CC; #endif } +void +rxvt_color::get (XColor &color) +{ + rgba c; + get (c); + + color.red = c.r; + color.green = c.g; + color.blue = c.b; + color.pixel = (Pixel)*this; +} + void rxvt_color::free (rxvt_screen *screen) { #if XFT XftColorFree (screen->xdisp, screen->visual, screen->cmap, &c); #else - XFreeColors (screen->xdisp, screen->cmap, &p, 1, AllPlanes); + XFreeColors (screen->xdisp, screen->cmap, &c.pixel, 1, AllPlanes); #endif } -rxvt_color -rxvt_color::fade (rxvt_screen *screen, int percent, const rxvt_rgba &to) +void +rxvt_color::fade (rxvt_screen *screen, int percent, rxvt_color &result, const rgba &to) { - rxvt_rgba c; - get (screen, c); + rgba c; + get (c); - rxvt_color faded; - faded.set ( + result.set ( screen, - rxvt_rgba ( - lerp (to.r, c.r, percent), - lerp (to.g, c.g, percent), - lerp (to.b, c.b, percent), - lerp (to.a, c.a, percent) + rgba ( + lerp (c.r, to.r, percent), + lerp (c.g, to.g, percent), + lerp (c.b, to.b, percent), + lerp (c.a, to.a, percent) ) ); - - return faded; }