… | |
… | |
82 | delete obj; |
82 | delete obj; |
83 | } |
83 | } |
84 | } |
84 | } |
85 | |
85 | |
86 | template<class T> |
86 | template<class T> |
87 | refcache<T>::~refcache () |
87 | void refcache<T>::clear () |
88 | { |
88 | { |
89 | while (this->size ()) |
89 | while (this->size ()) |
90 | put (*this->begin ()); |
90 | put (*this->begin ()); |
91 | } |
91 | } |
92 | |
92 | |
… | |
… | |
143 | { |
143 | { |
144 | } |
144 | } |
145 | |
145 | |
146 | bool rxvt_display::init () |
146 | bool rxvt_display::init () |
147 | { |
147 | { |
|
|
148 | #ifdef LOCAL_X_IS_UNIX |
|
|
149 | if (id[0] == ':') |
|
|
150 | { |
|
|
151 | val = rxvt_malloc (5 + strlen (id) + 1); |
|
|
152 | strcpy (val, "unix/"); |
|
|
153 | strcat (val, id); |
|
|
154 | display = XOpenDisplay (val); |
|
|
155 | free (val); |
|
|
156 | } |
|
|
157 | else |
|
|
158 | #endif |
|
|
159 | display = 0; |
|
|
160 | |
|
|
161 | if (!display) |
148 | display = XOpenDisplay (id); |
162 | display = XOpenDisplay (id); |
149 | |
163 | |
150 | if (!display) |
164 | if (!display) |
151 | return false; |
165 | return false; |
152 | |
166 | |
153 | screen = DefaultScreen (display); |
167 | screen = DefaultScreen (display); |
… | |
… | |
157 | depth = DefaultDepth (display, screen); |
171 | depth = DefaultDepth (display, screen); |
158 | |
172 | |
159 | int fd = XConnectionNumber (display); |
173 | int fd = XConnectionNumber (display); |
160 | |
174 | |
161 | #ifndef NO_SLOW_LINK_SUPPORT |
175 | #ifndef NO_SLOW_LINK_SUPPORT |
162 | // try to detetc wether we have a local connection. |
176 | // try to detect wether we have a local connection. |
163 | // assume unix domains socket == local, everything else not |
177 | // assume unix domains socket == local, everything else not |
164 | // TODO: might want to check for inet/127.0.0.1 |
178 | // TODO: might want to check for inet/127.0.0.1 |
165 | is_local = 0; |
179 | is_local = 0; |
166 | sockaddr_un sa; |
180 | sockaddr_un sa; |
167 | socklen_t sl = sizeof (sa); |
181 | socklen_t sl = sizeof (sa); |
168 | |
182 | |
169 | if (!getsockname (fd, (sockaddr *)&sa, &sl)) |
183 | if (!getsockname (fd, (sockaddr *)&sa, &sl)) |
170 | is_local = sa.sun_family == AF_LOCAL; |
184 | is_local = sa.sun_family == AF_LOCAL; |
|
|
185 | #endif |
|
|
186 | |
|
|
187 | #ifdef POINTER_BLANK |
|
|
188 | XColor blackcolour; |
|
|
189 | blackcolour.red = 0; |
|
|
190 | blackcolour.green = 0; |
|
|
191 | blackcolour.blue = 0; |
|
|
192 | Font f = XLoadFont (display, "fixed"); |
|
|
193 | blank_cursor = XCreateGlyphCursor (display, f, f, ' ', ' ', |
|
|
194 | &blackcolour, &blackcolour); |
|
|
195 | XUnloadFont (display, f); |
171 | #endif |
196 | #endif |
172 | |
197 | |
173 | #ifdef PREFER_24BIT |
198 | #ifdef PREFER_24BIT |
174 | /* |
199 | /* |
175 | * If depth is not 24, look for a 24bit visual. |
200 | * If depth is not 24, look for a 24bit visual. |
… | |
… | |
202 | return true; |
227 | return true; |
203 | } |
228 | } |
204 | |
229 | |
205 | rxvt_display::~rxvt_display () |
230 | rxvt_display::~rxvt_display () |
206 | { |
231 | { |
|
|
232 | if (!display) |
|
|
233 | return; |
|
|
234 | |
|
|
235 | #ifdef POINTER_BLANK |
|
|
236 | XFreeCursor (display, blank_cursor); |
|
|
237 | #endif |
207 | x_ev.stop (); |
238 | x_ev.stop (); |
208 | |
239 | #ifdef USE_XIM |
209 | if (display) |
240 | xims.clear (); |
|
|
241 | #endif |
210 | XCloseDisplay (display); |
242 | XCloseDisplay (display); |
211 | } |
243 | } |
212 | |
244 | |
213 | #ifdef USE_XIM |
245 | #ifdef USE_XIM |
214 | void rxvt_display::im_change_cb () |
246 | void rxvt_display::im_change_cb () |
215 | { |
247 | { |
… | |
… | |
217 | (*i)->call (); |
249 | (*i)->call (); |
218 | } |
250 | } |
219 | |
251 | |
220 | void rxvt_display::im_change_check () |
252 | void rxvt_display::im_change_check () |
221 | { |
253 | { |
222 | // make sure we only call im_change_cb when a new input method |
254 | // try to only call im_change_cb when a new input method |
223 | // registers, as xlib crashes due to a race otherwise. |
255 | // registers, as xlib crashes due to a race otherwise. |
224 | Atom actual_type, *atoms; |
256 | Atom actual_type, *atoms; |
225 | int actual_format; |
257 | int actual_format; |
226 | unsigned long nitems, bytes_after; |
258 | unsigned long nitems, bytes_after; |
227 | |
259 | |
… | |
… | |
251 | XNextEvent (display, &xev); |
283 | XNextEvent (display, &xev); |
252 | |
284 | |
253 | #ifdef USE_XIM |
285 | #ifdef USE_XIM |
254 | if (!XFilterEvent (&xev, None)) |
286 | if (!XFilterEvent (&xev, None)) |
255 | { |
287 | { |
256 | |
|
|
257 | if (xev.type == PropertyNotify |
288 | if (xev.type == PropertyNotify |
258 | && xev.xany.window == root |
289 | && xev.xany.window == root |
259 | && xev.xproperty.atom == xa_xim_servers) |
290 | && xev.xproperty.atom == xa_xim_servers) |
260 | im_change_check (); |
291 | im_change_check (); |
261 | #endif |
292 | #endif |
… | |
… | |
268 | } |
299 | } |
269 | #ifdef USE_XIM |
300 | #ifdef USE_XIM |
270 | } |
301 | } |
271 | #endif |
302 | #endif |
272 | } |
303 | } |
273 | while (XPending (display)); |
304 | while (XEventsQueued (display, QueuedAlready)); |
274 | |
305 | |
275 | flush (); |
306 | XFlush (display); |
276 | } |
307 | } |
277 | |
308 | |
278 | void rxvt_display::flush () |
309 | void rxvt_display::flush () |
279 | { |
310 | { |
280 | for (;;) |
311 | if (XEventsQueued (display, QueuedAlready)) |
281 | { |
312 | x_cb (x_ev, EVENT_READ); |
282 | if (!XPending (display)) |
|
|
283 | break; |
|
|
284 | |
313 | |
285 | x_cb (x_ev, 0); |
314 | XFlush (display); |
286 | } |
|
|
287 | } |
315 | } |
288 | |
316 | |
289 | void rxvt_display::reg (xevent_watcher *w) |
317 | void rxvt_display::reg (xevent_watcher *w) |
290 | { |
318 | { |
291 | xw.push_back (w); |
319 | xw.push_back (w); |
… | |
… | |
338 | return xim; |
366 | return xim; |
339 | } |
367 | } |
340 | |
368 | |
341 | void rxvt_display::put_xim (rxvt_xim *xim) |
369 | void rxvt_display::put_xim (rxvt_xim *xim) |
342 | { |
370 | { |
|
|
371 | #if XLIB_IS_RACEFREE |
343 | xims.put (xim); |
372 | xims.put (xim); |
|
|
373 | #endif |
344 | } |
374 | } |
345 | #endif |
375 | #endif |
346 | |
376 | |
347 | Atom rxvt_display::atom (const char *name) |
377 | Atom rxvt_display::atom (const char *name) |
348 | { |
378 | { |
… | |
… | |
386 | } |
416 | } |
387 | |
417 | |
388 | bool |
418 | bool |
389 | rxvt_color::set (rxvt_display *display, const char *name) |
419 | rxvt_color::set (rxvt_display *display, const char *name) |
390 | { |
420 | { |
|
|
421 | #if XFT |
|
|
422 | return XftColorAllocName (display->display, display->visual, display->cmap, |
|
|
423 | name, &c); |
|
|
424 | #else |
391 | XColor xc; |
425 | XColor xc; |
392 | |
426 | |
393 | if (XParseColor (display->display, display->cmap, name, &xc)) |
427 | if (XParseColor (display->display, display->cmap, name, &xc)) |
394 | return set (display, xc.red, xc.green, xc.blue); |
428 | return set (display, xc.red, xc.green, xc.blue); |
395 | |
429 | |
396 | return false; |
430 | return false; |
|
|
431 | #endif |
397 | } |
432 | } |
398 | |
433 | |
399 | bool |
434 | bool |
400 | rxvt_color::set (rxvt_display *display, unsigned short cr, unsigned short cg, unsigned short cb) |
435 | rxvt_color::set (rxvt_display *display, unsigned short cr, unsigned short cg, unsigned short cb) |
401 | { |
436 | { |
… | |
… | |
442 | } |
477 | } |
443 | |
478 | |
444 | rxvt_color |
479 | rxvt_color |
445 | rxvt_color::fade (rxvt_display *display, int percent) |
480 | rxvt_color::fade (rxvt_display *display, int percent) |
446 | { |
481 | { |
|
|
482 | percent = 100 - percent; |
|
|
483 | |
447 | unsigned short cr, cg, cb; |
484 | unsigned short cr, cg, cb; |
448 | rxvt_color faded; |
485 | rxvt_color faded; |
449 | |
486 | |
450 | get (display, cr, cg, cb); |
487 | get (display, cr, cg, cb); |
|
|
488 | |
451 | faded.set (display, |
489 | faded.set ( |
|
|
490 | display, |
452 | cr * percent / 100, |
491 | cr * percent / 100, |
453 | cg * percent / 100, |
492 | cg * percent / 100, |
454 | cb * percent / 100); |
493 | cb * percent / 100 |
|
|
494 | ); |
455 | |
495 | |
456 | return faded; |
496 | return faded; |
457 | } |
497 | } |
458 | |
498 | |
|
|
499 | #define LERP(a,b,p) (a * p + b * (100 - p)) / 100 |
|
|
500 | |
|
|
501 | rxvt_color |
|
|
502 | rxvt_color::fade (rxvt_display *display, int percent, rxvt_color &fadeto) |
|
|
503 | { |
|
|
504 | percent = 100 - percent; |
|
|
505 | |
|
|
506 | unsigned short cr, cg, cb; |
|
|
507 | unsigned short fcr, fcg, fcb; |
|
|
508 | rxvt_color faded; |
|
|
509 | |
|
|
510 | get (display, cr, cg, cb); |
|
|
511 | fadeto.get(display, fcr, fcg, fcb); |
|
|
512 | |
|
|
513 | faded.set ( |
|
|
514 | display, |
|
|
515 | LERP (cr, fcr, percent), |
|
|
516 | LERP (cg, fcg, percent), |
|
|
517 | LERP (cb, fcb, percent) |
|
|
518 | ); |
|
|
519 | |
|
|
520 | return faded; |
|
|
521 | } |
|
|
522 | |