--- rxvt-unicode/src/rxvttoolkit.C 2006/07/05 20:37:31 1.60 +++ rxvt-unicode/src/rxvttoolkit.C 2008/01/23 09:23:39 1.89 @@ -3,7 +3,7 @@ *----------------------------------------------------------------------* * * All portions of code are copyright by their respective author/s. - * Copyright (c) 2003-2006 Marc Lehmann + * Copyright (c) 2003-2007 Marc Lehmann * * 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 @@ -66,7 +66,7 @@ "WM_LOCALE_NAME", "XIM_SERVERS", #endif -#ifdef TRANSPARENT +#ifdef ENABLE_TRANSPARENCY "_XROOTPMAP_ID", "ESETROOT_PMAP_ID", #endif @@ -185,7 +185,7 @@ ximcallback.client_data = (XPointer)this; ximcallback.callback = im_destroy_cb; - XSetIMValues (xim, XNDestroyCallback, &ximcallback, 0); + XSetIMValues (xim, XNDestroyCallback, &ximcallback, (char *)0); return true; } @@ -297,15 +297,16 @@ rxvt_display::rxvt_display (const char *id) : refcounted (id) -, x_ev (this, &rxvt_display::x_cb) , selection_owner (0) { + x_ev .set (this); + flush_ev.set (this); } XrmDatabase rxvt_display::get_resources (bool refresh) { - char *homedir = (char *)getenv ("HOME"); + char *homedir = getenv ("HOME"); char fname[1024]; /* @@ -320,7 +321,7 @@ // 6. System wide per application default file. /* Add in $XAPPLRESDIR/Rxvt only; not bothering with XUSERFILESEARCHPATH */ - if ((xe = (char *)getenv ("XAPPLRESDIR"))) + if ((xe = getenv ("XAPPLRESDIR"))) { snprintf (fname, sizeof (fname), "%s/%s", xe, RESCLASS); @@ -402,7 +403,7 @@ // 3. User's per host defaults file /* Add in XENVIRONMENT file */ - if ((xe = (char *)getenv ("XENVIRONMENT")) + if ((xe = getenv ("XENVIRONMENT")) && (rdb1 = XrmGetFileDatabase (xe))) XrmMergeDatabases (rdb1, &database); else if (homedir) @@ -464,16 +465,17 @@ int fd = XConnectionNumber (dpy); // try to detect wether we have a local connection. - // assume unix domains socket == local, everything else not + // assume unix domain socket == local, everything else not // TODO: might want to check for inet/127.0.0.1 is_local = 0; sockaddr_un sa; socklen_t sl = sizeof (sa); if (!getsockname (fd, (sockaddr *)&sa, &sl)) - is_local = sa.sun_family == AF_LOCAL; + is_local = sa.sun_family == AF_UNIX; - x_ev.start (fd, EVENT_READ); + flush_ev.start (); + x_ev.start (fd, ev::READ); fcntl (fd, F_SETFD, FD_CLOEXEC); XSelectInput (dpy, root, PropertyChangeMask); @@ -501,6 +503,7 @@ XFreeCursor (dpy, blank_cursor); #endif x_ev.stop (); + flush_ev.stop (); #ifdef USE_XIM xims.clear (); #endif @@ -540,9 +543,9 @@ } #endif -void rxvt_display::x_cb (io_watcher &w, short revents) +void rxvt_display::x_cb (ev::io &w, int revents) { - do + while (XEventsQueued (dpy, QueuedAfterReading)) { XEvent xev; XNextEvent (dpy, &xev); @@ -555,6 +558,9 @@ && xev.xproperty.atom == xa[XA_XIM_SERVERS]) im_change_check (); #endif + if (xev.type == MappingNotify) + XRefreshKeyboardMapping (&xev.xmapping); + for (int i = xw.size (); i--; ) { if (!xw[i]) @@ -566,35 +572,41 @@ } #endif } - while (XEventsQueued (dpy, QueuedAlready)); - - XFlush (dpy); } -void rxvt_display::flush () +void rxvt_display::flush_cb (ev::prepare &w, int revents) { - if (XEventsQueued (dpy, QueuedAlready)) - x_cb (x_ev, EVENT_READ); - + w.stop (); XFlush (dpy); } void rxvt_display::reg (xevent_watcher *w) { - xw.push_back (w); - w->active = xw.size (); + if (!w->active) + { + xw.push_back (w); + w->active = xw.size (); + } } void rxvt_display::unreg (xevent_watcher *w) { if (w->active) - xw[w->active - 1] = 0; + { + xw[w->active - 1] = 0; + w->active = 0; + } } void rxvt_display::set_selection_owner (rxvt_term *owner) { if (selection_owner && selection_owner != owner) - selection_owner->selection_clear (); + { + rxvt_term *owner = selection_owner; + + owner->selection_clear (); + owner->flush (); + } selection_owner = owner; } @@ -659,10 +671,13 @@ { return (value * (mask + 1) >> 16) << shift; } - + bool rxvt_color::alloc (rxvt_screen *screen, const rgba &color) { + //TODO: only supports 24 bit truecolour + int alpha = color.a >= 0xff00 ? 0xffff : color.a; + #if XFT XRenderPictFormat *format; @@ -676,12 +691,12 @@ c.color.red = color.r; c.color.green = color.g; c.color.blue = color.b; - c.color.alpha = color.a; + 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 (color.a, format->direct.alphaMask, format->direct.alpha); + | insert_component (alpha , format->direct.alphaMask, format->direct.alpha); return true; } @@ -692,7 +707,7 @@ d.red = color.r; d.green = color.g; d.blue = color.b; - d.alpha = color.a; + d.alpha = alpha; return XftColorAllocValue (screen->dpy, screen->visual, screen->cmap, &d, &c); } @@ -703,12 +718,9 @@ 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 ); + c.pixel = (color.r >> (16 - popcount (screen->visual->red_mask )) << ctz (screen->visual->red_mask )) + | (color.g >> (16 - popcount (screen->visual->green_mask)) << ctz (screen->visual->green_mask)) + | (color.b >> (16 - popcount (screen->visual->blue_mask )) << ctz (screen->visual->blue_mask )); return true; } @@ -730,19 +742,19 @@ char eos; int skip; + c.a = rgba::MAX_CC; + // parse the nonstandard "[alphapercent]" prefix if (1 <= sscanf (name, "[%hd]%n", &c.a, &skip)) { c.a = lerp (0, rgba::MAX_CC, c.a); name += skip; } - else - c.a = rgba::MAX_CC; // 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; + XColor xc; if (XParseColor (screen->dpy, screen->cmap, name, &xc)) { @@ -779,7 +791,7 @@ 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->dpy, screen->cmap, colors, cmap_size); @@ -802,10 +814,10 @@ //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, rgba (best->red, best->green, best->blue)); - delete colors; + delete [] colors; } #endif @@ -840,7 +852,7 @@ color.pixel = (Pixel)*this; } -void +void rxvt_color::free (rxvt_screen *screen) { if (screen->visual->c_class == TrueColor) @@ -870,3 +882,19 @@ ); } +#if TRACE_PIXMAPS +# undef XCreatePixmap +# undef XFreePixmap +Pixmap trace_XCreatePixmap (const char *file, int line, Display *dpy, Window r, unsigned int w, unsigned int h, unsigned int d) +{ + Pixmap res = XCreatePixmap (dpy, r, w, h, d); + fprintf (stderr, "%s:%d: XCreatePixmap (%p,%lX,%u,%u,%u) returned %lX\n", file, line, dpy, r, w, h, d, res); + return res; +} + +void trace_XFreePixmap (const char *file, int line, Display *dpy, Pixmap p) +{ + fprintf (stderr, "%s:%d: XFreePixmap (%p,%lX)\n", file, line, dpy, p); + XFreePixmap (dpy,p); +} +#endif