… | |
… | |
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 | |
102 | struct im_watcher; |
101 | struct im_watcher; |
103 | struct xevent_watcher; |
102 | struct xevent_watcher; |
104 | |
103 | |
105 | template<class watcher> |
104 | template<class watcher> |
106 | struct event_vec : vector<watcher *> { |
105 | struct 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 | |
118 | struct rxvt_watcher { |
118 | struct 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 | |
126 | struct refcounted { |
127 | struct 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 | |
136 | template<class T> |
138 | template<class T> |
137 | struct refcache : vector<T *> { |
139 | struct 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 | |
150 | struct rxvt_screen; |
153 | struct rxvt_screen; |
151 | |
154 | |
152 | struct rxvt_drawable { |
155 | struct 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 |
178 | struct rxvt_xim : refcounted { |
182 | struct 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 | |
191 | struct rxvt_screen { |
196 | struct 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 | |
213 | struct rxvt_display : refcounted { |
219 | struct rxvt_display : refcounted |
|
|
220 | { |
214 | event_vec<xevent_watcher> xw; |
221 | event_vec<xevent_watcher> xw; |
215 | |
222 | |
|
|
223 | ev::idle flush_ev; void flush_cb (ev::idle &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); |
… | |
… | |
268 | display->unreg (this); |
280 | display->unreg (this); |
269 | } |
281 | } |
270 | }; |
282 | }; |
271 | #endif |
283 | #endif |
272 | |
284 | |
273 | struct xevent_watcher : rxvt_watcher, callback<void (XEvent &)> { |
285 | struct xevent_watcher : rxvt_watcher, callback<void (XEvent &)> |
|
|
286 | { |
274 | Window window; |
287 | Window window; |
275 | |
288 | |
276 | void start (rxvt_display *display, Window window) |
289 | void start (rxvt_display *display, Window window) |
277 | { |
290 | { |
278 | this->window = window; |
291 | this->window = window; |
… | |
… | |
289 | |
302 | |
290 | ///////////////////////////////////////////////////////////////////////////// |
303 | ///////////////////////////////////////////////////////////////////////////// |
291 | |
304 | |
292 | typedef unsigned long Pixel; |
305 | typedef unsigned long Pixel; |
293 | |
306 | |
294 | struct rgba { |
307 | struct rgba |
|
|
308 | { |
295 | unsigned short r, g, b, a; |
309 | unsigned short r, g, b, a; |
296 | |
310 | |
297 | enum { MIN_CC = 0x0000, MAX_CC = 0xffff }; |
311 | enum { MIN_CC = 0x0000, MAX_CC = 0xffff }; |
298 | |
312 | |
299 | rgba () |
313 | rgba () |
… | |
… | |
302 | 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) |
303 | : r(r), g(g), b(b), a(a) |
317 | : r(r), g(g), b(b), a(a) |
304 | { } |
318 | { } |
305 | }; |
319 | }; |
306 | |
320 | |
307 | struct rxvt_color { |
321 | struct rxvt_color |
|
|
322 | { |
308 | #if XFT |
323 | #if XFT |
309 | XftColor c; |
324 | XftColor c; |
310 | #else |
325 | #else |
311 | XColor c; |
326 | XColor c; |
312 | #endif |
327 | #endif |
… | |
… | |
314 | operator Pixel () const { return c.pixel; } |
329 | operator Pixel () const { return c.pixel; } |
315 | |
330 | |
316 | 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); } |
317 | 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); } |
318 | |
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 | |
319 | bool alloc (rxvt_screen *screen, const rgba &color); |
343 | bool alloc (rxvt_screen *screen, const rgba &color); |
320 | void free (rxvt_screen *screen); |
344 | void free (rxvt_screen *screen); |
321 | |
345 | |
322 | void get (rgba &color); |
346 | void get (rgba &color); |
323 | void get (XColor &color); |
347 | void get (XColor &color); |