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.26 by root, Mon Feb 20 22:40:35 2006 UTC vs.
Revision 1.47 by root, Wed Nov 5 14:43:54 2008 UTC

1/*--------------------------------*-C-*---------------------------------* 1/*----------------------------------------------------------------------*
2 * File: rxvttoolkit.h - provide toolkit-functionality for rxvt. 2 * File: rxvttoolkit.h - provide toolkit-functionality for rxvt.
3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
4 * 4 *
5 * All portions of code are copyright by their respective author/s. 5 * All portions of code are copyright by their respective author/s.
6 * Copyright (c) 2003-2006 Marc Lehmann <pcg@goof.com> 6 * Copyright (c) 2003-2006 Marc Lehmann <pcg@goof.com>
27 27
28#if XFT 28#if XFT
29# include <X11/Xft/Xft.h> 29# include <X11/Xft/Xft.h>
30#endif 30#endif
31 31
32#include "iom.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
60#if ENABLE_EWMH 59#if ENABLE_EWMH
61 XA_NET_WM_PID, 60 XA_NET_WM_PID,
62 XA_NET_WM_NAME, 61 XA_NET_WM_NAME,
63 XA_NET_WM_ICON_NAME, 62 XA_NET_WM_ICON_NAME,
64 XA_NET_WM_PING, 63 XA_NET_WM_PING,
64 XA_NET_WM_ICON,
65#endif 65#endif
66#if USE_XIM 66#if USE_XIM
67 XA_WM_LOCALE_NAME, 67 XA_WM_LOCALE_NAME,
68 XA_XIM_SERVERS, 68 XA_XIM_SERVERS,
69#endif 69#endif
70#if TRANSPARENT 70#if ENABLE_TRANSPARENCY
71 XA_XROOTPMAP_ID, 71 XA_XROOTPMAP_ID,
72 XA_ESETROOT_PMAP_ID, 72 XA_ESETROOT_PMAP_ID,
73#endif 73#endif
74#if ENABLE_XEMBED 74#if ENABLE_XEMBED
75 XA_XEMBED, 75 XA_XEMBED,
76 XA_XEMBED_INFO, 76 XA_XEMBED_INFO,
77#endif 77#endif
78#if !ENABLE_MINIMAL 78#if !ENABLE_MINIMAL
79 // these are usually allocated by other subsystens, but we do it 79 // these are usually allocated by other subsystems, but we do it
80 // here to avoid a server roundtrip. 80 // here to avoid a server roundtrip.
81 XA_SCREEN_RESOURCES, 81 XA_SCREEN_RESOURCES,
82 XA_XDCCC_LINEAR_RGB_CORRECTION, 82 XA_XDCCC_LINEAR_RGB_CORRECTION,
83 XA_XDCCC_LINEAR_RGB_MATRICES, 83 XA_XDCCC_LINEAR_RGB_MATRICES,
84 XA_WM_COLORMAP_WINDOWS, 84 XA_WM_COLORMAP_WINDOWS,
100struct rxvt_display; 100struct rxvt_display;
101 101
102struct im_watcher; 102struct im_watcher;
103struct xevent_watcher; 103struct xevent_watcher;
104 104
105template<class watcher>
106struct event_vec : vector<watcher *>
107{
108 void erase_unordered (unsigned int pos)
109 {
110 watcher *w = (*this)[this->size () - 1];
111 this->pop_back ();
112
113 if (!this->empty ())
114 if (((*this)[pos] = w)) // '=' is correct!
115 w->active = pos + 1;
116 }
117};
118
119struct rxvt_watcher
120{
121 int active; /* 0 == inactive, else index into respective vector */
122
123 bool is_active () { return active; }
124
125 rxvt_watcher () : active (0) { }
126};
127
105struct refcounted { 128struct refcounted
129{
106 int referenced; 130 int referenced;
107 char *id; 131 char *id;
108 132
109 refcounted (const char *id); 133 refcounted (const char *id);
110 bool ref_init () { return false; } 134 bool ref_init () { return false; }
111 void ref_next () { } 135 void ref_next () { }
112 ~refcounted (); 136 ~refcounted ();
113}; 137};
114 138
115template<class T> 139template<class T>
116struct refcache : vector<T *> { 140struct refcache : vector<T *>
141{
117 T *get (const char *id); 142 T *get (const char *id);
118 void put (T *obj); 143 void put (T *obj);
119 void clear (); 144 void clear ();
120 145
121 ~refcache () 146 ~refcache ()
126 151
127///////////////////////////////////////////////////////////////////////////// 152/////////////////////////////////////////////////////////////////////////////
128 153
129struct rxvt_screen; 154struct rxvt_screen;
130 155
131struct rxvt_drawable { 156struct rxvt_drawable
157{
132 rxvt_screen *screen; 158 rxvt_screen *screen;
133 Drawable drawable; 159 Drawable drawable;
134 operator Drawable() { return drawable; } 160 operator Drawable() { return drawable; }
135 161
136#if XFT 162#if XFT
152}; 178};
153 179
154///////////////////////////////////////////////////////////////////////////// 180/////////////////////////////////////////////////////////////////////////////
155 181
156#ifdef USE_XIM 182#ifdef USE_XIM
157struct rxvt_xim : refcounted { 183struct rxvt_xim : refcounted
184{
158 void destroy (); 185 void destroy ();
159 rxvt_display *display; 186 rxvt_display *display;
160 187
161//public 188//public
162 XIM xim; 189 XIM xim;
165 bool ref_init (); 192 bool ref_init ();
166 ~rxvt_xim (); 193 ~rxvt_xim ();
167}; 194};
168#endif 195#endif
169 196
170struct rxvt_screen { 197struct rxvt_screen
198{
171 rxvt_display *display; 199 rxvt_display *display;
172 Display *dpy; 200 Display *dpy;
173 int depth; 201 int depth;
174 Visual *visual; 202 Visual *visual;
175 Colormap cmap; 203 Colormap cmap;
183 211
184 rxvt_screen (); 212 rxvt_screen ();
185#endif 213#endif
186 214
187 void set (rxvt_display *disp); 215 void set (rxvt_display *disp);
188 void set (rxvt_display *disp, int bitdepth); 216 void select_visual (int bitdepth);
189 void clear (); 217 void clear ();
190}; 218};
191 219
192struct rxvt_display : refcounted { 220struct rxvt_display : refcounted
221{
193 io_manager_vec<xevent_watcher> xw; 222 event_vec<xevent_watcher> xw;
194 223
195 io_watcher x_ev; void x_cb (io_watcher &w, short revents); 224 ev::prepare flush_ev; void flush_cb (ev::prepare &w, int revents);
225 ev::io x_ev ; void x_cb (ev::io &w, int revents);
196 226
197#ifdef USE_XIM 227#ifdef USE_XIM
198 refcache<rxvt_xim> xims; 228 refcache<rxvt_xim> xims;
199 vector<im_watcher *> imw; 229 vector<im_watcher *> imw;
200 230
217 XrmDatabase get_resources (bool refresh); 247 XrmDatabase get_resources (bool refresh);
218 bool ref_init (); 248 bool ref_init ();
219 void ref_next (); 249 void ref_next ();
220 ~rxvt_display (); 250 ~rxvt_display ();
221 251
222 void flush (); 252 void flush ()
253 {
254 flush_ev.start ();
255 }
256
223 Atom atom (const char *name); 257 Atom atom (const char *name);
224 void set_selection_owner (rxvt_term *owner); 258 void set_selection_owner (rxvt_term *owner);
225 259
226 void reg (xevent_watcher *w); 260 void reg (xevent_watcher *w);
227 void unreg (xevent_watcher *w); 261 void unreg (xevent_watcher *w);
234 void put_xim (rxvt_xim *xim); 268 void put_xim (rxvt_xim *xim);
235#endif 269#endif
236}; 270};
237 271
238#ifdef USE_XIM 272#ifdef USE_XIM
239struct im_watcher : watcher, callback0<void> { 273struct im_watcher : rxvt_watcher, callback<void (void)>
240 template<class O1, class O2> 274{
241 im_watcher (O1 *object, void (O2::*method) ())
242 : callback0<void> (object,method)
243 { }
244
245 void start (rxvt_display *display) 275 void start (rxvt_display *display)
246 { 276 {
247 display->reg (this); 277 display->reg (this);
248 } 278 }
279
249 void stop (rxvt_display *display) 280 void stop (rxvt_display *display)
250 { 281 {
251 display->unreg (this); 282 display->unreg (this);
252 } 283 }
253}; 284};
254#endif 285#endif
255 286
256struct xevent_watcher : watcher, callback1<void, XEvent &> { 287struct xevent_watcher : rxvt_watcher, callback<void (XEvent &)>
288{
257 Window window; 289 Window window;
258
259 template<class O1, class O2>
260 xevent_watcher (O1 *object, void (O2::*method) (XEvent &))
261 : callback1<void, XEvent &> (object,method)
262 { }
263 290
264 void start (rxvt_display *display, Window window) 291 void start (rxvt_display *display, Window window)
265 { 292 {
266 this->window = window; 293 this->window = window;
267 display->reg (this); 294 display->reg (this);
268 } 295 }
296
269 void stop (rxvt_display *display) 297 void stop (rxvt_display *display)
270 { 298 {
271 display->unreg (this); 299 display->unreg (this);
272 } 300 }
273}; 301};
276 304
277///////////////////////////////////////////////////////////////////////////// 305/////////////////////////////////////////////////////////////////////////////
278 306
279typedef unsigned long Pixel; 307typedef unsigned long Pixel;
280 308
281struct rgba { 309struct rgba
310{
282 unsigned short r, g, b, a; 311 unsigned short r, g, b, a;
283 312
284 enum { MIN_CC = 0x0000, MAX_CC = 0xffff }; 313 enum { MIN_CC = 0x0000, MAX_CC = 0xffff };
285 314
286 rgba () 315 rgba ()
289 rgba (unsigned short r, unsigned short g, unsigned short b, unsigned short a = MAX_CC) 318 rgba (unsigned short r, unsigned short g, unsigned short b, unsigned short a = MAX_CC)
290 : r(r), g(g), b(b), a(a) 319 : r(r), g(g), b(b), a(a)
291 { } 320 { }
292}; 321};
293 322
294struct rxvt_color { 323struct rxvt_color
324{
295#if XFT 325#if XFT
296 XftColor c; 326 XftColor c;
297#else 327#else
298 XColor c; 328 XColor c;
299#endif 329#endif
301 operator Pixel () const { return c.pixel; } 331 operator Pixel () const { return c.pixel; }
302 332
303 bool operator == (const rxvt_color &b) const { return Pixel (*this) == Pixel (b); } 333 bool operator == (const rxvt_color &b) const { return Pixel (*this) == Pixel (b); }
304 bool operator != (const rxvt_color &b) const { return Pixel (*this) != Pixel (b); } 334 bool operator != (const rxvt_color &b) const { return Pixel (*this) != Pixel (b); }
305 335
336 bool is_opaque () const
337 {
338#if XFT
339 return c.color.alpha == rgba::MAX_CC;
340#else
341 return 1;
342#endif
343 }
344
306 bool alloc (rxvt_screen *screen, const rgba &color); 345 bool alloc (rxvt_screen *screen, const rgba &color);
307 void free (rxvt_screen *screen); 346 void free (rxvt_screen *screen);
308 347
309 void get (rgba &color); 348 void get (rgba &color);
310 void get (XColor &color); 349 void get (XColor &color);
311 350
312 bool set (rxvt_screen *screen, const char *name); 351 bool set (rxvt_screen *screen, const char *name);
313 bool set (rxvt_screen *screen, const rgba &color); 352 bool set (rxvt_screen *screen, const rgba &color);
314 353
315 void fade (rxvt_screen *screen, int percent, rxvt_color &result, const rgba &to = rgba (0, 0, 0)); 354 void fade (rxvt_screen *screen, int percent, rxvt_color &result, const rgba &to = rgba (0, 0, 0));
316}; 355};
317 356
318#endif 357#if TRACE_PIXMAPS
358Pixmap trace_XCreatePixmap (const char *file, int line, Display *dpy, Window r, unsigned int w, unsigned int h, unsigned int d);
359void trace_XFreePixmap (const char *file, int line, Display *dpy, Pixmap p);
319 360
361# define XCreatePixmap(dpy,r,w,h,d) trace_XCreatePixmap (__FILE__,__LINE__,dpy,r,w,h,d)
362# define XFreePixmap(dpy,p) trace_XFreePixmap (__FILE__,__LINE__,dpy,p)
363#endif
364
365#endif
366

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines