ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/rxvtcolor.C
(Generate patch)

Comparing rxvt-unicode/src/rxvtcolor.C (file contents):
Revision 1.7 by pcg, Thu Feb 12 01:42:03 2004 UTC vs.
Revision 1.17 by root, Thu Jul 29 22:34:12 2004 UTC

1/*--------------------------------*-C-*---------------------------------*
2 * File: rxvtcolor.C
3 *----------------------------------------------------------------------*
4 *
5 * All portions of code are copyright by their respective author/s.
6 * Copyright (c) 2003-2004 Marc Lehmann <pcg@goof.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 *----------------------------------------------------------------------*/
22
1#include "../config.h" 23#include "../config.h"
2#include <rxvt.h> 24#include <rxvt.h>
3#include <rxvtcolor.h> 25#include <rxvtcolor.h>
4 26
5#include <unistd.h> 27#include <unistd.h>
6#include <fcntl.h> 28#include <fcntl.h>
7 29
30class byteorder byteorder;
31
32byteorder::byteorder ()
33{
34 union {
35 uint32_t u;
36 uint8_t b[4];
37 } w;
38
39 w.b[0] = 0x11;
40 w.b[1] = 0x22;
41 w.b[2] = 0x33;
42 w.b[3] = 0x44;
43
44 e = w.u;
45}
46
8refcounted::refcounted (const char *id) 47refcounted::refcounted (const char *id)
9{ 48{
10 this->id = STRDUP (id); 49 this->id = STRDUP (id);
11} 50}
12 51
16} 55}
17 56
18template<class T> 57template<class T>
19T *refcache<T>::get (const char *id) 58T *refcache<T>::get (const char *id)
20{ 59{
21 for (T **i = begin (); i < end (); ++i) 60 for (T **i = this->begin (); i < this->end (); ++i)
22 { 61 {
23 if (!strcmp (id, (*i)->id)) 62 if (!strcmp (id, (*i)->id))
24 { 63 {
25 (*i)->referenced++; 64 (*i)->referenced++;
26 return *i; 65 return *i;
31 70
32 obj->referenced = 1; 71 obj->referenced = 1;
33 72
34 if (obj && obj->init ()) 73 if (obj && obj->init ())
35 { 74 {
36 push_back (obj); 75 this->push_back (obj);
37 return obj; 76 return obj;
38 } 77 }
39 else 78 else
40 { 79 {
41 delete obj; 80 delete obj;
49 if (!obj) 88 if (!obj)
50 return; 89 return;
51 90
52 if (!--obj->referenced) 91 if (!--obj->referenced)
53 { 92 {
54 erase (find (begin (), end (), obj)); 93 this->erase (find (this->begin (), this->end (), obj));
55 delete obj; 94 delete obj;
56 } 95 }
57} 96}
58 97
59template<class T> 98template<class T>
60refcache<T>::~refcache () 99refcache<T>::~refcache ()
61{ 100{
62 while (size ()) 101 while (this->size ())
63 put (*begin ()); 102 put (*this->begin ());
64} 103}
65 104
66///////////////////////////////////////////////////////////////////////////// 105/////////////////////////////////////////////////////////////////////////////
67 106
107#ifdef USE_XIM
68static void 108static void
69im_destroy_cb (XIM unused1, XPointer client_data, XPointer unused3) 109im_destroy_cb (XIM unused1, XPointer client_data, XPointer unused3)
70{ 110{
71 rxvt_xim *xim = (rxvt_xim *)client_data; 111 rxvt_xim *xim = (rxvt_xim *)client_data;
72 rxvt_display *display = xim->display; 112 rxvt_display *display = xim->display;
87 127
88 XIMCallback ximcallback; 128 XIMCallback ximcallback;
89 ximcallback.client_data = (XPointer)this; 129 ximcallback.client_data = (XPointer)this;
90 ximcallback.callback = im_destroy_cb; 130 ximcallback.callback = im_destroy_cb;
91 131
132 ((void (*)(XIM, ...)) XSetIMValues)
92 XSetIMValues (xim, XNDestroyCallback, &ximcallback, NULL); 133 (xim, XNDestroyCallback, &ximcallback, NULL);
93 134
94 return true; 135 return true;
95} 136}
96 137
97rxvt_xim::~rxvt_xim () 138rxvt_xim::~rxvt_xim ()
98{ 139{
99 if (xim) 140 if (xim)
100 XCloseIM (xim); 141 XCloseIM (xim);
101} 142}
143#endif
102 144
103///////////////////////////////////////////////////////////////////////////// 145/////////////////////////////////////////////////////////////////////////////
104 146
105rxvt_display::rxvt_display (const char *id) 147rxvt_display::rxvt_display (const char *id)
106: refcounted (id) 148: refcounted (id)
110} 152}
111 153
112bool rxvt_display::init () 154bool rxvt_display::init ()
113{ 155{
114 display = XOpenDisplay (id); 156 display = XOpenDisplay (id);
157
158 if (!display)
159 return false;
115 160
116 screen = DefaultScreen (display); 161 screen = DefaultScreen (display);
117 root = DefaultRootWindow (display); 162 root = DefaultRootWindow (display);
118 visual = DefaultVisual (display, screen); 163 visual = DefaultVisual (display, screen);
119 cmap = DefaultColormap (display, screen); 164 cmap = DefaultColormap (display, screen);
138 } 183 }
139#endif 184#endif
140 185
141 int fd = XConnectionNumber (display); 186 int fd = XConnectionNumber (display);
142 x_ev.start (fd, EVENT_READ); 187 x_ev.start (fd, EVENT_READ);
143 fcntl (fd, F_SETFL, FD_CLOEXEC); 188 fcntl (fd, F_SETFD, FD_CLOEXEC);
144 189
145 XSelectInput (display, root, PropertyChangeMask); 190 XSelectInput (display, root, PropertyChangeMask);
191#ifdef USE_XIM
146 xa_xim_servers = XInternAtom (display, "XIM_SERVERS", 0); 192 xa_xim_servers = XInternAtom (display, "XIM_SERVERS", 0);
193#endif
147 194
148 flush (); 195 flush ();
149 196
150 return true; 197 return true;
151} 198}
152 199
153rxvt_display::~rxvt_display () 200rxvt_display::~rxvt_display ()
154{ 201{
155 x_ev.stop (); 202 x_ev.stop ();
156 203
204 if (display)
157 XCloseDisplay (display); 205 XCloseDisplay (display);
158} 206}
159 207
208#ifdef USE_XIM
160void rxvt_display::im_change_cb () 209void rxvt_display::im_change_cb ()
161{ 210{
162 for (im_watcher **i = imw.begin (); i != imw.end (); ++i) 211 for (im_watcher **i = imw.begin (); i != imw.end (); ++i)
163 (*i)->call (); 212 (*i)->call ();
164} 213}
214#endif
165 215
166void rxvt_display::x_cb (io_watcher &w, short revents) 216void rxvt_display::x_cb (io_watcher &w, short revents)
167{ 217{
168 do 218 do
169 { 219 {
170 XEvent xev; 220 XEvent xev;
171 XNextEvent (display, &xev); 221 XNextEvent (display, &xev);
172 222
173 //printf ("T %d w %lx\n", xev.type, xev.xany.window);//D 223 //printf ("T %d w %lx\n", xev.type, xev.xany.window);//D
174 224
225#ifdef USE_XIM
175 if (xev.type == PropertyNotify 226 if (xev.type == PropertyNotify
176 && xev.xany.window == root 227 && xev.xany.window == root
177 && xev.xproperty.atom == xa_xim_servers) 228 && xev.xproperty.atom == xa_xim_servers)
178 im_change_cb (); 229 im_change_cb ();
230#endif
179 231
180 for (int i = xw.size (); i--; ) 232 for (int i = xw.size (); i--; )
181 { 233 {
182 if (!xw[i]) 234 if (!xw[i])
183 xw.erase_unordered (i); 235 xw.erase_unordered (i);
213{ 265{
214 if (w->active) 266 if (w->active)
215 xw[w->active - 1] = 0; 267 xw[w->active - 1] = 0;
216} 268}
217 269
218void rxvt_display::reg (im_watcher *w)
219{
220 imw.push_back (w);
221}
222
223void rxvt_display::unreg (im_watcher *w)
224{
225 imw.erase (find (imw.begin (), imw.end (), w));
226}
227
228void rxvt_display::set_selection_owner (rxvt_term *owner) 270void rxvt_display::set_selection_owner (rxvt_term *owner)
229{ 271{
230 if (selection_owner && selection_owner != owner) 272 if (selection_owner && selection_owner != owner)
231 selection_owner->selection_clear (); 273 selection_owner->selection_clear ();
232 274
233 selection_owner = owner; 275 selection_owner = owner;
234} 276}
235 277
278#ifdef USE_XIM
279void rxvt_display::reg (im_watcher *w)
280{
281 imw.push_back (w);
282}
283
284void rxvt_display::unreg (im_watcher *w)
285{
286 imw.erase (find (imw.begin (), imw.end (), w));
287}
288
236rxvt_xim *rxvt_display::get_xim (const char *locale, const char *modifiers) 289rxvt_xim *rxvt_display::get_xim (const char *locale, const char *modifiers)
237{ 290{
238 // asprintf is a GNU and *BSD extension.. sorry...
239 char *id; 291 char *id;
292 int l, m;
240 293
241 if (asprintf (&id, "%s\n%s", locale, modifiers) < 0) 294 l = strlen (locale);
295 m = strlen (modifiers);
296
297 if (!(id = (char *)malloc (l + m + 2)))
242 return 0; 298 return 0;
243 299
300 memcpy (id, locale, l); id[l] = '\n';
301 memcpy (id + l + 1, modifiers, m); id[l + m + 1] = 0;
302
244 rxvt_xim *xim = xims.get (id); 303 rxvt_xim *xim = xims.get (id);
245 304
246 free (id); 305 free (id);
247 306
248 return xim; 307 return xim;
250 309
251void rxvt_display::put_xim (rxvt_xim *xim) 310void rxvt_display::put_xim (rxvt_xim *xim)
252{ 311{
253 xims.put (xim); 312 xims.put (xim);
254} 313}
314#endif
315
316Atom rxvt_display::atom (const char *name)
317{
318 return XInternAtom (display, name, False);
319}
255 320
256///////////////////////////////////////////////////////////////////////////// 321/////////////////////////////////////////////////////////////////////////////
257 322
258template refcache<rxvt_display>; 323template class refcache<rxvt_display>;
259refcache<rxvt_display> displays; 324refcache<rxvt_display> displays;
260 325
261///////////////////////////////////////////////////////////////////////////// 326/////////////////////////////////////////////////////////////////////////////
262 327
263bool 328bool
339rxvt_color::free (rxvt_display *display) 404rxvt_color::free (rxvt_display *display)
340{ 405{
341#if XFT 406#if XFT
342 XftColorFree (display->display, display->visual, display->cmap, &c); 407 XftColorFree (display->display, display->visual, display->cmap, &c);
343#else 408#else
344 XFreeColors (display->display, display->cmap, &c, 1, AllPlanes); 409 XFreeColors (display->display, display->cmap, &p, 1, AllPlanes);
345#endif 410#endif
346} 411}
347 412

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines