… | |
… | |
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" |
34 | #include "rxvtlib.h" |
35 | #include "rxvtutil.h" |
35 | #include "rxvtutil.h" |
36 | |
36 | |
37 | #include "callback.h" |
37 | #include "callback.h" |
… | |
… | |
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 |
70 | #if TRANSPARENT |
70 | #if ENABLE_TRANSPARENCY |
71 | XA_XROOTPMAP_ID, |
71 | XA_XROOTPMAP_ID, |
72 | XA_ESETROOT_PMAP_ID, |
72 | XA_ESETROOT_PMAP_ID, |
73 | #endif |
73 | #endif |
74 | #if ENABLE_XEMBED |
74 | #if ENABLE_XEMBED |
75 | XA_XEMBED, |
75 | XA_XEMBED, |
… | |
… | |
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::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; |
… | |
… | |
241 | void put_xim (rxvt_xim *xim); |
263 | void put_xim (rxvt_xim *xim); |
242 | #endif |
264 | #endif |
243 | }; |
265 | }; |
244 | |
266 | |
245 | #ifdef USE_XIM |
267 | #ifdef USE_XIM |
246 | struct im_watcher : watcher, callback<void (void)> { |
268 | 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) |
269 | void start (rxvt_display *display) |
253 | { |
270 | { |
254 | display->reg (this); |
271 | display->reg (this); |
255 | } |
272 | } |
|
|
273 | |
256 | void stop (rxvt_display *display) |
274 | void stop (rxvt_display *display) |
257 | { |
275 | { |
258 | display->unreg (this); |
276 | display->unreg (this); |
259 | } |
277 | } |
260 | }; |
278 | }; |
261 | #endif |
279 | #endif |
262 | |
280 | |
263 | struct xevent_watcher : watcher, callback<void (XEvent &)> { |
281 | struct xevent_watcher : rxvt_watcher, callback<void (XEvent &)> |
|
|
282 | { |
264 | Window window; |
283 | Window window; |
265 | |
|
|
266 | template<class O, class M> |
|
|
267 | xevent_watcher (O object, M method) |
|
|
268 | : callback<void (XEvent &)> (object, method) |
|
|
269 | { } |
|
|
270 | |
284 | |
271 | void start (rxvt_display *display, Window window) |
285 | void start (rxvt_display *display, Window window) |
272 | { |
286 | { |
273 | this->window = window; |
287 | this->window = window; |
274 | display->reg (this); |
288 | display->reg (this); |
275 | } |
289 | } |
|
|
290 | |
276 | void stop (rxvt_display *display) |
291 | void stop (rxvt_display *display) |
277 | { |
292 | { |
278 | display->unreg (this); |
293 | display->unreg (this); |
279 | } |
294 | } |
280 | }; |
295 | }; |
… | |
… | |
283 | |
298 | |
284 | ///////////////////////////////////////////////////////////////////////////// |
299 | ///////////////////////////////////////////////////////////////////////////// |
285 | |
300 | |
286 | typedef unsigned long Pixel; |
301 | typedef unsigned long Pixel; |
287 | |
302 | |
288 | struct rgba { |
303 | struct rgba |
|
|
304 | { |
289 | unsigned short r, g, b, a; |
305 | unsigned short r, g, b, a; |
290 | |
306 | |
291 | enum { MIN_CC = 0x0000, MAX_CC = 0xffff }; |
307 | enum { MIN_CC = 0x0000, MAX_CC = 0xffff }; |
292 | |
308 | |
293 | rgba () |
309 | rgba () |
… | |
… | |
296 | rgba (unsigned short r, unsigned short g, unsigned short b, unsigned short a = MAX_CC) |
312 | rgba (unsigned short r, unsigned short g, unsigned short b, unsigned short a = MAX_CC) |
297 | : r(r), g(g), b(b), a(a) |
313 | : r(r), g(g), b(b), a(a) |
298 | { } |
314 | { } |
299 | }; |
315 | }; |
300 | |
316 | |
301 | struct rxvt_color { |
317 | struct rxvt_color |
|
|
318 | { |
302 | #if XFT |
319 | #if XFT |
303 | XftColor c; |
320 | XftColor c; |
304 | #else |
321 | #else |
305 | XColor c; |
322 | XColor c; |
306 | #endif |
323 | #endif |
… | |
… | |
313 | bool alloc (rxvt_screen *screen, const rgba &color); |
330 | bool alloc (rxvt_screen *screen, const rgba &color); |
314 | void free (rxvt_screen *screen); |
331 | void free (rxvt_screen *screen); |
315 | |
332 | |
316 | void get (rgba &color); |
333 | void get (rgba &color); |
317 | void get (XColor &color); |
334 | void get (XColor &color); |
318 | |
335 | |
319 | bool set (rxvt_screen *screen, const char *name); |
336 | bool set (rxvt_screen *screen, const char *name); |
320 | bool set (rxvt_screen *screen, const rgba &color); |
337 | bool set (rxvt_screen *screen, const rgba &color); |
321 | |
338 | |
322 | void fade (rxvt_screen *screen, int percent, rxvt_color &result, const rgba &to = rgba (0, 0, 0)); |
339 | void fade (rxvt_screen *screen, int percent, rxvt_color &result, const rgba &to = rgba (0, 0, 0)); |
323 | }; |
340 | }; |
324 | |
341 | |
325 | #endif |
342 | #if TRACE_PIXMAPS |
|
|
343 | Pixmap trace_XCreatePixmap (const char *file, int line, Display *dpy, Window r, unsigned int w, unsigned int h, unsigned int d); |
|
|
344 | void trace_XFreePixmap (const char *file, int line, Display *dpy, Pixmap p); |
326 | |
345 | |
|
|
346 | # define XCreatePixmap(dpy,r,w,h,d) trace_XCreatePixmap (__FILE__,__LINE__,dpy,r,w,h,d) |
|
|
347 | # define XFreePixmap(dpy,p) trace_XFreePixmap (__FILE__,__LINE__,dpy,p) |
|
|
348 | #endif |
|
|
349 | |
|
|
350 | #endif |
|
|
351 | |