--- rxvt-unicode/src/rxvtcolor.C 2004/02/11 08:13:45 1.6 +++ rxvt-unicode/src/rxvtcolor.C 2004/07/29 22:34:12 1.17 @@ -1,3 +1,25 @@ +/*--------------------------------*-C-*---------------------------------* + * File: rxvtcolor.C + *----------------------------------------------------------------------* + * + * All portions of code are copyright by their respective author/s. + * Copyright (c) 2003-2004 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + *----------------------------------------------------------------------*/ + #include "../config.h" #include #include @@ -5,6 +27,23 @@ #include #include +class byteorder byteorder; + +byteorder::byteorder () +{ + union { + uint32_t u; + uint8_t b[4]; + } w; + + w.b[0] = 0x11; + w.b[1] = 0x22; + w.b[2] = 0x33; + w.b[3] = 0x44; + + e = w.u; +} + refcounted::refcounted (const char *id) { this->id = STRDUP (id); @@ -18,7 +57,7 @@ template T *refcache::get (const char *id) { - for (T **i = begin (); i < end (); ++i) + for (T **i = this->begin (); i < this->end (); ++i) { if (!strcmp (id, (*i)->id)) { @@ -33,7 +72,7 @@ if (obj && obj->init ()) { - push_back (obj); + this->push_back (obj); return obj; } else @@ -51,7 +90,7 @@ if (!--obj->referenced) { - erase (find (begin (), end (), obj)); + this->erase (find (this->begin (), this->end (), obj)); delete obj; } } @@ -59,12 +98,13 @@ template refcache::~refcache () { - while (size ()) - put (*begin ()); + while (this->size ()) + put (*this->begin ()); } ///////////////////////////////////////////////////////////////////////////// +#ifdef USE_XIM static void im_destroy_cb (XIM unused1, XPointer client_data, XPointer unused3) { @@ -89,7 +129,8 @@ ximcallback.client_data = (XPointer)this; ximcallback.callback = im_destroy_cb; - XSetIMValues (xim, XNDestroyCallback, &ximcallback, NULL); + ((void (*)(XIM, ...)) XSetIMValues) + (xim, XNDestroyCallback, &ximcallback, NULL); return true; } @@ -99,12 +140,13 @@ if (xim) XCloseIM (xim); } +#endif ///////////////////////////////////////////////////////////////////////////// rxvt_display::rxvt_display (const char *id) : refcounted (id) -, x_watcher (this, &rxvt_display::x_event) +, x_ev (this, &rxvt_display::x_cb) , selection_owner (0) { } @@ -113,6 +155,9 @@ { display = XOpenDisplay (id); + if (!display) + return false; + screen = DefaultScreen (display); root = DefaultRootWindow (display); visual = DefaultVisual (display, screen); @@ -139,29 +184,36 @@ #endif int fd = XConnectionNumber (display); - x_watcher.start (fd, EVENT_READ); - fcntl (fd, F_SETFL, FD_CLOEXEC); + x_ev.start (fd, EVENT_READ); + fcntl (fd, F_SETFD, FD_CLOEXEC); XSelectInput (display, root, PropertyChangeMask); +#ifdef USE_XIM xa_xim_servers = XInternAtom (display, "XIM_SERVERS", 0); +#endif + + flush (); return true; } rxvt_display::~rxvt_display () { - x_watcher.stop (); + x_ev.stop (); - XCloseDisplay (display); + if (display) + XCloseDisplay (display); } +#ifdef USE_XIM void rxvt_display::im_change_cb () { for (im_watcher **i = imw.begin (); i != imw.end (); ++i) (*i)->call (); } +#endif -void rxvt_display::x_event (io_watcher &w, short revents) +void rxvt_display::x_cb (io_watcher &w, short revents) { do { @@ -170,10 +222,12 @@ //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--; ) { @@ -184,6 +238,21 @@ } } while (XPending (display)); + + flush (); +} + +void rxvt_display::flush () +{ + for (;;) + { + XFlush (display); + + if (!XPending (display)) + break; + + x_cb (x_ev, 0); + } } void rxvt_display::reg (xevent_watcher *w) @@ -198,6 +267,15 @@ xw[w->active - 1] = 0; } +void rxvt_display::set_selection_owner (rxvt_term *owner) +{ + if (selection_owner && selection_owner != owner) + selection_owner->selection_clear (); + + selection_owner = owner; +} + +#ifdef USE_XIM void rxvt_display::reg (im_watcher *w) { imw.push_back (w); @@ -208,22 +286,20 @@ imw.erase (find (imw.begin (), imw.end (), w)); } -void rxvt_display::set_selection_owner (rxvt_term *owner) -{ - if (selection_owner && selection_owner != owner) - selection_owner->selection_clear (); - - selection_owner = owner; -} - rxvt_xim *rxvt_display::get_xim (const char *locale, const char *modifiers) { - // asprintf is a GNU and *BSD extension.. sorry... char *id; + int l, m; + + l = strlen (locale); + m = strlen (modifiers); - if (asprintf (&id, "%s\n%s", locale, modifiers) < 0) + if (!(id = (char *)malloc (l + m + 2))) return 0; + memcpy (id, locale, l); id[l] = '\n'; + memcpy (id + l + 1, modifiers, m); id[l + m + 1] = 0; + rxvt_xim *xim = xims.get (id); free (id); @@ -235,10 +311,16 @@ { xims.put (xim); } +#endif + +Atom rxvt_display::atom (const char *name) +{ + return XInternAtom (display, name, False); +} ///////////////////////////////////////////////////////////////////////////// -template refcache; +template class refcache; refcache displays; ///////////////////////////////////////////////////////////////////////////// @@ -324,7 +406,7 @@ #if XFT XftColorFree (display->display, display->visual, display->cmap, &c); #else - XFreeColors (display->display, display->cmap, &c, 1, AllPlanes); + XFreeColors (display->display, display->cmap, &p, 1, AllPlanes); #endif }