ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/rxvttoolkit.h
Revision: 1.24
Committed: Sat Feb 18 14:14:43 2006 UTC (18 years, 3 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.23: +37 -0 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 /*
2     * rxvttoolkit.h - provide toolkit-functionality for rxvt.
3     */
4     #ifndef RXVT_TOOLKIT_H
5     #define RXVT_TOOLKIT_H
6    
7     #include <X11/Xlib.h>
8    
9     #if XFT
10     # include <X11/Xft/Xft.h>
11     #endif
12    
13     #include "iom.h"
14    
15     #include "rxvtlib.h"
16     #include "rxvtutil.h"
17    
18     #include "callback.h"
19    
20 root 1.11 // see rxvttoolkit.C:xa_names, which must be kept in sync
21     enum {
22     XA_TEXT,
23     XA_COMPOUND_TEXT,
24     XA_UTF8_STRING,
25     XA_MULTIPLE,
26     XA_TARGETS,
27     XA_TIMESTAMP,
28     XA_VT_SELECTION,
29     XA_INCR,
30     XA_WM_PROTOCOLS,
31     XA_WM_DELETE_WINDOW,
32     XA_CLIPBOARD,
33 root 1.14 XA_AVERAGE_WIDTH,
34     XA_WEIGHT_NAME,
35     XA_SLANT,
36     XA_CHARSET_REGISTRY,
37     XA_CHARSET_ENCODING,
38 root 1.11 #if ENABLE_FRILLS
39     XA_MOTIF_WM_HINTS,
40     #endif
41     #if ENABLE_EWMH
42     XA_NET_WM_PID,
43     XA_NET_WM_NAME,
44     XA_NET_WM_ICON_NAME,
45     XA_NET_WM_PING,
46     #endif
47     #if USE_XIM
48     XA_WM_LOCALE_NAME,
49     XA_XIM_SERVERS,
50     #endif
51     #if TRANSPARENT
52     XA_XROOTPMAP_ID,
53     XA_ESETROOT_PMAP_ID,
54     #endif
55     #if ENABLE_XEMBED
56     XA_XEMBED,
57     XA_XEMBED_INFO,
58     #endif
59 root 1.14 #if !ENABLE_MINIMAL
60     // these are usually allocated by other subsystens, but we do it
61     // here to avoid a server roundtrip.
62     XA_SCREEN_RESOURCES,
63     XA_XDCCC_LINEAR_RGB_CORRECTION,
64     XA_XDCCC_LINEAR_RGB_MATRICES,
65     XA_WM_COLORMAP_WINDOWS,
66     XA_WM_STATE,
67 root 1.15 XA_cursor,
68     # if USE_XIM
69     // various selection targets used by XIM
70     XA_TRANSPORT,
71     XA_LOCALES,
72     XA__XIM_PROTOCOL,
73     XA__XIM_XCONNECT,
74     XA__XIM_MOREDATA,
75     # endif
76 root 1.14 #endif
77 root 1.11 NUM_XA
78     };
79    
80 root 1.1 struct rxvt_term;
81 root 1.2 struct rxvt_display;
82 root 1.1
83     struct im_watcher;
84     struct xevent_watcher;
85    
86     struct refcounted {
87     int referenced;
88     char *id;
89    
90     refcounted (const char *id);
91 root 1.9 bool ref_init () { return false; }
92     void ref_next () { }
93 root 1.1 ~refcounted ();
94     };
95    
96     template<class T>
97     struct refcache : vector<T *> {
98     T *get (const char *id);
99     void put (T *obj);
100 root 1.7 void clear ();
101    
102     ~refcache ()
103     {
104     clear ();
105     }
106 root 1.1 };
107    
108     /////////////////////////////////////////////////////////////////////////////
109    
110 root 1.24 struct rxvt_screen;
111    
112     struct rxvt_drawable {
113     rxvt_screen *screen;
114     Drawable drawable;
115     operator Drawable() { return drawable; }
116    
117     #if XFT
118     XftDraw *xftdrawable;
119     operator XftDraw *();
120     #endif
121    
122     rxvt_drawable (rxvt_screen *screen, Drawable drawable)
123     : screen(screen),
124     #if XFT
125     xftdrawable(0),
126     #endif
127     drawable(drawable)
128     { }
129    
130     #if XFT
131     ~rxvt_drawable ();
132     #endif
133     };
134    
135     /////////////////////////////////////////////////////////////////////////////
136    
137 root 1.1 #ifdef USE_XIM
138     struct rxvt_xim : refcounted {
139     void destroy ();
140     rxvt_display *display;
141    
142     //public
143     XIM xim;
144    
145     rxvt_xim (const char *id) : refcounted (id) { }
146 root 1.9 bool ref_init ();
147 root 1.1 ~rxvt_xim ();
148     };
149     #endif
150    
151 root 1.12 struct rxvt_screen {
152     rxvt_display *display;
153 root 1.23 Display *dpy;
154 root 1.12 int depth;
155     Visual *visual;
156     Colormap cmap;
157    
158 root 1.24 #if XFT
159     // scratch pixmap
160     rxvt_drawable *scratch_area;
161     int scratch_w, scratch_h;
162    
163     rxvt_drawable &scratch_drawable (int w, int h);
164    
165     rxvt_screen ();
166     #endif
167    
168 root 1.12 void set (rxvt_display *disp);
169 root 1.13 void set (rxvt_display *disp, int bitdepth);
170 root 1.12 void clear ();
171     };
172    
173 root 1.1 struct rxvt_display : refcounted {
174     io_manager_vec<xevent_watcher> xw;
175    
176     io_watcher x_ev; void x_cb (io_watcher &w, short revents);
177    
178     #ifdef USE_XIM
179     refcache<rxvt_xim> xims;
180     vector<im_watcher *> imw;
181    
182     void im_change_cb ();
183 root 1.3 void im_change_check ();
184 root 1.1 #endif
185    
186     //public
187 root 1.23 Display *dpy;
188 root 1.7 int screen;
189     Window root;
190 root 1.1 rxvt_term *selection_owner;
191 root 1.11 Atom xa[NUM_XA];
192 root 1.1 #ifndef NO_SLOW_LINK_SUPPORT
193 root 1.7 bool is_local;
194     #endif
195     #ifdef POINTER_BLANK
196     Cursor blank_cursor;
197 root 1.1 #endif
198    
199     rxvt_display (const char *id);
200 root 1.22 XrmDatabase get_resources (bool refresh);
201 root 1.9 bool ref_init ();
202     void ref_next ();
203 root 1.1 ~rxvt_display ();
204    
205     void flush ();
206 root 1.5 Atom atom (const char *name);
207 root 1.1 void set_selection_owner (rxvt_term *owner);
208    
209     void reg (xevent_watcher *w);
210     void unreg (xevent_watcher *w);
211    
212     #ifdef USE_XIM
213     void reg (im_watcher *w);
214     void unreg (im_watcher *w);
215    
216     rxvt_xim *get_xim (const char *locale, const char *modifiers);
217     void put_xim (rxvt_xim *xim);
218     #endif
219     };
220    
221     #ifdef USE_XIM
222     struct im_watcher : watcher, callback0<void> {
223     template<class O1, class O2>
224     im_watcher (O1 *object, void (O2::*method) ())
225     : callback0<void> (object,method)
226     { }
227    
228     void start (rxvt_display *display)
229     {
230     display->reg (this);
231     }
232     void stop (rxvt_display *display)
233     {
234     display->unreg (this);
235     }
236     };
237     #endif
238    
239     struct xevent_watcher : watcher, callback1<void, XEvent &> {
240     Window window;
241    
242     template<class O1, class O2>
243     xevent_watcher (O1 *object, void (O2::*method) (XEvent &))
244     : callback1<void, XEvent &> (object,method)
245     { }
246    
247     void start (rxvt_display *display, Window window)
248     {
249     this->window = window;
250     display->reg (this);
251     }
252     void stop (rxvt_display *display)
253     {
254     display->unreg (this);
255     }
256     };
257    
258     extern refcache<rxvt_display> displays;
259    
260     /////////////////////////////////////////////////////////////////////////////
261    
262     typedef unsigned long Pixel;
263    
264 root 1.19 struct rgba {
265 root 1.13 unsigned short r, g, b, a;
266    
267     enum { MIN_CC = 0x0000, MAX_CC = 0xffff };
268    
269 root 1.19 rgba ()
270 root 1.13 { }
271    
272 root 1.19 rgba (unsigned short r, unsigned short g, unsigned short b, unsigned short a = MAX_CC)
273 root 1.13 : r(r), g(g), b(b), a(a)
274     { }
275     };
276    
277 root 1.1 struct rxvt_color {
278     #if XFT
279     XftColor c;
280     #else
281 root 1.19 XColor c;
282 root 1.1 #endif
283    
284 root 1.19 operator Pixel () const { return c.pixel; }
285    
286 root 1.1 bool operator == (const rxvt_color &b) const { return Pixel (*this) == Pixel (b); }
287     bool operator != (const rxvt_color &b) const { return Pixel (*this) != Pixel (b); }
288    
289 root 1.19 bool alloc (rxvt_screen *screen, const rgba &color);
290 root 1.16 void free (rxvt_screen *screen);
291    
292 root 1.20 void get (rgba &color);
293 root 1.21 void get (XColor &color);
294 root 1.1
295 root 1.12 bool set (rxvt_screen *screen, const char *name);
296 root 1.19 bool set (rxvt_screen *screen, const rgba &color);
297 root 1.1
298 root 1.19 void fade (rxvt_screen *screen, int percent, rxvt_color &result, const rgba &to = rgba (0, 0, 0));
299 root 1.1 };
300    
301     #endif
302