… | |
… | |
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 |
… | |
… | |
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, |
… | |
… | |
100 | struct rxvt_display; |
100 | struct rxvt_display; |
101 | |
101 | |
102 | struct im_watcher; |
102 | struct im_watcher; |
103 | struct xevent_watcher; |
103 | struct xevent_watcher; |
104 | |
104 | |
|
|
105 | template<class watcher> |
|
|
106 | struct 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 | |
|
|
119 | struct 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 | |
105 | struct refcounted { |
128 | struct 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 | |
115 | template<class T> |
139 | template<class T> |
116 | struct refcache : vector<T *> { |
140 | struct 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 | |
129 | struct rxvt_screen; |
154 | struct rxvt_screen; |
130 | |
155 | |
131 | struct rxvt_drawable { |
156 | struct 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 |
157 | struct rxvt_xim : refcounted { |
183 | struct 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 | |
170 | struct rxvt_screen { |
197 | struct 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; |
… | |
… | |
187 | void set (rxvt_display *disp); |
215 | void set (rxvt_display *disp); |
188 | void select_visual (int bitdepth); |
216 | void select_visual (int bitdepth); |
189 | void clear (); |
217 | void clear (); |
190 | }; |
218 | }; |
191 | |
219 | |
192 | #ifdef HAVE_AFTERIMAGE |
|
|
193 | struct ASVisual; |
|
|
194 | #endif |
|
|
195 | |
|
|
196 | struct rxvt_display : refcounted { |
220 | struct rxvt_display : refcounted |
|
|
221 | { |
197 | io_manager_vec<xevent_watcher> xw; |
222 | event_vec<xevent_watcher> xw; |
198 | |
223 | |
199 | 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); |
200 | |
226 | |
201 | #ifdef USE_XIM |
227 | #ifdef USE_XIM |
202 | refcache<rxvt_xim> xims; |
228 | refcache<rxvt_xim> xims; |
203 | vector<im_watcher *> imw; |
229 | vector<im_watcher *> imw; |
204 | |
230 | |
… | |
… | |
208 | |
234 | |
209 | //public |
235 | //public |
210 | Display *dpy; |
236 | Display *dpy; |
211 | int screen; |
237 | int screen; |
212 | Window root; |
238 | Window root; |
213 | #ifdef HAVE_AFTERIMAGE |
|
|
214 | struct ASVisual *asv; |
|
|
215 | #endif |
|
|
216 | rxvt_term *selection_owner; |
239 | rxvt_term *selection_owner; |
|
|
240 | rxvt_term *clipboard_owner; |
217 | Atom xa[NUM_XA]; |
241 | Atom xa[NUM_XA]; |
218 | bool is_local; |
242 | bool is_local; |
219 | #ifdef POINTER_BLANK |
243 | #ifdef POINTER_BLANK |
220 | Cursor blank_cursor; |
244 | Cursor blank_cursor; |
221 | #endif |
245 | #endif |
… | |
… | |
224 | XrmDatabase get_resources (bool refresh); |
248 | XrmDatabase get_resources (bool refresh); |
225 | bool ref_init (); |
249 | bool ref_init (); |
226 | void ref_next (); |
250 | void ref_next (); |
227 | ~rxvt_display (); |
251 | ~rxvt_display (); |
228 | |
252 | |
229 | void flush (); |
253 | void flush () |
|
|
254 | { |
|
|
255 | flush_ev.start (); |
|
|
256 | } |
|
|
257 | |
230 | Atom atom (const char *name); |
258 | Atom atom (const char *name); |
231 | void set_selection_owner (rxvt_term *owner); |
259 | void set_selection_owner (rxvt_term *owner, bool clipboard); |
232 | |
260 | |
233 | void reg (xevent_watcher *w); |
261 | void reg (xevent_watcher *w); |
234 | void unreg (xevent_watcher *w); |
262 | void unreg (xevent_watcher *w); |
235 | |
263 | |
236 | #ifdef USE_XIM |
264 | #ifdef USE_XIM |
… | |
… | |
241 | void put_xim (rxvt_xim *xim); |
269 | void put_xim (rxvt_xim *xim); |
242 | #endif |
270 | #endif |
243 | }; |
271 | }; |
244 | |
272 | |
245 | #ifdef USE_XIM |
273 | #ifdef USE_XIM |
246 | struct im_watcher : watcher, callback<void (void)> { |
274 | struct im_watcher : rxvt_watcher, callback<void (void)> |
247 | template<class O, class M> |
275 | { |
248 | im_watcher (O object, M method) |
|
|
249 | : callback<void (void)> (object, method) |
|
|
250 | { } |
|
|
251 | |
|
|
252 | void start (rxvt_display *display) |
276 | void start (rxvt_display *display) |
253 | { |
277 | { |
254 | display->reg (this); |
278 | display->reg (this); |
255 | } |
279 | } |
|
|
280 | |
256 | void stop (rxvt_display *display) |
281 | void stop (rxvt_display *display) |
257 | { |
282 | { |
258 | display->unreg (this); |
283 | display->unreg (this); |
259 | } |
284 | } |
260 | }; |
285 | }; |
261 | #endif |
286 | #endif |
262 | |
287 | |
263 | struct xevent_watcher : watcher, callback<void (XEvent &)> { |
288 | struct xevent_watcher : rxvt_watcher, callback<void (XEvent &)> |
|
|
289 | { |
264 | Window window; |
290 | Window window; |
265 | |
|
|
266 | template<class O, class M> |
|
|
267 | xevent_watcher (O object, M method) |
|
|
268 | : callback<void (XEvent &)> (object, method) |
|
|
269 | { } |
|
|
270 | |
291 | |
271 | void start (rxvt_display *display, Window window) |
292 | void start (rxvt_display *display, Window window) |
272 | { |
293 | { |
273 | this->window = window; |
294 | this->window = window; |
274 | display->reg (this); |
295 | display->reg (this); |
275 | } |
296 | } |
|
|
297 | |
276 | void stop (rxvt_display *display) |
298 | void stop (rxvt_display *display) |
277 | { |
299 | { |
278 | display->unreg (this); |
300 | display->unreg (this); |
279 | } |
301 | } |
280 | }; |
302 | }; |
… | |
… | |
283 | |
305 | |
284 | ///////////////////////////////////////////////////////////////////////////// |
306 | ///////////////////////////////////////////////////////////////////////////// |
285 | |
307 | |
286 | typedef unsigned long Pixel; |
308 | typedef unsigned long Pixel; |
287 | |
309 | |
288 | struct rgba { |
310 | struct rgba |
|
|
311 | { |
289 | unsigned short r, g, b, a; |
312 | unsigned short r, g, b, a; |
290 | |
313 | |
291 | enum { MIN_CC = 0x0000, MAX_CC = 0xffff }; |
314 | enum { MIN_CC = 0x0000, MAX_CC = 0xffff }; |
292 | |
315 | |
293 | rgba () |
316 | rgba () |
… | |
… | |
296 | rgba (unsigned short r, unsigned short g, unsigned short b, unsigned short a = MAX_CC) |
319 | rgba (unsigned short r, unsigned short g, unsigned short b, unsigned short a = MAX_CC) |
297 | : r(r), g(g), b(b), a(a) |
320 | : r(r), g(g), b(b), a(a) |
298 | { } |
321 | { } |
299 | }; |
322 | }; |
300 | |
323 | |
301 | struct rxvt_color { |
324 | struct rxvt_color |
|
|
325 | { |
302 | #if XFT |
326 | #if XFT |
303 | XftColor c; |
327 | XftColor c; |
304 | #else |
328 | #else |
305 | XColor c; |
329 | XColor c; |
306 | #endif |
330 | #endif |
… | |
… | |
308 | operator Pixel () const { return c.pixel; } |
332 | operator Pixel () const { return c.pixel; } |
309 | |
333 | |
310 | 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); } |
311 | bool operator != (const rxvt_color &b) const { return Pixel (*this) != Pixel (b); } |
335 | bool operator != (const rxvt_color &b) const { return Pixel (*this) != Pixel (b); } |
312 | |
336 | |
|
|
337 | bool is_opaque () const |
|
|
338 | { |
|
|
339 | #if XFT |
|
|
340 | return c.color.alpha == rgba::MAX_CC; |
|
|
341 | #else |
|
|
342 | return 1; |
|
|
343 | #endif |
|
|
344 | } |
|
|
345 | |
313 | bool alloc (rxvt_screen *screen, const rgba &color); |
346 | bool alloc (rxvt_screen *screen, const rgba &color); |
314 | void free (rxvt_screen *screen); |
347 | void free (rxvt_screen *screen); |
315 | |
348 | |
316 | void get (rgba &color); |
349 | void get (rgba &color); |
317 | void get (XColor &color); |
350 | void get (XColor &color); |
318 | |
351 | |
319 | bool set (rxvt_screen *screen, const char *name); |
352 | bool set (rxvt_screen *screen, const char *name); |
320 | bool set (rxvt_screen *screen, const rgba &color); |
353 | bool set (rxvt_screen *screen, const rgba &color); |
321 | |
354 | |
322 | void fade (rxvt_screen *screen, int percent, rxvt_color &result, const rgba &to = rgba (0, 0, 0)); |
355 | void fade (rxvt_screen *screen, int percent, rxvt_color &result, const rgba &to = rgba (0, 0, 0)); |
323 | }; |
356 | }; |