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.13 by pcg, Sun Apr 4 23:47:29 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>
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;
104 127
105 XIMCallback ximcallback; 128 XIMCallback ximcallback;
106 ximcallback.client_data = (XPointer)this; 129 ximcallback.client_data = (XPointer)this;
107 ximcallback.callback = im_destroy_cb; 130 ximcallback.callback = im_destroy_cb;
108 131
132 ((void (*)(XIM, ...)) XSetIMValues)
109 XSetIMValues (xim, XNDestroyCallback, &ximcallback, NULL); 133 (xim, XNDestroyCallback, &ximcallback, NULL);
110 134
111 return true; 135 return true;
112} 136}
113 137
114rxvt_xim::~rxvt_xim () 138rxvt_xim::~rxvt_xim ()
115{ 139{
116 if (xim) 140 if (xim)
117 XCloseIM (xim); 141 XCloseIM (xim);
118} 142}
143#endif
119 144
120///////////////////////////////////////////////////////////////////////////// 145/////////////////////////////////////////////////////////////////////////////
121 146
122rxvt_display::rxvt_display (const char *id) 147rxvt_display::rxvt_display (const char *id)
123: refcounted (id) 148: refcounted (id)
161 int fd = XConnectionNumber (display); 186 int fd = XConnectionNumber (display);
162 x_ev.start (fd, EVENT_READ); 187 x_ev.start (fd, EVENT_READ);
163 fcntl (fd, F_SETFD, FD_CLOEXEC); 188 fcntl (fd, F_SETFD, FD_CLOEXEC);
164 189
165 XSelectInput (display, root, PropertyChangeMask); 190 XSelectInput (display, root, PropertyChangeMask);
191#ifdef USE_XIM
166 xa_xim_servers = XInternAtom (display, "XIM_SERVERS", 0); 192 xa_xim_servers = XInternAtom (display, "XIM_SERVERS", 0);
193#endif
167 194
168 flush (); 195 flush ();
169 196
170 return true; 197 return true;
171} 198}
176 203
177 if (display) 204 if (display)
178 XCloseDisplay (display); 205 XCloseDisplay (display);
179} 206}
180 207
208#ifdef USE_XIM
181void rxvt_display::im_change_cb () 209void rxvt_display::im_change_cb ()
182{ 210{
183 for (im_watcher **i = imw.begin (); i != imw.end (); ++i) 211 for (im_watcher **i = imw.begin (); i != imw.end (); ++i)
184 (*i)->call (); 212 (*i)->call ();
185} 213}
214#endif
186 215
187void rxvt_display::x_cb (io_watcher &w, short revents) 216void rxvt_display::x_cb (io_watcher &w, short revents)
188{ 217{
189 do 218 do
190 { 219 {
191 XEvent xev; 220 XEvent xev;
192 XNextEvent (display, &xev); 221 XNextEvent (display, &xev);
193 222
194 //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
195 224
225#ifdef USE_XIM
196 if (xev.type == PropertyNotify 226 if (xev.type == PropertyNotify
197 && xev.xany.window == root 227 && xev.xany.window == root
198 && xev.xproperty.atom == xa_xim_servers) 228 && xev.xproperty.atom == xa_xim_servers)
199 im_change_cb (); 229 im_change_cb ();
230#endif
200 231
201 for (int i = xw.size (); i--; ) 232 for (int i = xw.size (); i--; )
202 { 233 {
203 if (!xw[i]) 234 if (!xw[i])
204 xw.erase_unordered (i); 235 xw.erase_unordered (i);
234{ 265{
235 if (w->active) 266 if (w->active)
236 xw[w->active - 1] = 0; 267 xw[w->active - 1] = 0;
237} 268}
238 269
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) 270void rxvt_display::set_selection_owner (rxvt_term *owner)
250{ 271{
251 if (selection_owner && selection_owner != owner) 272 if (selection_owner && selection_owner != owner)
252 selection_owner->selection_clear (); 273 selection_owner->selection_clear ();
253 274
254 selection_owner = owner; 275 selection_owner = owner;
255} 276}
256 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
257rxvt_xim *rxvt_display::get_xim (const char *locale, const char *modifiers) 289rxvt_xim *rxvt_display::get_xim (const char *locale, const char *modifiers)
258{ 290{
259 char *id; 291 char *id;
260 int l, m; 292 int l, m;
261 293
277 309
278void rxvt_display::put_xim (rxvt_xim *xim) 310void rxvt_display::put_xim (rxvt_xim *xim)
279{ 311{
280 xims.put (xim); 312 xims.put (xim);
281} 313}
314#endif
282 315
283Atom rxvt_display::atom (const char *name) 316Atom rxvt_display::atom (const char *name)
284{ 317{
285 return XInternAtom (display, name, False); 318 return XInternAtom (display, name, False);
286} 319}
287 320
288///////////////////////////////////////////////////////////////////////////// 321/////////////////////////////////////////////////////////////////////////////
289 322
290template refcache<rxvt_display>; 323template class refcache<rxvt_display>;
291refcache<rxvt_display> displays; 324refcache<rxvt_display> displays;
292 325
293///////////////////////////////////////////////////////////////////////////// 326/////////////////////////////////////////////////////////////////////////////
294 327
295bool 328bool

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines