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.9 by pcg, Sun Mar 14 17:33:08 2004 UTC vs.
Revision 1.15 by root, Sun May 30 19:12:42 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
68static void 107static void
141 } 180 }
142#endif 181#endif
143 182
144 int fd = XConnectionNumber (display); 183 int fd = XConnectionNumber (display);
145 x_ev.start (fd, EVENT_READ); 184 x_ev.start (fd, EVENT_READ);
146 fcntl (fd, F_SETFL, FD_CLOEXEC); 185 fcntl (fd, F_SETFD, FD_CLOEXEC);
147 186
148 XSelectInput (display, root, PropertyChangeMask); 187 XSelectInput (display, root, PropertyChangeMask);
149 xa_xim_servers = XInternAtom (display, "XIM_SERVERS", 0); 188 xa_xim_servers = XInternAtom (display, "XIM_SERVERS", 0);
150 189
151 flush (); 190 flush ();
237 selection_owner = owner; 276 selection_owner = owner;
238} 277}
239 278
240rxvt_xim *rxvt_display::get_xim (const char *locale, const char *modifiers) 279rxvt_xim *rxvt_display::get_xim (const char *locale, const char *modifiers)
241{ 280{
242 // asprintf is a GNU and *BSD extension.. sorry...
243 char *id; 281 char *id;
282 int l, m;
244 283
245 if (asprintf (&id, "%s\n%s", locale, modifiers) < 0) 284 l = strlen (locale);
285 m = strlen (modifiers);
286
287 if (!(id = (char *)malloc (l + m + 2)))
246 return 0; 288 return 0;
247 289
290 memcpy (id, locale, l); id[l] = '\n';
291 memcpy (id + l + 1, modifiers, m); id[l + m + 1] = 0;
292
248 rxvt_xim *xim = xims.get (id); 293 rxvt_xim *xim = xims.get (id);
249 294
250 free (id); 295 free (id);
251 296
252 return xim; 297 return xim;
255void rxvt_display::put_xim (rxvt_xim *xim) 300void rxvt_display::put_xim (rxvt_xim *xim)
256{ 301{
257 xims.put (xim); 302 xims.put (xim);
258} 303}
259 304
305Atom rxvt_display::atom (const char *name)
306{
307 return XInternAtom (display, name, False);
308}
309
260///////////////////////////////////////////////////////////////////////////// 310/////////////////////////////////////////////////////////////////////////////
261 311
262template refcache<rxvt_display>; 312template class refcache<rxvt_display>;
263refcache<rxvt_display> displays; 313refcache<rxvt_display> displays;
264 314
265///////////////////////////////////////////////////////////////////////////// 315/////////////////////////////////////////////////////////////////////////////
266 316
267bool 317bool

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines