--- rxvt-unicode/src/rxvtcolor.C 2004/03/30 14:45:13 1.11 +++ rxvt-unicode/src/rxvtcolor.C 2004/08/04 03:29:28 1.22 @@ -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,11 @@ #include #include +#ifndef NO_SLOW_LINK_SUPPORT +# include +# include +#endif + class byteorder byteorder; byteorder::byteorder () @@ -35,7 +62,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)) { @@ -50,7 +77,7 @@ if (obj && obj->init ()) { - push_back (obj); + this->push_back (obj); return obj; } else @@ -68,7 +95,7 @@ if (!--obj->referenced) { - erase (find (begin (), end (), obj)); + this->erase (find (this->begin (), this->end (), obj)); delete obj; } } @@ -76,14 +103,19 @@ template refcache::~refcache () { - while (size ()) - put (*begin ()); + while (this->size ()) + put (*this->begin ()); } ///////////////////////////////////////////////////////////////////////////// +#ifdef USE_XIM static void +#if XIMCB_PROTO_BROKEN +im_destroy_cb (XIC unused1, XPointer client_data, XPointer unused3) +#else im_destroy_cb (XIM unused1, XPointer client_data, XPointer unused3) +#endif { rxvt_xim *xim = (rxvt_xim *)client_data; rxvt_display *display = xim->display; @@ -116,6 +148,7 @@ if (xim) XCloseIM (xim); } +#endif ///////////////////////////////////////////////////////////////////////////// @@ -139,6 +172,20 @@ cmap = DefaultColormap (display, screen); depth = DefaultDepth (display, screen); + int fd = XConnectionNumber (display); + +#ifndef NO_SLOW_LINK_SUPPORT + // try to detetc wether we have a local connection. + // assume unix domains 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; +#endif + #ifdef PREFER_24BIT /* * If depth is not 24, look for a 24bit visual. @@ -158,12 +205,13 @@ } #endif - int fd = XConnectionNumber (display); x_ev.start (fd, EVENT_READ); - fcntl (fd, F_SETFL, FD_CLOEXEC); + fcntl (fd, F_SETFD, FD_CLOEXEC); XSelectInput (display, root, PropertyChangeMask); +#ifdef USE_XIM xa_xim_servers = XInternAtom (display, "XIM_SERVERS", 0); +#endif flush (); @@ -178,11 +226,13 @@ 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_cb (io_watcher &w, short revents) { @@ -193,10 +243,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--; ) { @@ -215,8 +267,6 @@ { for (;;) { - XFlush (display); - if (!XPending (display)) break; @@ -236,6 +286,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); @@ -246,22 +305,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); @@ -273,6 +330,7 @@ { xims.put (xim); } +#endif Atom rxvt_display::atom (const char *name) { @@ -281,7 +339,7 @@ ///////////////////////////////////////////////////////////////////////////// -template refcache; +template class refcache; refcache displays; ///////////////////////////////////////////////////////////////////////////// @@ -371,3 +429,18 @@ #endif } +rxvt_color +rxvt_color::fade (rxvt_display *display, int percent) +{ + unsigned short cr, cg, cb; + rxvt_color faded; + + get (display, cr, cg, cb); + faded.set (display, + cr * percent / 100, + cg * percent / 100, + cb * percent / 100); + + return faded; +} +