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 |
// 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 |
XA_AVERAGE_WIDTH, |
34 |
XA_WEIGHT_NAME, |
35 |
XA_SLANT, |
36 |
XA_CHARSET_REGISTRY, |
37 |
XA_CHARSET_ENCODING, |
38 |
#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 |
#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 |
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 |
#endif |
77 |
NUM_XA |
78 |
}; |
79 |
|
80 |
struct rxvt_term; |
81 |
struct rxvt_display; |
82 |
|
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 |
bool ref_init () { return false; } |
92 |
void ref_next () { } |
93 |
~refcounted (); |
94 |
}; |
95 |
|
96 |
template<class T> |
97 |
struct refcache : vector<T *> { |
98 |
T *get (const char *id); |
99 |
void put (T *obj); |
100 |
void clear (); |
101 |
|
102 |
~refcache () |
103 |
{ |
104 |
clear (); |
105 |
} |
106 |
}; |
107 |
|
108 |
///////////////////////////////////////////////////////////////////////////// |
109 |
|
110 |
#ifdef USE_XIM |
111 |
struct rxvt_xim : refcounted { |
112 |
void destroy (); |
113 |
rxvt_display *display; |
114 |
|
115 |
//public |
116 |
XIM xim; |
117 |
|
118 |
rxvt_xim (const char *id) : refcounted (id) { } |
119 |
bool ref_init (); |
120 |
~rxvt_xim (); |
121 |
}; |
122 |
#endif |
123 |
|
124 |
struct rxvt_screen { |
125 |
rxvt_display *display; |
126 |
Display *xdisp; |
127 |
int depth; |
128 |
Visual *visual; |
129 |
Colormap cmap; |
130 |
|
131 |
void set (rxvt_display *disp); |
132 |
void set (rxvt_display *disp, int bitdepth); |
133 |
void clear (); |
134 |
}; |
135 |
|
136 |
struct rxvt_display : refcounted { |
137 |
io_manager_vec<xevent_watcher> xw; |
138 |
|
139 |
io_watcher x_ev; void x_cb (io_watcher &w, short revents); |
140 |
|
141 |
#ifdef USE_XIM |
142 |
refcache<rxvt_xim> xims; |
143 |
vector<im_watcher *> imw; |
144 |
|
145 |
void im_change_cb (); |
146 |
void im_change_check (); |
147 |
#endif |
148 |
|
149 |
//public |
150 |
Display *display; |
151 |
int screen; |
152 |
Window root; |
153 |
rxvt_term *selection_owner; |
154 |
Atom xa[NUM_XA]; |
155 |
#ifndef NO_SLOW_LINK_SUPPORT |
156 |
bool is_local; |
157 |
#endif |
158 |
#ifdef POINTER_BLANK |
159 |
Cursor blank_cursor; |
160 |
#endif |
161 |
|
162 |
rxvt_display (const char *id); |
163 |
XrmDatabase get_resources (); |
164 |
bool ref_init (); |
165 |
void ref_next (); |
166 |
~rxvt_display (); |
167 |
|
168 |
void flush (); |
169 |
Atom atom (const char *name); |
170 |
void set_selection_owner (rxvt_term *owner); |
171 |
|
172 |
void reg (xevent_watcher *w); |
173 |
void unreg (xevent_watcher *w); |
174 |
|
175 |
#ifdef USE_XIM |
176 |
void reg (im_watcher *w); |
177 |
void unreg (im_watcher *w); |
178 |
|
179 |
rxvt_xim *get_xim (const char *locale, const char *modifiers); |
180 |
void put_xim (rxvt_xim *xim); |
181 |
#endif |
182 |
}; |
183 |
|
184 |
#ifdef USE_XIM |
185 |
struct im_watcher : watcher, callback0<void> { |
186 |
template<class O1, class O2> |
187 |
im_watcher (O1 *object, void (O2::*method) ()) |
188 |
: callback0<void> (object,method) |
189 |
{ } |
190 |
|
191 |
void start (rxvt_display *display) |
192 |
{ |
193 |
display->reg (this); |
194 |
} |
195 |
void stop (rxvt_display *display) |
196 |
{ |
197 |
display->unreg (this); |
198 |
} |
199 |
}; |
200 |
#endif |
201 |
|
202 |
struct xevent_watcher : watcher, callback1<void, XEvent &> { |
203 |
Window window; |
204 |
|
205 |
template<class O1, class O2> |
206 |
xevent_watcher (O1 *object, void (O2::*method) (XEvent &)) |
207 |
: callback1<void, XEvent &> (object,method) |
208 |
{ } |
209 |
|
210 |
void start (rxvt_display *display, Window window) |
211 |
{ |
212 |
this->window = window; |
213 |
display->reg (this); |
214 |
} |
215 |
void stop (rxvt_display *display) |
216 |
{ |
217 |
display->unreg (this); |
218 |
} |
219 |
}; |
220 |
|
221 |
extern refcache<rxvt_display> displays; |
222 |
|
223 |
///////////////////////////////////////////////////////////////////////////// |
224 |
|
225 |
typedef unsigned long Pixel; |
226 |
|
227 |
struct rgba { |
228 |
unsigned short r, g, b, a; |
229 |
|
230 |
enum { MIN_CC = 0x0000, MAX_CC = 0xffff }; |
231 |
|
232 |
rgba () |
233 |
{ } |
234 |
|
235 |
rgba (unsigned short r, unsigned short g, unsigned short b, unsigned short a = MAX_CC) |
236 |
: r(r), g(g), b(b), a(a) |
237 |
{ } |
238 |
}; |
239 |
|
240 |
struct rxvt_color { |
241 |
#if XFT |
242 |
XftColor c; |
243 |
#else |
244 |
XColor c; |
245 |
#endif |
246 |
|
247 |
operator Pixel () const { return c.pixel; } |
248 |
|
249 |
bool operator == (const rxvt_color &b) const { return Pixel (*this) == Pixel (b); } |
250 |
bool operator != (const rxvt_color &b) const { return Pixel (*this) != Pixel (b); } |
251 |
|
252 |
bool alloc (rxvt_screen *screen, const rgba &color); |
253 |
void free (rxvt_screen *screen); |
254 |
|
255 |
void get (rxvt_screen *screen, rgba &color); |
256 |
|
257 |
bool set (rxvt_screen *screen, const char *name); |
258 |
bool set (rxvt_screen *screen, const rgba &color); |
259 |
|
260 |
void fade (rxvt_screen *screen, int percent, rxvt_color &result, const rgba &to = rgba (0, 0, 0)); |
261 |
}; |
262 |
|
263 |
#endif |
264 |
|