… | |
… | |
183 | |
183 | |
184 | XIMCallback ximcallback; |
184 | XIMCallback ximcallback; |
185 | ximcallback.client_data = (XPointer)this; |
185 | ximcallback.client_data = (XPointer)this; |
186 | ximcallback.callback = im_destroy_cb; |
186 | ximcallback.callback = im_destroy_cb; |
187 | |
187 | |
188 | XSetIMValues (xim, XNDestroyCallback, &ximcallback, 0); |
188 | XSetIMValues (xim, XNDestroyCallback, &ximcallback, (char *)0); |
189 | |
189 | |
190 | return true; |
190 | return true; |
191 | } |
191 | } |
192 | |
192 | |
193 | rxvt_xim::~rxvt_xim () |
193 | rxvt_xim::~rxvt_xim () |
… | |
… | |
462 | #endif |
462 | #endif |
463 | |
463 | |
464 | int fd = XConnectionNumber (dpy); |
464 | int fd = XConnectionNumber (dpy); |
465 | |
465 | |
466 | // try to detect wether we have a local connection. |
466 | // try to detect wether we have a local connection. |
467 | // assume unix domains socket == local, everything else not |
467 | // assume unix domain socket == local, everything else not |
468 | // TODO: might want to check for inet/127.0.0.1 |
468 | // TODO: might want to check for inet/127.0.0.1 |
469 | is_local = 0; |
469 | is_local = 0; |
470 | sockaddr_un sa; |
470 | sockaddr_un sa; |
471 | socklen_t sl = sizeof (sa); |
471 | socklen_t sl = sizeof (sa); |
472 | |
472 | |
473 | if (!getsockname (fd, (sockaddr *)&sa, &sl)) |
473 | if (!getsockname (fd, (sockaddr *)&sa, &sl)) |
474 | is_local = sa.sun_family == AF_UNIX; |
474 | is_local = sa.sun_family == AF_UNIX; |
475 | |
475 | |
476 | x_ev.start (fd, EVENT_READ); |
476 | x_ev.start (fd, ev::READ); |
477 | fcntl (fd, F_SETFD, FD_CLOEXEC); |
477 | fcntl (fd, F_SETFD, FD_CLOEXEC); |
478 | |
478 | |
479 | XSelectInput (dpy, root, PropertyChangeMask); |
479 | XSelectInput (dpy, root, PropertyChangeMask); |
480 | |
480 | |
481 | flush (); |
481 | flush (); |
… | |
… | |
538 | |
538 | |
539 | XFree (atoms); |
539 | XFree (atoms); |
540 | } |
540 | } |
541 | #endif |
541 | #endif |
542 | |
542 | |
543 | void rxvt_display::x_cb (io_watcher &w, short revents) |
543 | void rxvt_display::x_cb (ev::io &w, int revents) |
544 | { |
544 | { |
545 | do |
545 | do |
546 | { |
546 | { |
547 | XEvent xev; |
547 | XEvent xev; |
548 | XNextEvent (dpy, &xev); |
548 | XNextEvent (dpy, &xev); |
… | |
… | |
575 | } |
575 | } |
576 | |
576 | |
577 | void rxvt_display::flush () |
577 | void rxvt_display::flush () |
578 | { |
578 | { |
579 | if (XEventsQueued (dpy, QueuedAlready)) |
579 | if (XEventsQueued (dpy, QueuedAlready)) |
580 | x_cb (x_ev, EVENT_READ); |
580 | x_cb (x_ev, ev::READ); |
581 | |
581 | |
582 | XFlush (dpy); |
582 | XFlush (dpy); |
583 | } |
583 | } |
584 | |
584 | |
585 | void rxvt_display::reg (xevent_watcher *w) |
585 | void rxvt_display::reg (xevent_watcher *w) |
… | |
… | |
666 | static unsigned int |
666 | static unsigned int |
667 | insert_component (unsigned int value, unsigned int mask, unsigned int shift) |
667 | insert_component (unsigned int value, unsigned int mask, unsigned int shift) |
668 | { |
668 | { |
669 | return (value * (mask + 1) >> 16) << shift; |
669 | return (value * (mask + 1) >> 16) << shift; |
670 | } |
670 | } |
671 | |
671 | |
672 | bool |
672 | bool |
673 | rxvt_color::alloc (rxvt_screen *screen, const rgba &color) |
673 | rxvt_color::alloc (rxvt_screen *screen, const rgba &color) |
674 | { |
674 | { |
675 | #if XFT |
675 | #if XFT |
676 | XRenderPictFormat *format; |
676 | XRenderPictFormat *format; |
… | |
… | |
758 | c.a = (c.a << 8) | 0x0ff; |
758 | c.a = (c.a << 8) | 0x0ff; |
759 | } |
759 | } |
760 | // parse the non-standard "rgba:rrrr/gggg/bbbb/aaaa" format |
760 | // parse the non-standard "rgba:rrrr/gggg/bbbb/aaaa" format |
761 | else if (strlen (name) != 4+5*4 || 4 != sscanf (name, "rgba:%4hx/%4hx/%4hx/%4hx%c", &c.r, &c.g, &c.b, &c.a, &eos)) |
761 | else if (strlen (name) != 4+5*4 || 4 != sscanf (name, "rgba:%4hx/%4hx/%4hx/%4hx%c", &c.r, &c.g, &c.b, &c.a, &eos)) |
762 | { |
762 | { |
763 | XColor xc, xc_exact; |
763 | XColor xc; |
764 | |
764 | |
765 | if (XParseColor (screen->dpy, screen->cmap, name, &xc)) |
765 | if (XParseColor (screen->dpy, screen->cmap, name, &xc)) |
766 | { |
766 | { |
767 | c.r = xc.red; |
767 | c.r = xc.red; |
768 | c.g = xc.green; |
768 | c.g = xc.green; |
… | |
… | |
795 | { |
795 | { |
796 | XColor *colors = new XColor [screen->visual->map_entries]; |
796 | XColor *colors = new XColor [screen->visual->map_entries]; |
797 | |
797 | |
798 | for (int i = 0; i < cmap_size; i++) |
798 | for (int i = 0; i < cmap_size; i++) |
799 | colors [i].pixel = i; |
799 | colors [i].pixel = i; |
800 | |
800 | |
801 | // many kilobytes transfer per colour, but pseudocolor isn't worth |
801 | // many kilobytes transfer per colour, but pseudocolor isn't worth |
802 | // many extra optimisations. |
802 | // many extra optimisations. |
803 | XQueryColors (screen->dpy, screen->cmap, colors, cmap_size); |
803 | XQueryColors (screen->dpy, screen->cmap, colors, cmap_size); |
804 | |
804 | |
805 | int diff = 0x7fffffffUL; |
805 | int diff = 0x7fffffffUL; |
… | |
… | |
818 | } |
818 | } |
819 | } |
819 | } |
820 | |
820 | |
821 | //rxvt_warn ("could not allocate %04x %04x %04x, getting %04x %04x %04x instead (%d)\n", |
821 | //rxvt_warn ("could not allocate %04x %04x %04x, getting %04x %04x %04x instead (%d)\n", |
822 | // color.r, color.g, color.b, best->red, best->green, best->blue, diff); |
822 | // color.r, color.g, color.b, best->red, best->green, best->blue, diff); |
823 | |
823 | |
824 | got = alloc (screen, rgba (best->red, best->green, best->blue)); |
824 | got = alloc (screen, rgba (best->red, best->green, best->blue)); |
825 | |
825 | |
826 | delete [] colors; |
826 | delete [] colors; |
827 | } |
827 | } |
828 | #endif |
828 | #endif |
… | |
… | |
856 | color.green = c.g; |
856 | color.green = c.g; |
857 | color.blue = c.b; |
857 | color.blue = c.b; |
858 | color.pixel = (Pixel)*this; |
858 | color.pixel = (Pixel)*this; |
859 | } |
859 | } |
860 | |
860 | |
861 | void |
861 | void |
862 | rxvt_color::free (rxvt_screen *screen) |
862 | rxvt_color::free (rxvt_screen *screen) |
863 | { |
863 | { |
864 | if (screen->visual->c_class == TrueColor) |
864 | if (screen->visual->c_class == TrueColor) |
865 | return; // nothing to do |
865 | return; // nothing to do |
866 | |
866 | |
… | |
… | |
886 | lerp (c.a, to.a, percent) |
886 | lerp (c.a, to.a, percent) |
887 | ) |
887 | ) |
888 | ); |
888 | ); |
889 | } |
889 | } |
890 | |
890 | |
|
|
891 | #if TRACE_PIXMAPS |
|
|
892 | # undef XCreatePixmap |
|
|
893 | # undef XFreePixmap |
|
|
894 | Pixmap trace_XCreatePixmap (const char *file, int line, Display *dpy, Window r, unsigned int w, unsigned int h, unsigned int d) |
|
|
895 | { |
|
|
896 | Pixmap res = XCreatePixmap (dpy, r, w, h, d); |
|
|
897 | fprintf (stderr, "%s:%d: XCreatePixmap (%p,%lX,%u,%u,%u) returned %lX\n", file, line, dpy, r, w, h, d, res); |
|
|
898 | return res; |
|
|
899 | } |
|
|
900 | |
|
|
901 | void trace_XFreePixmap (const char *file, int line, Display *dpy, Pixmap p) |
|
|
902 | { |
|
|
903 | fprintf (stderr, "%s:%d: XFreePixmap (%p,%lX)\n", file, line, dpy, p); |
|
|
904 | XFreePixmap (dpy,p); |
|
|
905 | } |
|
|
906 | #endif |