… | |
… | |
64 | #endif |
64 | #endif |
65 | #if USE_XIM |
65 | #if USE_XIM |
66 | "WM_LOCALE_NAME", |
66 | "WM_LOCALE_NAME", |
67 | "XIM_SERVERS", |
67 | "XIM_SERVERS", |
68 | #endif |
68 | #endif |
69 | #ifdef TRANSPARENT |
69 | #ifdef ENABLE_TRANSPARENCY |
70 | "_XROOTPMAP_ID", |
70 | "_XROOTPMAP_ID", |
71 | "ESETROOT_PMAP_ID", |
71 | "ESETROOT_PMAP_ID", |
72 | #endif |
72 | #endif |
73 | #if ENABLE_XEMBED |
73 | #if ENABLE_XEMBED |
74 | "_XEMBED", |
74 | "_XEMBED", |
… | |
… | |
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 () |
… | |
… | |
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_LOCAL; |
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); |
… | |
… | |
553 | if (xev.type == PropertyNotify |
553 | if (xev.type == PropertyNotify |
554 | && xev.xany.window == root |
554 | && xev.xany.window == root |
555 | && xev.xproperty.atom == xa[XA_XIM_SERVERS]) |
555 | && xev.xproperty.atom == xa[XA_XIM_SERVERS]) |
556 | im_change_check (); |
556 | im_change_check (); |
557 | #endif |
557 | #endif |
|
|
558 | if (xev.type == MappingNotify) |
|
|
559 | XRefreshKeyboardMapping (&xev.xmapping); |
|
|
560 | |
558 | for (int i = xw.size (); i--; ) |
561 | for (int i = xw.size (); i--; ) |
559 | { |
562 | { |
560 | if (!xw[i]) |
563 | if (!xw[i]) |
561 | xw.erase_unordered (i); |
564 | xw.erase_unordered (i); |
562 | else if (xw[i]->window == xev.xany.window) |
565 | else if (xw[i]->window == xev.xany.window) |
… | |
… | |
572 | } |
575 | } |
573 | |
576 | |
574 | void rxvt_display::flush () |
577 | void rxvt_display::flush () |
575 | { |
578 | { |
576 | if (XEventsQueued (dpy, QueuedAlready)) |
579 | if (XEventsQueued (dpy, QueuedAlready)) |
577 | x_cb (x_ev, EVENT_READ); |
580 | x_cb (x_ev, ev::READ); |
578 | |
581 | |
579 | XFlush (dpy); |
582 | XFlush (dpy); |
580 | } |
583 | } |
581 | |
584 | |
582 | void rxvt_display::reg (xevent_watcher *w) |
585 | void rxvt_display::reg (xevent_watcher *w) |
583 | { |
586 | { |
|
|
587 | if (!w->active) |
|
|
588 | { |
584 | xw.push_back (w); |
589 | xw.push_back (w); |
585 | w->active = xw.size (); |
590 | w->active = xw.size (); |
|
|
591 | } |
586 | } |
592 | } |
587 | |
593 | |
588 | void rxvt_display::unreg (xevent_watcher *w) |
594 | void rxvt_display::unreg (xevent_watcher *w) |
589 | { |
595 | { |
590 | if (w->active) |
596 | if (w->active) |
|
|
597 | { |
591 | xw[w->active - 1] = 0; |
598 | xw[w->active - 1] = 0; |
|
|
599 | w->active = 0; |
|
|
600 | } |
592 | } |
601 | } |
593 | |
602 | |
594 | void rxvt_display::set_selection_owner (rxvt_term *owner) |
603 | void rxvt_display::set_selection_owner (rxvt_term *owner) |
595 | { |
604 | { |
596 | if (selection_owner && selection_owner != owner) |
605 | if (selection_owner && selection_owner != owner) |
… | |
… | |
657 | static unsigned int |
666 | static unsigned int |
658 | insert_component (unsigned int value, unsigned int mask, unsigned int shift) |
667 | insert_component (unsigned int value, unsigned int mask, unsigned int shift) |
659 | { |
668 | { |
660 | return (value * (mask + 1) >> 16) << shift; |
669 | return (value * (mask + 1) >> 16) << shift; |
661 | } |
670 | } |
662 | |
671 | |
663 | bool |
672 | bool |
664 | rxvt_color::alloc (rxvt_screen *screen, const rgba &color) |
673 | rxvt_color::alloc (rxvt_screen *screen, const rgba &color) |
665 | { |
674 | { |
666 | #if XFT |
675 | #if XFT |
667 | XRenderPictFormat *format; |
676 | XRenderPictFormat *format; |
… | |
… | |
701 | c.green = color.g; |
710 | c.green = color.g; |
702 | c.blue = color.b; |
711 | c.blue = color.b; |
703 | |
712 | |
704 | if (screen->visual->c_class == TrueColor) |
713 | if (screen->visual->c_class == TrueColor) |
705 | { |
714 | { |
706 | c.pixel = (color.r * (screen->visual->red_mask >> ctz (screen->visual->red_mask )) |
715 | c.pixel = (color.r >> (16 - popcount (screen->visual->red_mask )) << ctz (screen->visual->red_mask )) |
707 | / rgba::MAX_CC) << ctz (screen->visual->red_mask ) |
716 | | (color.g >> (16 - popcount (screen->visual->green_mask)) << ctz (screen->visual->green_mask)) |
708 | | (color.g * (screen->visual->green_mask >> ctz (screen->visual->green_mask)) |
|
|
709 | / rgba::MAX_CC) << ctz (screen->visual->green_mask) |
|
|
710 | | (color.b * (screen->visual->blue_mask >> ctz (screen->visual->blue_mask )) |
717 | | (color.b >> (16 - popcount (screen->visual->blue_mask )) << ctz (screen->visual->blue_mask )); |
711 | / rgba::MAX_CC) << ctz (screen->visual->blue_mask ); |
|
|
712 | |
718 | |
713 | return true; |
719 | return true; |
714 | } |
720 | } |
715 | else if (XAllocColor (screen->dpy, screen->cmap, &c)) |
721 | else if (XAllocColor (screen->dpy, screen->cmap, &c)) |
716 | return true; |
722 | return true; |
… | |
… | |
737 | name += skip; |
743 | name += skip; |
738 | } |
744 | } |
739 | else |
745 | else |
740 | c.a = rgba::MAX_CC; |
746 | c.a = rgba::MAX_CC; |
741 | |
747 | |
|
|
748 | // parse the non-standard "#aarrggbb" format |
|
|
749 | if (name[0] == '#' && strlen (name) == 1+2+2+2+2 && 4 == sscanf (name+1, "%2hx%2hx%2hx%2hx%c", &c.a, &c.r, &c.g, &c.b, &eos)) |
|
|
750 | { |
|
|
751 | if (c.r) |
|
|
752 | c.r = (c.r << 8) | 0x0ff; |
|
|
753 | if (c.g) |
|
|
754 | c.g = (c.g << 8) | 0x0ff; |
|
|
755 | if (c.b) |
|
|
756 | c.b = (c.b << 8) | 0x0ff; |
|
|
757 | if (c.a) |
|
|
758 | c.a = (c.a << 8) | 0x0ff; |
|
|
759 | } |
742 | // parse the non-standard "rgba:rrrr/gggg/bbbb/aaaa" format |
760 | // parse the non-standard "rgba:rrrr/gggg/bbbb/aaaa" format |
743 | 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)) |
744 | { |
762 | { |
745 | XColor xc, xc_exact; |
763 | XColor xc; |
746 | |
764 | |
747 | if (XParseColor (screen->dpy, screen->cmap, name, &xc)) |
765 | if (XParseColor (screen->dpy, screen->cmap, name, &xc)) |
748 | { |
766 | { |
749 | c.r = xc.red; |
767 | c.r = xc.red; |
750 | c.g = xc.green; |
768 | c.g = xc.green; |
… | |
… | |
777 | { |
795 | { |
778 | XColor *colors = new XColor [screen->visual->map_entries]; |
796 | XColor *colors = new XColor [screen->visual->map_entries]; |
779 | |
797 | |
780 | for (int i = 0; i < cmap_size; i++) |
798 | for (int i = 0; i < cmap_size; i++) |
781 | colors [i].pixel = i; |
799 | colors [i].pixel = i; |
782 | |
800 | |
783 | // many kilobytes transfer per colour, but pseudocolor isn't worth |
801 | // many kilobytes transfer per colour, but pseudocolor isn't worth |
784 | // many extra optimisations. |
802 | // many extra optimisations. |
785 | XQueryColors (screen->dpy, screen->cmap, colors, cmap_size); |
803 | XQueryColors (screen->dpy, screen->cmap, colors, cmap_size); |
786 | |
804 | |
787 | int diff = 0x7fffffffUL; |
805 | int diff = 0x7fffffffUL; |
… | |
… | |
800 | } |
818 | } |
801 | } |
819 | } |
802 | |
820 | |
803 | //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", |
804 | // 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); |
805 | |
823 | |
806 | got = alloc (screen, rgba (best->red, best->green, best->blue)); |
824 | got = alloc (screen, rgba (best->red, best->green, best->blue)); |
807 | |
825 | |
808 | delete colors; |
826 | delete [] colors; |
809 | } |
827 | } |
810 | #endif |
828 | #endif |
811 | |
829 | |
812 | return got; |
830 | return got; |
813 | } |
831 | } |
… | |
… | |
838 | color.green = c.g; |
856 | color.green = c.g; |
839 | color.blue = c.b; |
857 | color.blue = c.b; |
840 | color.pixel = (Pixel)*this; |
858 | color.pixel = (Pixel)*this; |
841 | } |
859 | } |
842 | |
860 | |
843 | void |
861 | void |
844 | rxvt_color::free (rxvt_screen *screen) |
862 | rxvt_color::free (rxvt_screen *screen) |
845 | { |
863 | { |
846 | if (screen->visual->c_class == TrueColor) |
864 | if (screen->visual->c_class == TrueColor) |
847 | return; // nothing to do |
865 | return; // nothing to do |
848 | |
866 | |