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.12 by pcg, Fri Apr 2 20:41:01 2004 UTC vs.
Revision 1.16 by root, Thu Jul 29 14:05:27 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>
33} 55}
34 56
35template<class T> 57template<class T>
36T *refcache<T>::get (const char *id) 58T *refcache<T>::get (const char *id)
37{ 59{
38 for (T **i = begin (); i < end (); ++i) 60 for (T **i = this->begin (); i < this->end (); ++i)
39 { 61 {
40 if (!strcmp (id, (*i)->id)) 62 if (!strcmp (id, (*i)->id))
41 { 63 {
42 (*i)->referenced++; 64 (*i)->referenced++;
43 return *i; 65 return *i;
48 70
49 obj->referenced = 1; 71 obj->referenced = 1;
50 72
51 if (obj && obj->init ()) 73 if (obj && obj->init ())
52 { 74 {
53 push_back (obj); 75 this->push_back (obj);
54 return obj; 76 return obj;
55 } 77 }
56 else 78 else
57 { 79 {
58 delete obj; 80 delete obj;
66 if (!obj) 88 if (!obj)
67 return; 89 return;
68 90
69 if (!--obj->referenced) 91 if (!--obj->referenced)
70 { 92 {
71 erase (find (begin (), end (), obj)); 93 this->erase (find (this->begin (), this->end (), obj));
72 delete obj; 94 delete obj;
73 } 95 }
74} 96}
75 97
76template<class T> 98template<class T>
77refcache<T>::~refcache () 99refcache<T>::~refcache ()
78{ 100{
79 while (size ()) 101 while (this->size ())
80 put (*begin ()); 102 put (*this->begin ());
81} 103}
82 104
83///////////////////////////////////////////////////////////////////////////// 105/////////////////////////////////////////////////////////////////////////////
84 106
107#ifdef USE_XIM
85static void 108static void
86im_destroy_cb (XIM unused1, XPointer client_data, XPointer unused3) 109im_destroy_cb (XIM unused1, XPointer client_data, XPointer unused3)
87{ 110{
88 rxvt_xim *xim = (rxvt_xim *)client_data; 111 rxvt_xim *xim = (rxvt_xim *)client_data;
89 rxvt_display *display = xim->display; 112 rxvt_display *display = xim->display;
114rxvt_xim::~rxvt_xim () 137rxvt_xim::~rxvt_xim ()
115{ 138{
116 if (xim) 139 if (xim)
117 XCloseIM (xim); 140 XCloseIM (xim);
118} 141}
142#endif
119 143
120///////////////////////////////////////////////////////////////////////////// 144/////////////////////////////////////////////////////////////////////////////
121 145
122rxvt_display::rxvt_display (const char *id) 146rxvt_display::rxvt_display (const char *id)
123: refcounted (id) 147: refcounted (id)
158 } 182 }
159#endif 183#endif
160 184
161 int fd = XConnectionNumber (display); 185 int fd = XConnectionNumber (display);
162 x_ev.start (fd, EVENT_READ); 186 x_ev.start (fd, EVENT_READ);
163 fcntl (fd, F_SETFL, FD_CLOEXEC); 187 fcntl (fd, F_SETFD, FD_CLOEXEC);
164 188
165 XSelectInput (display, root, PropertyChangeMask); 189 XSelectInput (display, root, PropertyChangeMask);
190#ifdef USE_XIM
166 xa_xim_servers = XInternAtom (display, "XIM_SERVERS", 0); 191 xa_xim_servers = XInternAtom (display, "XIM_SERVERS", 0);
192#endif
167 193
168 flush (); 194 flush ();
169 195
170 return true; 196 return true;
171} 197}
176 202
177 if (display) 203 if (display)
178 XCloseDisplay (display); 204 XCloseDisplay (display);
179} 205}
180 206
207#ifdef USE_XIM
181void rxvt_display::im_change_cb () 208void rxvt_display::im_change_cb ()
182{ 209{
183 for (im_watcher **i = imw.begin (); i != imw.end (); ++i) 210 for (im_watcher **i = imw.begin (); i != imw.end (); ++i)
184 (*i)->call (); 211 (*i)->call ();
185} 212}
213#endif
186 214
187void rxvt_display::x_cb (io_watcher &w, short revents) 215void rxvt_display::x_cb (io_watcher &w, short revents)
188{ 216{
189 do 217 do
190 { 218 {
191 XEvent xev; 219 XEvent xev;
192 XNextEvent (display, &xev); 220 XNextEvent (display, &xev);
193 221
194 //printf ("T %d w %lx\n", xev.type, xev.xany.window);//D 222 //printf ("T %d w %lx\n", xev.type, xev.xany.window);//D
195 223
224#ifdef USE_XIM
196 if (xev.type == PropertyNotify 225 if (xev.type == PropertyNotify
197 && xev.xany.window == root 226 && xev.xany.window == root
198 && xev.xproperty.atom == xa_xim_servers) 227 && xev.xproperty.atom == xa_xim_servers)
199 im_change_cb (); 228 im_change_cb ();
229#endif
200 230
201 for (int i = xw.size (); i--; ) 231 for (int i = xw.size (); i--; )
202 { 232 {
203 if (!xw[i]) 233 if (!xw[i])
204 xw.erase_unordered (i); 234 xw.erase_unordered (i);
234{ 264{
235 if (w->active) 265 if (w->active)
236 xw[w->active - 1] = 0; 266 xw[w->active - 1] = 0;
237} 267}
238 268
239void rxvt_display::reg (im_watcher *w)
240{
241 imw.push_back (w);
242}
243
244void rxvt_display::unreg (im_watcher *w)
245{
246 imw.erase (find (imw.begin (), imw.end (), w));
247}
248
249void rxvt_display::set_selection_owner (rxvt_term *owner) 269void rxvt_display::set_selection_owner (rxvt_term *owner)
250{ 270{
251 if (selection_owner && selection_owner != owner) 271 if (selection_owner && selection_owner != owner)
252 selection_owner->selection_clear (); 272 selection_owner->selection_clear ();
253 273
254 selection_owner = owner; 274 selection_owner = owner;
255} 275}
256 276
277#ifdef USE_XIM
278void rxvt_display::reg (im_watcher *w)
279{
280 imw.push_back (w);
281}
282
283void rxvt_display::unreg (im_watcher *w)
284{
285 imw.erase (find (imw.begin (), imw.end (), w));
286}
287
257rxvt_xim *rxvt_display::get_xim (const char *locale, const char *modifiers) 288rxvt_xim *rxvt_display::get_xim (const char *locale, const char *modifiers)
258{ 289{
259 char *id; 290 char *id;
260 int l, m; 291 int l, m;
261 292
277 308
278void rxvt_display::put_xim (rxvt_xim *xim) 309void rxvt_display::put_xim (rxvt_xim *xim)
279{ 310{
280 xims.put (xim); 311 xims.put (xim);
281} 312}
313#endif
282 314
283Atom rxvt_display::atom (const char *name) 315Atom rxvt_display::atom (const char *name)
284{ 316{
285 return XInternAtom (display, name, False); 317 return XInternAtom (display, name, False);
286} 318}
287 319
288///////////////////////////////////////////////////////////////////////////// 320/////////////////////////////////////////////////////////////////////////////
289 321
290template refcache<rxvt_display>; 322template class refcache<rxvt_display>;
291refcache<rxvt_display> displays; 323refcache<rxvt_display> displays;
292 324
293///////////////////////////////////////////////////////////////////////////// 325/////////////////////////////////////////////////////////////////////////////
294 326
295bool 327bool

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines