… | |
… | |
32 | #ifndef NO_SLOW_LINK_SUPPORT |
32 | #ifndef NO_SLOW_LINK_SUPPORT |
33 | # include <sys/socket.h> |
33 | # include <sys/socket.h> |
34 | # include <sys/un.h> |
34 | # include <sys/un.h> |
35 | #endif |
35 | #endif |
36 | |
36 | |
|
|
37 | const char *const xa_names[] = |
|
|
38 | { |
|
|
39 | "TEXT", |
|
|
40 | "COMPOUND_TEXT", |
|
|
41 | "UTF8_STRING", |
|
|
42 | "MULTIPLE", |
|
|
43 | "TARGETS", |
|
|
44 | "TIMESTAMP", |
|
|
45 | "VT_SELECTION", |
|
|
46 | "INCR", |
|
|
47 | "WM_PROTOCOLS", |
|
|
48 | "WM_DELETE_WINDOW", |
|
|
49 | "CLIPBOARD", |
|
|
50 | #if ENABLE_FRILLS |
|
|
51 | "_MOTIF_WM_HINTS", |
|
|
52 | #endif |
|
|
53 | #if ENABLE_EWMH |
|
|
54 | "_NET_WM_PID", |
|
|
55 | "_NET_WM_NAME", |
|
|
56 | "_NET_WM_ICON_NAME", |
|
|
57 | "_NET_WM_PING", |
|
|
58 | #endif |
|
|
59 | #if USE_XIM |
|
|
60 | "WM_LOCALE_NAME", |
|
|
61 | "XIM_SERVERS", |
|
|
62 | #endif |
|
|
63 | #ifdef TRANSPARENT |
|
|
64 | "_XROOTPMAP_ID", |
|
|
65 | "ESETROOT_PMAP_ID", |
|
|
66 | #endif |
|
|
67 | #if ENABLE_XEMBED |
|
|
68 | "_XEMBED", |
|
|
69 | "_XEMBED_INFO", |
|
|
70 | #endif |
|
|
71 | }; |
|
|
72 | |
|
|
73 | ///////////////////////////////////////////////////////////////////////////// |
|
|
74 | |
37 | refcounted::refcounted (const char *id) |
75 | refcounted::refcounted (const char *id) |
38 | { |
76 | { |
39 | this->id = strdup (id); |
77 | this->id = strdup (id); |
40 | } |
78 | } |
41 | |
79 | |
… | |
… | |
93 | } |
131 | } |
94 | |
132 | |
95 | ///////////////////////////////////////////////////////////////////////////// |
133 | ///////////////////////////////////////////////////////////////////////////// |
96 | |
134 | |
97 | #ifdef USE_XIM |
135 | #ifdef USE_XIM |
|
|
136 | |
98 | static void |
137 | static void |
99 | #if XIMCB_PROTO_BROKEN |
138 | #if XIMCB_PROTO_BROKEN |
100 | im_destroy_cb (XIC unused1, XPointer client_data, XPointer unused3) |
139 | im_destroy_cb (XIC unused1, XPointer client_data, XPointer unused3) |
101 | #else |
140 | #else |
102 | im_destroy_cb (XIM unused1, XPointer client_data, XPointer unused3) |
141 | im_destroy_cb (XIM unused1, XPointer client_data, XPointer unused3) |
… | |
… | |
133 | rxvt_xim::~rxvt_xim () |
172 | rxvt_xim::~rxvt_xim () |
134 | { |
173 | { |
135 | if (xim) |
174 | if (xim) |
136 | XCloseIM (xim); |
175 | XCloseIM (xim); |
137 | } |
176 | } |
|
|
177 | |
138 | #endif |
178 | #endif |
|
|
179 | |
|
|
180 | ///////////////////////////////////////////////////////////////////////////// |
|
|
181 | |
|
|
182 | void |
|
|
183 | rxvt_screen::set (rxvt_display *disp) |
|
|
184 | { |
|
|
185 | display = disp; |
|
|
186 | |
|
|
187 | xdisp = disp->display; |
|
|
188 | |
|
|
189 | Screen *screen = ScreenOfDisplay (xdisp, disp->screen); |
|
|
190 | |
|
|
191 | depth = DefaultDepthOfScreen (screen); |
|
|
192 | visual = DefaultVisualOfScreen (screen); |
|
|
193 | cmap = DefaultColormapOfScreen (screen); |
|
|
194 | } |
|
|
195 | |
|
|
196 | void |
|
|
197 | rxvt_screen::set (rxvt_display *disp, int depth) |
|
|
198 | { |
|
|
199 | set (disp); |
|
|
200 | |
|
|
201 | XVisualInfo vinfo; |
|
|
202 | |
|
|
203 | if (XMatchVisualInfo (xdisp, display->screen, depth, TrueColor, &vinfo)) |
|
|
204 | { |
|
|
205 | this->depth = depth; |
|
|
206 | this->visual = vinfo.visual; |
|
|
207 | this->cmap = XCreateColormap (xdisp, disp->root, visual, AllocNone); |
|
|
208 | } |
|
|
209 | } |
|
|
210 | |
|
|
211 | void |
|
|
212 | rxvt_screen::clear () |
|
|
213 | { |
|
|
214 | if (cmap != DefaultColormapOfScreen (ScreenOfDisplay (xdisp, display->screen))) |
|
|
215 | XFreeColormap (xdisp, cmap); |
|
|
216 | } |
139 | |
217 | |
140 | ///////////////////////////////////////////////////////////////////////////// |
218 | ///////////////////////////////////////////////////////////////////////////// |
141 | |
219 | |
142 | rxvt_display::rxvt_display (const char *id) |
220 | rxvt_display::rxvt_display (const char *id) |
143 | : refcounted (id) |
221 | : refcounted (id) |
… | |
… | |
247 | if (!display) |
325 | if (!display) |
248 | return false; |
326 | return false; |
249 | |
327 | |
250 | screen = DefaultScreen (display); |
328 | screen = DefaultScreen (display); |
251 | root = DefaultRootWindow (display); |
329 | root = DefaultRootWindow (display); |
252 | visual = DefaultVisual (display, screen); |
330 | |
253 | cmap = DefaultColormap (display, screen); |
331 | assert (sizeof (xa_names) / sizeof (char *) == NUM_XA); |
254 | depth = DefaultDepth (display, screen); |
332 | XInternAtoms (display, (char **)xa_names, NUM_XA, False, xa); |
255 | |
333 | |
256 | XrmSetDatabase (display, get_resources ()); |
334 | XrmSetDatabase (display, get_resources ()); |
257 | |
335 | |
258 | #ifdef POINTER_BLANK |
336 | #ifdef POINTER_BLANK |
259 | XColor blackcolour; |
337 | XColor blackcolour; |
… | |
… | |
264 | blank_cursor = XCreateGlyphCursor (display, f, f, ' ', ' ', |
342 | blank_cursor = XCreateGlyphCursor (display, f, f, ' ', ' ', |
265 | &blackcolour, &blackcolour); |
343 | &blackcolour, &blackcolour); |
266 | XUnloadFont (display, f); |
344 | XUnloadFont (display, f); |
267 | #endif |
345 | #endif |
268 | |
346 | |
269 | #ifdef PREFER_24BIT |
|
|
270 | /* |
|
|
271 | * If depth is not 24, look for a 24bit visual. |
|
|
272 | */ |
|
|
273 | if (depth != 24) |
|
|
274 | { |
|
|
275 | XVisualInfo vinfo; |
|
|
276 | |
|
|
277 | if (XMatchVisualInfo (display, screen, 24, TrueColor, &vinfo)) |
|
|
278 | { |
|
|
279 | depth = 24; |
|
|
280 | visual = vinfo.visual; |
|
|
281 | cmap = XCreateColormap (display, |
|
|
282 | RootWindow (display, screen), |
|
|
283 | visual, AllocNone); |
|
|
284 | } |
|
|
285 | } |
|
|
286 | #endif |
|
|
287 | |
|
|
288 | int fd = XConnectionNumber (display); |
347 | int fd = XConnectionNumber (display); |
289 | |
348 | |
290 | #ifndef NO_SLOW_LINK_SUPPORT |
349 | #ifndef NO_SLOW_LINK_SUPPORT |
291 | // try to detect wether we have a local connection. |
350 | // try to detect wether we have a local connection. |
292 | // assume unix domains socket == local, everything else not |
351 | // assume unix domains socket == local, everything else not |
… | |
… | |
301 | |
360 | |
302 | x_ev.start (fd, EVENT_READ); |
361 | x_ev.start (fd, EVENT_READ); |
303 | fcntl (fd, F_SETFD, FD_CLOEXEC); |
362 | fcntl (fd, F_SETFD, FD_CLOEXEC); |
304 | |
363 | |
305 | XSelectInput (display, root, PropertyChangeMask); |
364 | XSelectInput (display, root, PropertyChangeMask); |
306 | #ifdef USE_XIM |
|
|
307 | xa_xim_servers = XInternAtom (display, "XIM_SERVERS", 0); |
|
|
308 | #endif |
|
|
309 | |
365 | |
310 | flush (); |
366 | flush (); |
311 | |
367 | |
312 | return true; |
368 | return true; |
313 | } |
369 | } |
… | |
… | |
349 | // registers, as xlib crashes due to a race otherwise. |
405 | // registers, as xlib crashes due to a race otherwise. |
350 | Atom actual_type, *atoms; |
406 | Atom actual_type, *atoms; |
351 | int actual_format; |
407 | int actual_format; |
352 | unsigned long nitems, bytes_after; |
408 | unsigned long nitems, bytes_after; |
353 | |
409 | |
354 | if (XGetWindowProperty (display, root, xa_xim_servers, 0L, 1000000L, |
410 | if (XGetWindowProperty (display, root, xa[XA_XIM_SERVERS], 0L, 1000000L, |
355 | False, XA_ATOM, &actual_type, &actual_format, |
411 | False, XA_ATOM, &actual_type, &actual_format, |
356 | &nitems, &bytes_after, (unsigned char **)&atoms) |
412 | &nitems, &bytes_after, (unsigned char **)&atoms) |
357 | != Success ) |
413 | != Success ) |
358 | return; |
414 | return; |
359 | |
415 | |
… | |
… | |
379 | #ifdef USE_XIM |
435 | #ifdef USE_XIM |
380 | if (!XFilterEvent (&xev, None)) |
436 | if (!XFilterEvent (&xev, None)) |
381 | { |
437 | { |
382 | if (xev.type == PropertyNotify |
438 | if (xev.type == PropertyNotify |
383 | && xev.xany.window == root |
439 | && xev.xany.window == root |
384 | && xev.xproperty.atom == xa_xim_servers) |
440 | && xev.xproperty.atom == xa[XA_XIM_SERVERS]) |
385 | im_change_check (); |
441 | im_change_check (); |
386 | #endif |
442 | #endif |
387 | for (int i = xw.size (); i--; ) |
443 | for (int i = xw.size (); i--; ) |
388 | { |
444 | { |
389 | if (!xw[i]) |
445 | if (!xw[i]) |
… | |
… | |
479 | refcache<rxvt_display> displays; |
535 | refcache<rxvt_display> displays; |
480 | |
536 | |
481 | ///////////////////////////////////////////////////////////////////////////// |
537 | ///////////////////////////////////////////////////////////////////////////// |
482 | |
538 | |
483 | bool |
539 | bool |
484 | rxvt_color::set (rxvt_display *display, Pixel p) |
540 | rxvt_color::set (rxvt_screen *screen, Pixel p) |
485 | { |
541 | { |
486 | #if XFT |
542 | #if XFT |
487 | XColor xc; |
543 | XColor xc; |
488 | |
544 | |
489 | xc.pixel = p; |
545 | xc.pixel = p; |
490 | if (!XQueryColor (display->display, display->cmap, &xc)) |
546 | if (!XQueryColor (screen->xdisp, screen->cmap, &xc)) |
491 | return false; |
547 | return false; |
492 | |
548 | |
493 | XRenderColor d; |
549 | XRenderColor d; |
494 | |
550 | |
495 | d.red = xc.red; |
551 | d.red = xc.red; |
496 | d.green = xc.green; |
552 | d.green = xc.green; |
497 | d.blue = xc.blue; |
553 | d.blue = xc.blue; |
498 | d.alpha = 0xffff; |
554 | d.alpha = 0xffff; |
499 | |
555 | |
500 | return |
556 | return |
501 | XftColorAllocValue (display->display, |
557 | XftColorAllocValue (screen->xdisp, |
502 | display->visual, |
558 | screen->visual, |
503 | display->cmap, |
559 | screen->cmap, |
504 | &d, &c); |
560 | &d, &c); |
505 | #else |
561 | #else |
506 | this->p = p; |
562 | this->p = p; |
507 | #endif |
563 | #endif |
508 | |
564 | |
509 | return true; |
565 | return true; |
510 | } |
566 | } |
511 | |
567 | |
512 | bool |
568 | bool |
513 | rxvt_color::set (rxvt_display *display, const char *name) |
569 | rxvt_color::set (rxvt_screen *screen, const char *name) |
514 | { |
570 | { |
515 | #if XFT |
571 | #if XFT |
516 | return XftColorAllocName (display->display, display->visual, display->cmap, |
572 | return XftColorAllocName (screen->xdisp, screen->visual, screen->cmap, name, &c); |
517 | name, &c); |
|
|
518 | #else |
573 | #else |
519 | XColor xc; |
574 | XColor xc; |
520 | |
575 | |
521 | if (XParseColor (display->display, display->cmap, name, &xc)) |
576 | if (XParseColor (screen->xdisp, screen->cmap, name, &xc)) |
522 | return set (display, xc.red, xc.green, xc.blue); |
577 | return set (screen, xc.red, xc.green, xc.blue); |
523 | |
578 | |
524 | return false; |
579 | return false; |
525 | #endif |
580 | #endif |
526 | } |
581 | } |
527 | |
582 | |
528 | bool |
583 | bool |
529 | rxvt_color::set (rxvt_display *display, unsigned short cr, unsigned short cg, unsigned short cb) |
584 | rxvt_color::set (rxvt_screen *screen, unsigned short cr, unsigned short cg, unsigned short cb) |
530 | { |
585 | { |
531 | XColor xc; |
586 | XColor xc; |
532 | |
587 | |
533 | xc.red = cr; |
588 | xc.red = cr; |
534 | xc.green = cg; |
589 | xc.green = cg; |
535 | xc.blue = cb; |
590 | xc.blue = cb; |
536 | xc.flags = DoRed | DoGreen | DoBlue; |
591 | xc.flags = DoRed | DoGreen | DoBlue; |
537 | |
592 | |
538 | if (XAllocColor (display->display, display->cmap, &xc)) |
593 | if (XAllocColor (screen->xdisp, screen->cmap, &xc)) |
539 | return set (display, xc.pixel); |
594 | return set (screen, xc.pixel); |
540 | |
595 | |
541 | return false; |
596 | return false; |
542 | } |
597 | } |
543 | |
598 | |
544 | void |
599 | void |
545 | rxvt_color::get (rxvt_display *display, unsigned short &cr, unsigned short &cg, unsigned short &cb) |
600 | rxvt_color::get (rxvt_screen *screen, unsigned short &cr, unsigned short &cg, unsigned short &cb) |
546 | { |
601 | { |
547 | #if XFT |
602 | #if XFT |
548 | cr = c.color.red; |
603 | cr = c.color.red; |
549 | cg = c.color.green; |
604 | cg = c.color.green; |
550 | cb = c.color.blue; |
605 | cb = c.color.blue; |
551 | #else |
606 | #else |
552 | XColor c; |
607 | XColor c; |
553 | |
608 | |
554 | c.pixel = p; |
609 | c.pixel = p; |
555 | XQueryColor (display->display, display->cmap, &c); |
610 | XQueryColor (screen->xdisp, screen->cmap, &c); |
556 | |
611 | |
557 | cr = c.red; |
612 | cr = c.red; |
558 | cg = c.green; |
613 | cg = c.green; |
559 | cb = c.blue; |
614 | cb = c.blue; |
560 | #endif |
615 | #endif |
561 | } |
616 | } |
562 | |
617 | |
563 | void |
618 | void |
564 | rxvt_color::free (rxvt_display *display) |
619 | rxvt_color::free (rxvt_screen *screen) |
565 | { |
620 | { |
566 | #if XFT |
621 | #if XFT |
567 | XftColorFree (display->display, display->visual, display->cmap, &c); |
622 | XftColorFree (screen->xdisp, screen->visual, screen->cmap, &c); |
568 | #else |
623 | #else |
569 | XFreeColors (display->display, display->cmap, &p, 1, AllPlanes); |
624 | XFreeColors (screen->xdisp, screen->cmap, &p, 1, AllPlanes); |
570 | #endif |
625 | #endif |
571 | } |
626 | } |
572 | |
627 | |
573 | rxvt_color |
628 | rxvt_color |
574 | rxvt_color::fade (rxvt_display *display, int percent) |
629 | rxvt_color::fade (rxvt_screen *screen, int percent) |
575 | { |
630 | { |
576 | percent = 100 - percent; |
631 | percent = 100 - percent; |
577 | |
632 | |
578 | unsigned short cr, cg, cb; |
633 | unsigned short cr, cg, cb; |
579 | rxvt_color faded; |
634 | rxvt_color faded; |
580 | |
635 | |
581 | get (display, cr, cg, cb); |
636 | get (screen, cr, cg, cb); |
582 | |
637 | |
583 | faded.set ( |
638 | faded.set ( |
584 | display, |
639 | screen, |
585 | cr * percent / 100, |
640 | cr * percent / 100, |
586 | cg * percent / 100, |
641 | cg * percent / 100, |
587 | cb * percent / 100 |
642 | cb * percent / 100 |
588 | ); |
643 | ); |
589 | |
644 | |
… | |
… | |
591 | } |
646 | } |
592 | |
647 | |
593 | #define LERP(a,b,p) (a * p + b * (100 - p)) / 100 |
648 | #define LERP(a,b,p) (a * p + b * (100 - p)) / 100 |
594 | |
649 | |
595 | rxvt_color |
650 | rxvt_color |
596 | rxvt_color::fade (rxvt_display *display, int percent, rxvt_color &fadeto) |
651 | rxvt_color::fade (rxvt_screen *screen, int percent, rxvt_color &fadeto) |
597 | { |
652 | { |
598 | percent = 100 - percent; |
653 | percent = 100 - percent; |
599 | |
654 | |
600 | unsigned short cr, cg, cb; |
655 | unsigned short cr, cg, cb; |
601 | unsigned short fcr, fcg, fcb; |
656 | unsigned short fcr, fcg, fcb; |
602 | rxvt_color faded; |
657 | rxvt_color faded; |
603 | |
658 | |
604 | get (display, cr, cg, cb); |
659 | get (screen, cr, cg, cb); |
605 | fadeto.get(display, fcr, fcg, fcb); |
660 | fadeto.get (screen, fcr, fcg, fcb); |
606 | |
661 | |
607 | faded.set ( |
662 | faded.set ( |
608 | display, |
663 | screen, |
609 | LERP (cr, fcr, percent), |
664 | LERP (cr, fcr, percent), |
610 | LERP (cg, fcg, percent), |
665 | LERP (cg, fcg, percent), |
611 | LERP (cb, fcb, percent) |
666 | LERP (cb, fcb, percent) |
612 | ); |
667 | ); |
613 | |
668 | |