… | |
… | |
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 |
… | |
… | |
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, |
… | |
… | |
100 | struct rxvt_display; |
99 | struct rxvt_display; |
101 | |
100 | |
102 | struct im_watcher; |
101 | struct im_watcher; |
103 | struct xevent_watcher; |
102 | struct xevent_watcher; |
104 | |
103 | |
|
|
104 | template<class watcher> |
|
|
105 | struct event_vec : vector<watcher *> |
|
|
106 | { |
|
|
107 | void erase_unordered (unsigned int pos) |
|
|
108 | { |
|
|
109 | watcher *w = (*this)[this->size () - 1]; |
|
|
110 | this->pop_back (); |
|
|
111 | |
|
|
112 | if (!this->empty ()) |
|
|
113 | if (((*this)[pos] = w)) // '=' is correct! |
|
|
114 | w->active = pos + 1; |
|
|
115 | } |
|
|
116 | }; |
|
|
117 | |
|
|
118 | struct rxvt_watcher |
|
|
119 | { |
|
|
120 | int active; /* 0 == inactive, else index into respective vector */ |
|
|
121 | |
|
|
122 | bool is_active () { return active; } |
|
|
123 | |
|
|
124 | rxvt_watcher () : active (0) { } |
|
|
125 | }; |
|
|
126 | |
105 | struct refcounted { |
127 | struct refcounted |
|
|
128 | { |
106 | int referenced; |
129 | int referenced; |
107 | char *id; |
130 | char *id; |
108 | |
131 | |
109 | refcounted (const char *id); |
132 | refcounted (const char *id); |
110 | bool ref_init () { return false; } |
133 | bool ref_init () { return false; } |
111 | void ref_next () { } |
134 | void ref_next () { } |
112 | ~refcounted (); |
135 | ~refcounted (); |
113 | }; |
136 | }; |
114 | |
137 | |
115 | template<class T> |
138 | template<class T> |
116 | struct refcache : vector<T *> { |
139 | struct refcache : vector<T *> |
|
|
140 | { |
117 | T *get (const char *id); |
141 | T *get (const char *id); |
118 | void put (T *obj); |
142 | void put (T *obj); |
119 | void clear (); |
143 | void clear (); |
120 | |
144 | |
121 | ~refcache () |
145 | ~refcache () |
… | |
… | |
126 | |
150 | |
127 | ///////////////////////////////////////////////////////////////////////////// |
151 | ///////////////////////////////////////////////////////////////////////////// |
128 | |
152 | |
129 | struct rxvt_screen; |
153 | struct rxvt_screen; |
130 | |
154 | |
131 | struct rxvt_drawable { |
155 | struct rxvt_drawable |
|
|
156 | { |
132 | rxvt_screen *screen; |
157 | rxvt_screen *screen; |
133 | Drawable drawable; |
158 | Drawable drawable; |
134 | operator Drawable() { return drawable; } |
159 | operator Drawable() { return drawable; } |
135 | |
160 | |
136 | #if XFT |
161 | #if XFT |
… | |
… | |
152 | }; |
177 | }; |
153 | |
178 | |
154 | ///////////////////////////////////////////////////////////////////////////// |
179 | ///////////////////////////////////////////////////////////////////////////// |
155 | |
180 | |
156 | #ifdef USE_XIM |
181 | #ifdef USE_XIM |
157 | struct rxvt_xim : refcounted { |
182 | struct rxvt_xim : refcounted |
|
|
183 | { |
158 | void destroy (); |
184 | void destroy (); |
159 | rxvt_display *display; |
185 | rxvt_display *display; |
160 | |
186 | |
161 | //public |
187 | //public |
162 | XIM xim; |
188 | XIM xim; |
… | |
… | |
165 | bool ref_init (); |
191 | bool ref_init (); |
166 | ~rxvt_xim (); |
192 | ~rxvt_xim (); |
167 | }; |
193 | }; |
168 | #endif |
194 | #endif |
169 | |
195 | |
170 | struct rxvt_screen { |
196 | struct rxvt_screen |
|
|
197 | { |
171 | rxvt_display *display; |
198 | rxvt_display *display; |
172 | Display *dpy; |
199 | Display *dpy; |
173 | int depth; |
200 | int depth; |
174 | Visual *visual; |
201 | Visual *visual; |
175 | Colormap cmap; |
202 | Colormap cmap; |
… | |
… | |
187 | void set (rxvt_display *disp); |
214 | void set (rxvt_display *disp); |
188 | void select_visual (int bitdepth); |
215 | void select_visual (int bitdepth); |
189 | void clear (); |
216 | void clear (); |
190 | }; |
217 | }; |
191 | |
218 | |
192 | #ifdef HAVE_AFTERIMAGE |
|
|
193 | struct ASVisual; |
|
|
194 | #endif |
|
|
195 | |
|
|
196 | struct rxvt_display : refcounted { |
219 | struct rxvt_display : refcounted |
|
|
220 | { |
197 | io_manager_vec<xevent_watcher> xw; |
221 | event_vec<xevent_watcher> xw; |
198 | |
222 | |
199 | io_watcher x_ev; void x_cb (io_watcher &w, short revents); |
223 | ev::prepare flush_ev; void flush_cb (ev::prepare &w, int revents); |
|
|
224 | ev::io x_ev ; void x_cb (ev::io &w, int revents); |
200 | |
225 | |
201 | #ifdef USE_XIM |
226 | #ifdef USE_XIM |
202 | refcache<rxvt_xim> xims; |
227 | refcache<rxvt_xim> xims; |
203 | vector<im_watcher *> imw; |
228 | vector<im_watcher *> imw; |
204 | |
229 | |
… | |
… | |
208 | |
233 | |
209 | //public |
234 | //public |
210 | Display *dpy; |
235 | Display *dpy; |
211 | int screen; |
236 | int screen; |
212 | Window root; |
237 | Window root; |
213 | #ifdef HAVE_AFTERIMAGE |
|
|
214 | struct ASVisual *asv; |
|
|
215 | #endif |
|
|
216 | rxvt_term *selection_owner; |
238 | rxvt_term *selection_owner; |
217 | Atom xa[NUM_XA]; |
239 | Atom xa[NUM_XA]; |
218 | bool is_local; |
240 | bool is_local; |
219 | #ifdef POINTER_BLANK |
241 | #ifdef POINTER_BLANK |
220 | Cursor blank_cursor; |
242 | Cursor blank_cursor; |
… | |
… | |
224 | XrmDatabase get_resources (bool refresh); |
246 | XrmDatabase get_resources (bool refresh); |
225 | bool ref_init (); |
247 | bool ref_init (); |
226 | void ref_next (); |
248 | void ref_next (); |
227 | ~rxvt_display (); |
249 | ~rxvt_display (); |
228 | |
250 | |
229 | void flush (); |
251 | void flush () |
|
|
252 | { |
|
|
253 | flush_ev.start (); |
|
|
254 | } |
|
|
255 | |
230 | Atom atom (const char *name); |
256 | Atom atom (const char *name); |
231 | void set_selection_owner (rxvt_term *owner); |
257 | void set_selection_owner (rxvt_term *owner); |
232 | |
258 | |
233 | void reg (xevent_watcher *w); |
259 | void reg (xevent_watcher *w); |
234 | void unreg (xevent_watcher *w); |
260 | void unreg (xevent_watcher *w); |
… | |
… | |
241 | void put_xim (rxvt_xim *xim); |
267 | void put_xim (rxvt_xim *xim); |
242 | #endif |
268 | #endif |
243 | }; |
269 | }; |
244 | |
270 | |
245 | #ifdef USE_XIM |
271 | #ifdef USE_XIM |
246 | struct im_watcher : watcher, callback<void (void)> { |
272 | struct im_watcher : rxvt_watcher, callback<void (void)> { |
247 | template<class O, class M> |
|
|
248 | im_watcher (O object, M method) |
|
|
249 | : callback<void (void)> (object, method) |
|
|
250 | { } |
|
|
251 | |
|
|
252 | void start (rxvt_display *display) |
273 | void start (rxvt_display *display) |
253 | { |
274 | { |
254 | display->reg (this); |
275 | display->reg (this); |
255 | } |
276 | } |
|
|
277 | |
256 | void stop (rxvt_display *display) |
278 | void stop (rxvt_display *display) |
257 | { |
279 | { |
258 | display->unreg (this); |
280 | display->unreg (this); |
259 | } |
281 | } |
260 | }; |
282 | }; |
261 | #endif |
283 | #endif |
262 | |
284 | |
263 | struct xevent_watcher : watcher, callback<void (XEvent &)> { |
285 | struct xevent_watcher : rxvt_watcher, callback<void (XEvent &)> |
|
|
286 | { |
264 | Window window; |
287 | Window window; |
265 | |
|
|
266 | template<class O, class M> |
|
|
267 | xevent_watcher (O object, M method) |
|
|
268 | : callback<void (XEvent &)> (object, method) |
|
|
269 | { } |
|
|
270 | |
288 | |
271 | void start (rxvt_display *display, Window window) |
289 | void start (rxvt_display *display, Window window) |
272 | { |
290 | { |
273 | this->window = window; |
291 | this->window = window; |
274 | display->reg (this); |
292 | display->reg (this); |
275 | } |
293 | } |
|
|
294 | |
276 | void stop (rxvt_display *display) |
295 | void stop (rxvt_display *display) |
277 | { |
296 | { |
278 | display->unreg (this); |
297 | display->unreg (this); |
279 | } |
298 | } |
280 | }; |
299 | }; |
… | |
… | |
283 | |
302 | |
284 | ///////////////////////////////////////////////////////////////////////////// |
303 | ///////////////////////////////////////////////////////////////////////////// |
285 | |
304 | |
286 | typedef unsigned long Pixel; |
305 | typedef unsigned long Pixel; |
287 | |
306 | |
288 | struct rgba { |
307 | struct rgba |
|
|
308 | { |
289 | unsigned short r, g, b, a; |
309 | unsigned short r, g, b, a; |
290 | |
310 | |
291 | enum { MIN_CC = 0x0000, MAX_CC = 0xffff }; |
311 | enum { MIN_CC = 0x0000, MAX_CC = 0xffff }; |
292 | |
312 | |
293 | rgba () |
313 | rgba () |
… | |
… | |
296 | 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) |
297 | : r(r), g(g), b(b), a(a) |
317 | : r(r), g(g), b(b), a(a) |
298 | { } |
318 | { } |
299 | }; |
319 | }; |
300 | |
320 | |
301 | struct rxvt_color { |
321 | struct rxvt_color |
|
|
322 | { |
302 | #if XFT |
323 | #if XFT |
303 | XftColor c; |
324 | XftColor c; |
304 | #else |
325 | #else |
305 | XColor c; |
326 | XColor c; |
306 | #endif |
327 | #endif |
… | |
… | |
308 | operator Pixel () const { return c.pixel; } |
329 | operator Pixel () const { return c.pixel; } |
309 | |
330 | |
310 | 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); } |
311 | 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); } |
312 | |
333 | |
|
|
334 | bool is_opaque () const |
|
|
335 | { |
|
|
336 | #if XFT |
|
|
337 | //TODO: only supports 24 bit truecolour |
|
|
338 | return c.color.alpha < 0xff00; |
|
|
339 | #else |
|
|
340 | return 1; |
|
|
341 | #endif |
|
|
342 | } |
|
|
343 | |
313 | bool alloc (rxvt_screen *screen, const rgba &color); |
344 | bool alloc (rxvt_screen *screen, const rgba &color); |
314 | void free (rxvt_screen *screen); |
345 | void free (rxvt_screen *screen); |
315 | |
346 | |
316 | void get (rgba &color); |
347 | void get (rgba &color); |
317 | void get (XColor &color); |
348 | void get (XColor &color); |
318 | |
349 | |
319 | bool set (rxvt_screen *screen, const char *name); |
350 | bool set (rxvt_screen *screen, const char *name); |
320 | bool set (rxvt_screen *screen, const rgba &color); |
351 | bool set (rxvt_screen *screen, const rgba &color); |
321 | |
352 | |
322 | void fade (rxvt_screen *screen, int percent, rxvt_color &result, const rgba &to = rgba (0, 0, 0)); |
353 | void fade (rxvt_screen *screen, int percent, rxvt_color &result, const rgba &to = rgba (0, 0, 0)); |
323 | }; |
354 | }; |
324 | |
355 | |
325 | #endif |
356 | #if TRACE_PIXMAPS |
|
|
357 | Pixmap trace_XCreatePixmap (const char *file, int line, Display *dpy, Window r, unsigned int w, unsigned int h, unsigned int d); |
|
|
358 | void trace_XFreePixmap (const char *file, int line, Display *dpy, Pixmap p); |
326 | |
359 | |
|
|
360 | # define XCreatePixmap(dpy,r,w,h,d) trace_XCreatePixmap (__FILE__,__LINE__,dpy,r,w,h,d) |
|
|
361 | # define XFreePixmap(dpy,p) trace_XFreePixmap (__FILE__,__LINE__,dpy,p) |
|
|
362 | #endif |
|
|
363 | |
|
|
364 | #endif |
|
|
365 | |