--- rxvt-unicode/src/rxvttoolkit.C 2006/07/05 19:22:15 1.58 +++ rxvt-unicode/src/rxvttoolkit.C 2007/12/04 16:24:00 1.79 @@ -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; } @@ -264,10 +264,8 @@ } void -rxvt_screen::set (rxvt_display *disp, int bitdepth) +rxvt_screen::select_visual (int bitdepth) { - set (disp); - #if XFT XVisualInfo vinfo; @@ -275,7 +273,7 @@ { depth = bitdepth; visual = vinfo.visual; - cmap = XCreateColormap (dpy, disp->root, visual, AllocNone); + cmap = XCreateColormap (dpy, display->root, visual, AllocNone); } #endif } @@ -299,9 +297,9 @@ rxvt_display::rxvt_display (const char *id) : refcounted (id) -, x_ev (this, &rxvt_display::x_cb) , selection_owner (0) { + x_ev.set (this); } XrmDatabase @@ -317,6 +315,7 @@ XrmDatabase rdb1, database = 0; // for ordering, see for example http://www.faqs.org/faqs/Xt-FAQ/ Subject: 20 + // as opposed to "standard practise", we always read in ~/.Xdefaults // 6. System wide per application default file. @@ -333,6 +332,14 @@ // none // 4. User's defaults file. + if (homedir) + { + snprintf (fname, sizeof (fname), "%s/.Xdefaults", homedir); + + if ((rdb1 = XrmGetFileDatabase (fname))) + XrmMergeDatabases (rdb1, &database); + } + /* Get any Xserver defaults */ if (refresh) { @@ -358,6 +365,7 @@ else { displayResource = 0; + if (val) XFree(val); } @@ -374,13 +382,6 @@ if ((rdb1 = XrmGetStringDatabase (displayResource))) XrmMergeDatabases (rdb1, &database); } - else if (homedir) - { - snprintf (fname, sizeof (fname), "%s/.Xdefaults", homedir); - - if ((rdb1 = XrmGetFileDatabase (fname))) - XrmMergeDatabases (rdb1, &database); - } #if !XLIB_ILLEGAL_ACCESS if (refresh && displayResource) @@ -463,16 +464,16 @@ 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); + x_ev.start (fd, ev::READ); fcntl (fd, F_SETFD, FD_CLOEXEC); XSelectInput (dpy, root, PropertyChangeMask); @@ -539,9 +540,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); @@ -554,6 +555,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]) @@ -565,29 +569,31 @@ } #endif } - while (XEventsQueued (dpy, QueuedAlready)); XFlush (dpy); } void rxvt_display::flush () { - if (XEventsQueued (dpy, QueuedAlready)) - x_cb (x_ev, EVENT_READ); - - XFlush (dpy); + x_cb (x_ev, ev::READ); } 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) @@ -658,7 +664,7 @@ { return (value * (mask + 1) >> 16) << shift; } - + bool rxvt_color::alloc (rxvt_screen *screen, const rgba &color) { @@ -702,12 +708,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; } @@ -738,10 +741,22 @@ else c.a = rgba::MAX_CC; + // parse the non-standard "#aarrggbb" format + if (name[0] == '#' && strlen (name) == 1+2+2+2+2 && 4 == sscanf (name+1, "%2hx%2hx%2hx%2hx%c", &c.a, &c.r, &c.g, &c.b, &eos)) + { + if (c.r) + c.r = (c.r << 8) | 0x0ff; + if (c.g) + c.g = (c.g << 8) | 0x0ff; + if (c.b) + c.b = (c.b << 8) | 0x0ff; + if (c.a) + c.a = (c.a << 8) | 0x0ff; + } // 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)) + else 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)) { @@ -778,7 +793,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); @@ -801,10 +816,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 @@ -839,7 +854,7 @@ color.pixel = (Pixel)*this; } -void +void rxvt_color::free (rxvt_screen *screen) { if (screen->visual->c_class == TrueColor) @@ -869,3 +884,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