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