--- rxvt-unicode/src/rxvttoolkit.C 2008/01/26 12:12:38 1.96 +++ rxvt-unicode/src/rxvttoolkit.C 2010/12/18 18:17:39 1.111 @@ -35,7 +35,7 @@ # include #endif -const char *const xa_names[] = +static const char *const xa_names[] = { "TEXT", "COMPOUND_TEXT", @@ -61,6 +61,7 @@ "_NET_WM_NAME", "_NET_WM_ICON_NAME", "_NET_WM_PING", + "_NET_WM_ICON", #endif #if USE_XIM "WM_LOCALE_NAME", @@ -298,6 +299,7 @@ rxvt_display::rxvt_display (const char *id) : refcounted (id) , selection_owner (0) +, clipboard_owner (0) { x_ev .set (this); flush_ev.set (this); @@ -362,14 +364,14 @@ (unsigned char **)&val) == Success && actual_type == XA_STRING && actual_format == 8) - displayResource = val; - else - { - displayResource = 0; - - if (val) - XFree(val); - } + displayResource = val; + else + { + displayResource = 0; + + if (val) + XFree (val); + } #if XLIB_ILLEGAL_ACCESS dpy->xdefaults = displayResource; @@ -427,11 +429,11 @@ #ifdef LOCAL_X_IS_UNIX if (id[0] == ':') { - val = rxvt_malloc (5 + strlen (id) + 1); + if (!(val = rxvt_temp_buf (5 + strlen (id) + 1))) + return false; strcpy (val, "unix/"); strcat (val, id); dpy = XOpenDisplay (val); - free (val); } else #endif @@ -446,7 +448,7 @@ screen = DefaultScreen (dpy); root = DefaultRootWindow (dpy); - assert (sizeof (xa_names) / sizeof (char *) == NUM_XA); + assert (ARRAY_LENGTH(xa_names) == NUM_XA); XInternAtoms (dpy, (char **)xa_names, NUM_XA, False, xa); XrmSetDatabase (dpy, get_resources (false)); @@ -464,7 +466,7 @@ int fd = XConnectionNumber (dpy); - // try to detect wether we have a local connection. + // try to detect whether we have a local connection. // assume unix domain socket == local, everything else not // TODO: might want to check for inet/127.0.0.1 is_local = 0; @@ -488,7 +490,7 @@ void rxvt_display::ref_next () { - // TODO: somehow check wether the database files/resources changed + // TODO: somehow check whether the database files/resources changed // before affording re-loading/parsing XrmDestroyDatabase (XrmGetDatabase (dpy)); XrmSetDatabase (dpy, get_resources (true)); @@ -528,10 +530,10 @@ if (XGetWindowProperty (dpy, root, xa[XA_XIM_SERVERS], 0L, 1000000L, False, XA_ATOM, &actual_type, &actual_format, &nitems, &bytes_after, (unsigned char **)&atoms) - != Success ) + != Success) return; - if (actual_type == XA_ATOM && actual_format == 32) + if (actual_type == XA_ATOM && actual_format == 32) for (int i = 0; i < nitems; i++) if (XGetSelectionOwner (dpy, atoms[i])) { @@ -545,43 +547,41 @@ void rxvt_display::x_cb (ev::io &w, int revents) { - while (XEventsQueued (dpy, QueuedAfterReading)) - { - XEvent xev; - XNextEvent (dpy, &xev); - -#ifdef USE_XIM - if (!XFilterEvent (&xev, None)) -#endif - { - if (xev.type == PropertyNotify - && xev.xany.window == root - && xev.xproperty.atom == xa[XA_XIM_SERVERS]) - im_change_check (); - - if (xev.type == MappingNotify) - XRefreshKeyboardMapping (&xev.xmapping); - - 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); - } - } - } + flush_ev.start (); } void rxvt_display::flush_cb (ev::prepare &w, int revents) { - XFlush (dpy); - if (XEventsQueued (dpy, QueuedAfterReading)) - x_cb(x_ev,0);//D - XFlush (dpy); - if (XEventsQueued (dpy, QueuedAfterReading)) - x_cb(x_ev,0);//D - XFlush (dpy); + while (XEventsQueued (dpy, QueuedAfterFlush)) + do + { + XEvent xev; + XNextEvent (dpy, &xev); + +#ifdef USE_XIM + if (!XFilterEvent (&xev, None)) + { + if (xev.type == PropertyNotify + && xev.xany.window == root + && 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]) + xw.erase_unordered (i); + else if (xw[i]->window == xev.xany.window) + xw[i]->call (xev); + } +#ifdef USE_XIM + } +#endif + } + while (XEventsQueued (dpy, QueuedAlready)); + w.stop (); } @@ -603,17 +603,18 @@ } } -void rxvt_display::set_selection_owner (rxvt_term *owner) +void rxvt_display::set_selection_owner (rxvt_term *owner, bool clipboard) { - if (selection_owner && selection_owner != owner) - { - rxvt_term *owner = selection_owner; + rxvt_term * &cur_owner = !clipboard ? selection_owner : clipboard_owner; - owner->selection_clear (); - owner->flush (); + if (cur_owner && cur_owner != owner) + { + rxvt_term *term = cur_owner; + term->selection_clear (clipboard); + term->flush (); } - selection_owner = owner; + cur_owner = owner; } #ifdef USE_XIM @@ -636,7 +637,7 @@ l = strlen (locale); m = strlen (modifiers); - if (!(id = (char *)malloc (l + m + 2))) + if (!(id = rxvt_temp_buf (l + m + 2))) return 0; memcpy (id, locale, l); id[l] = '\n'; @@ -644,8 +645,6 @@ rxvt_xim *xim = xims.get (id); - free (id); - return xim; } @@ -723,9 +722,9 @@ if (screen->visual->c_class == TrueColor) { - 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 )); + 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 )); return true; } @@ -887,19 +886,3 @@ ); } -#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