--- rxvt-unicode/src/rxvttoolkit.C 2004/08/15 04:54:21 1.2 +++ rxvt-unicode/src/rxvttoolkit.C 2005/07/13 00:51:47 1.16 @@ -1,5 +1,5 @@ /*--------------------------------*-C-*---------------------------------* - * File: rxvtcolor.C + * File: rxvttoolkit.C *----------------------------------------------------------------------* * * All portions of code are copyright by their respective author/s. @@ -84,7 +84,7 @@ } template -refcache::~refcache () +void refcache::clear () { while (this->size ()) put (*this->begin ()); @@ -103,8 +103,9 @@ rxvt_xim *xim = (rxvt_xim *)client_data; rxvt_display *display = xim->display; - display->xims.erase (find (display->xims.begin (), display->xims.end (), xim)); + xim->xim = 0; + display->xims.erase (find (display->xims.begin (), display->xims.end (), xim)); display->im_change_cb (); } @@ -144,7 +145,21 @@ bool rxvt_display::init () { - display = XOpenDisplay (id); +#ifdef LOCAL_X_IS_UNIX + if (id[0] == ':') + { + val = rxvt_malloc (5 + strlen (id) + 1); + strcpy (val, "unix/"); + strcat (val, id); + display = XOpenDisplay (val); + free (val); + } + else +#endif + display = 0; + + if (!display) + display = XOpenDisplay (id); if (!display) return false; @@ -169,6 +184,17 @@ is_local = sa.sun_family == AF_LOCAL; #endif +#ifdef POINTER_BLANK + XColor blackcolour; + blackcolour.red = 0; + blackcolour.green = 0; + blackcolour.blue = 0; + Font f = XLoadFont (display, "fixed"); + blank_cursor = XCreateGlyphCursor (display, f, f, ' ', ' ', + &blackcolour, &blackcolour); + XUnloadFont (display, f); +#endif + #ifdef PREFER_24BIT /* * If depth is not 24, look for a 24bit visual. @@ -204,6 +230,9 @@ rxvt_display::~rxvt_display () { x_ev.stop (); +#ifdef USE_XIM + xims.clear (); +#endif if (display) XCloseDisplay (display); @@ -215,6 +244,31 @@ for (im_watcher **i = imw.begin (); i != imw.end (); ++i) (*i)->call (); } + +void rxvt_display::im_change_check () +{ + // try to only call im_change_cb when a new input method + // registers, as xlib crashes due to a race otherwise. + Atom actual_type, *atoms; + int actual_format; + unsigned long nitems, bytes_after; + + if (XGetWindowProperty (display, root, xa_xim_servers, 0L, 1000000L, + False, XA_ATOM, &actual_type, &actual_format, + &nitems, &bytes_after, (unsigned char **)&atoms) + != Success ) + return; + + if (actual_type == XA_ATOM && actual_format == 32) + for (int i = 0; i < nitems; i++) + if (XGetSelectionOwner (display, atoms[i])) + { + im_change_cb (); + break; + } + + XFree (atoms); +} #endif void rxvt_display::x_cb (io_watcher &w, short revents) @@ -224,37 +278,37 @@ XEvent xev; XNextEvent (display, &xev); - //printf ("T %d w %lx\n", xev.type, xev.xany.window);//D - #ifdef USE_XIM - if (xev.type == PropertyNotify - && xev.xany.window == root - && xev.xproperty.atom == xa_xim_servers) - im_change_cb (); -#endif - - for (int i = xw.size (); i--; ) + if (!XFilterEvent (&xev, None)) { - if (!xw[i]) - xw.erase_unordered (i); - else if (xw[i]->window == xev.xany.window) - xw[i]->call (xev); + + if (xev.type == PropertyNotify + && xev.xany.window == root + && xev.xproperty.atom == xa_xim_servers) + im_change_check (); +#endif + for (int i = xw.size (); i--; ) + { + if (!xw[i]) + xw.erase_unordered (i); + else if (xw[i]->window == xev.xany.window) + xw[i]->call (xev); + } +#ifdef USE_XIM } +#endif } - while (XPending (display)); + while (XEventsQueued (display, QueuedAlready)); - flush (); + XFlush (display); } void rxvt_display::flush () { - for (;;) - { - if (!XPending (display)) - break; + if (XEventsQueued (display, QueuedAlready)) + x_cb (x_ev, EVENT_READ); - x_cb (x_ev, 0); - } + XFlush (display); } void rxvt_display::reg (xevent_watcher *w) @@ -311,7 +365,9 @@ void rxvt_display::put_xim (rxvt_xim *xim) { +#if XLIB_IS_RACEFREE xims.put (xim); +#endif } #endif @@ -359,12 +415,17 @@ bool rxvt_color::set (rxvt_display *display, const char *name) { +#if XFT + return XftColorAllocName (display->display, display->visual, display->cmap, + name, &c); +#else XColor xc; if (XParseColor (display->display, display->cmap, name, &xc)) return set (display, xc.red, xc.green, xc.blue); return false; +#endif } bool