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

Comparing rxvt-unicode/src/rxvttoolkit.h (file contents):
Revision 1.35 by sasha, Wed Nov 14 22:25:42 2007 UTC vs.
Revision 1.45 by root, Sat Jan 26 11:37:51 2008 UTC

29# include <X11/Xft/Xft.h> 29# include <X11/Xft/Xft.h>
30#endif 30#endif
31 31
32#include "ev_cpp.h" 32#include "ev_cpp.h"
33 33
34#include "rxvtlib.h"
35#include "rxvtutil.h" 34#include "rxvtutil.h"
36 35
37#include "callback.h" 36#include "callback.h"
38 37
39// see rxvttoolkit.C:xa_names, which must be kept in sync 38// see rxvttoolkit.C:xa_names, which must be kept in sync
74#if ENABLE_XEMBED 73#if ENABLE_XEMBED
75 XA_XEMBED, 74 XA_XEMBED,
76 XA_XEMBED_INFO, 75 XA_XEMBED_INFO,
77#endif 76#endif
78#if !ENABLE_MINIMAL 77#if !ENABLE_MINIMAL
79 // these are usually allocated by other subsystens, but we do it 78 // these are usually allocated by other subsystems, but we do it
80 // here to avoid a server roundtrip. 79 // here to avoid a server roundtrip.
81 XA_SCREEN_RESOURCES, 80 XA_SCREEN_RESOURCES,
82 XA_XDCCC_LINEAR_RGB_CORRECTION, 81 XA_XDCCC_LINEAR_RGB_CORRECTION,
83 XA_XDCCC_LINEAR_RGB_MATRICES, 82 XA_XDCCC_LINEAR_RGB_MATRICES,
84 XA_WM_COLORMAP_WINDOWS, 83 XA_WM_COLORMAP_WINDOWS,
101 100
102struct im_watcher; 101struct im_watcher;
103struct xevent_watcher; 102struct xevent_watcher;
104 103
105template<class watcher> 104template<class watcher>
106struct event_vec : vector<watcher *> { 105struct event_vec : vector<watcher *>
106{
107 void erase_unordered (unsigned int pos) 107 void erase_unordered (unsigned int pos)
108 { 108 {
109 watcher *w = (*this)[this->size () - 1]; 109 watcher *w = (*this)[this->size () - 1];
110 this->pop_back (); 110 this->pop_back ();
111 111
113 if (((*this)[pos] = w)) // '=' is correct! 113 if (((*this)[pos] = w)) // '=' is correct!
114 w->active = pos + 1; 114 w->active = pos + 1;
115 } 115 }
116}; 116};
117 117
118struct rxvt_watcher { 118struct rxvt_watcher
119{
119 int active; /* 0 == inactive, else index into respective vector */ 120 int active; /* 0 == inactive, else index into respective vector */
120 121
121 bool is_active () { return active; } 122 bool is_active () { return active; }
122 123
123 rxvt_watcher () : active (0) { } 124 rxvt_watcher () : active (0) { }
124}; 125};
125 126
126struct refcounted { 127struct refcounted
128{
127 int referenced; 129 int referenced;
128 char *id; 130 char *id;
129 131
130 refcounted (const char *id); 132 refcounted (const char *id);
131 bool ref_init () { return false; } 133 bool ref_init () { return false; }
132 void ref_next () { } 134 void ref_next () { }
133 ~refcounted (); 135 ~refcounted ();
134}; 136};
135 137
136template<class T> 138template<class T>
137struct refcache : vector<T *> { 139struct refcache : vector<T *>
140{
138 T *get (const char *id); 141 T *get (const char *id);
139 void put (T *obj); 142 void put (T *obj);
140 void clear (); 143 void clear ();
141 144
142 ~refcache () 145 ~refcache ()
147 150
148///////////////////////////////////////////////////////////////////////////// 151/////////////////////////////////////////////////////////////////////////////
149 152
150struct rxvt_screen; 153struct rxvt_screen;
151 154
152struct rxvt_drawable { 155struct rxvt_drawable
156{
153 rxvt_screen *screen; 157 rxvt_screen *screen;
154 Drawable drawable; 158 Drawable drawable;
155 operator Drawable() { return drawable; } 159 operator Drawable() { return drawable; }
156 160
157#if XFT 161#if XFT
173}; 177};
174 178
175///////////////////////////////////////////////////////////////////////////// 179/////////////////////////////////////////////////////////////////////////////
176 180
177#ifdef USE_XIM 181#ifdef USE_XIM
178struct rxvt_xim : refcounted { 182struct rxvt_xim : refcounted
183{
179 void destroy (); 184 void destroy ();
180 rxvt_display *display; 185 rxvt_display *display;
181 186
182//public 187//public
183 XIM xim; 188 XIM xim;
186 bool ref_init (); 191 bool ref_init ();
187 ~rxvt_xim (); 192 ~rxvt_xim ();
188}; 193};
189#endif 194#endif
190 195
191struct rxvt_screen { 196struct rxvt_screen
197{
192 rxvt_display *display; 198 rxvt_display *display;
193 Display *dpy; 199 Display *dpy;
194 int depth; 200 int depth;
195 Visual *visual; 201 Visual *visual;
196 Colormap cmap; 202 Colormap cmap;
208 void set (rxvt_display *disp); 214 void set (rxvt_display *disp);
209 void select_visual (int bitdepth); 215 void select_visual (int bitdepth);
210 void clear (); 216 void clear ();
211}; 217};
212 218
213struct rxvt_display : refcounted { 219struct rxvt_display : refcounted
220{
214 event_vec<xevent_watcher> xw; 221 event_vec<xevent_watcher> xw;
215 222
223 ev::prepare flush_ev; void flush_cb (ev::prepare &w, int revents);
216 ev::io x_ev; void x_cb (ev::io &w, int revents); 224 ev::io x_ev ; void x_cb (ev::io &w, int revents);
217 225
218#ifdef USE_XIM 226#ifdef USE_XIM
219 refcache<rxvt_xim> xims; 227 refcache<rxvt_xim> xims;
220 vector<im_watcher *> imw; 228 vector<im_watcher *> imw;
221 229
238 XrmDatabase get_resources (bool refresh); 246 XrmDatabase get_resources (bool refresh);
239 bool ref_init (); 247 bool ref_init ();
240 void ref_next (); 248 void ref_next ();
241 ~rxvt_display (); 249 ~rxvt_display ();
242 250
243 void flush (); 251 void flush ()
252 {
253 flush_ev.start ();
254 }
255
244 Atom atom (const char *name); 256 Atom atom (const char *name);
245 void set_selection_owner (rxvt_term *owner); 257 void set_selection_owner (rxvt_term *owner);
246 258
247 void reg (xevent_watcher *w); 259 void reg (xevent_watcher *w);
248 void unreg (xevent_watcher *w); 260 void unreg (xevent_watcher *w);
256#endif 268#endif
257}; 269};
258 270
259#ifdef USE_XIM 271#ifdef USE_XIM
260struct im_watcher : rxvt_watcher, callback<void (void)> { 272struct im_watcher : rxvt_watcher, callback<void (void)> {
261 template<class O, class M>
262 im_watcher (O object, M method)
263 : callback<void (void)> (object, method)
264 { }
265
266 void start (rxvt_display *display) 273 void start (rxvt_display *display)
267 { 274 {
268 display->reg (this); 275 display->reg (this);
269 } 276 }
270 277
273 display->unreg (this); 280 display->unreg (this);
274 } 281 }
275}; 282};
276#endif 283#endif
277 284
278struct xevent_watcher : rxvt_watcher, callback<void (XEvent &)> { 285struct xevent_watcher : rxvt_watcher, callback<void (XEvent &)>
286{
279 Window window; 287 Window window;
280
281 template<class O, class M>
282 xevent_watcher (O object, M method)
283 : callback<void (XEvent &)> (object, method)
284 { }
285 288
286 void start (rxvt_display *display, Window window) 289 void start (rxvt_display *display, Window window)
287 { 290 {
288 this->window = window; 291 this->window = window;
289 display->reg (this); 292 display->reg (this);
299 302
300///////////////////////////////////////////////////////////////////////////// 303/////////////////////////////////////////////////////////////////////////////
301 304
302typedef unsigned long Pixel; 305typedef unsigned long Pixel;
303 306
304struct rgba { 307struct rgba
308{
305 unsigned short r, g, b, a; 309 unsigned short r, g, b, a;
306 310
307 enum { MIN_CC = 0x0000, MAX_CC = 0xffff }; 311 enum { MIN_CC = 0x0000, MAX_CC = 0xffff };
308 312
309 rgba () 313 rgba ()
312 rgba (unsigned short r, unsigned short g, unsigned short b, unsigned short a = MAX_CC) 316 rgba (unsigned short r, unsigned short g, unsigned short b, unsigned short a = MAX_CC)
313 : r(r), g(g), b(b), a(a) 317 : r(r), g(g), b(b), a(a)
314 { } 318 { }
315}; 319};
316 320
317struct rxvt_color { 321struct rxvt_color
322{
318#if XFT 323#if XFT
319 XftColor c; 324 XftColor c;
320#else 325#else
321 XColor c; 326 XColor c;
322#endif 327#endif
324 operator Pixel () const { return c.pixel; } 329 operator Pixel () const { return c.pixel; }
325 330
326 bool operator == (const rxvt_color &b) const { return Pixel (*this) == Pixel (b); } 331 bool operator == (const rxvt_color &b) const { return Pixel (*this) == Pixel (b); }
327 bool operator != (const rxvt_color &b) const { return Pixel (*this) != Pixel (b); } 332 bool operator != (const rxvt_color &b) const { return Pixel (*this) != Pixel (b); }
328 333
334 bool is_opaque () const
335 {
336#if XFT
337 return c.color.alpha == rgba::MAX_CC;
338#else
339 return 1;
340#endif
341 }
342
329 bool alloc (rxvt_screen *screen, const rgba &color); 343 bool alloc (rxvt_screen *screen, const rgba &color);
330 void free (rxvt_screen *screen); 344 void free (rxvt_screen *screen);
331 345
332 void get (rgba &color); 346 void get (rgba &color);
333 void get (XColor &color); 347 void get (XColor &color);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines