… | |
… | |
6 | * Copyright (c) 2003-2011 Marc Lehmann <schmorp@schmorp.de> |
6 | * Copyright (c) 2003-2011 Marc Lehmann <schmorp@schmorp.de> |
7 | * Copyright (c) 2011 Emanuele Giaquinta <e.giaquinta@glauco.it> |
7 | * Copyright (c) 2011 Emanuele Giaquinta <e.giaquinta@glauco.it> |
8 | * |
8 | * |
9 | * This program is free software; you can redistribute it and/or modify |
9 | * This program is free software; you can redistribute it and/or modify |
10 | * it under the terms of the GNU General Public License as published by |
10 | * it under the terms of the GNU General Public License as published by |
11 | * the Free Software Foundation; either version 2 of the License, or |
11 | * the Free Software Foundation; either version 3 of the License, or |
12 | * (at your option) any later version. |
12 | * (at your option) any later version. |
13 | * |
13 | * |
14 | * This program is distributed in the hope that it will be useful, |
14 | * This program is distributed in the hope that it will be useful, |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
… | |
… | |
66 | #endif |
66 | #endif |
67 | #if USE_XIM |
67 | #if USE_XIM |
68 | "WM_LOCALE_NAME", |
68 | "WM_LOCALE_NAME", |
69 | "XIM_SERVERS", |
69 | "XIM_SERVERS", |
70 | #endif |
70 | #endif |
71 | #ifdef ENABLE_TRANSPARENCY |
71 | #if HAVE_IMG || ENABLE_PERL |
72 | "_XROOTPMAP_ID", |
72 | "_XROOTPMAP_ID", |
73 | "ESETROOT_PMAP_ID", |
73 | "ESETROOT_PMAP_ID", |
74 | #endif |
74 | #endif |
75 | #if ENABLE_XEMBED |
75 | #if ENABLE_XEMBED |
76 | "_XEMBED", |
76 | "_XEMBED", |
… | |
… | |
153 | put (*this->begin ()); |
153 | put (*this->begin ()); |
154 | } |
154 | } |
155 | |
155 | |
156 | ///////////////////////////////////////////////////////////////////////////// |
156 | ///////////////////////////////////////////////////////////////////////////// |
157 | |
157 | |
158 | #ifdef USE_XIM |
158 | #if USE_XIM |
159 | |
159 | |
160 | static void |
160 | static void |
161 | #if XIMCB_PROTO_BROKEN |
161 | #if XIMCB_PROTO_BROKEN |
162 | im_destroy_cb (XIC unused1, XPointer client_data, XPointer unused3) |
162 | im_destroy_cb (XIC unused1, XPointer client_data, XPointer unused3) |
163 | #else |
163 | #else |
… | |
… | |
260 | depth = DefaultDepthOfScreen (screen); |
260 | depth = DefaultDepthOfScreen (screen); |
261 | visual = DefaultVisualOfScreen (screen); |
261 | visual = DefaultVisualOfScreen (screen); |
262 | cmap = DefaultColormapOfScreen (screen); |
262 | cmap = DefaultColormapOfScreen (screen); |
263 | } |
263 | } |
264 | |
264 | |
|
|
265 | #if ENABLE_FRILLS |
|
|
266 | |
265 | void |
267 | void |
266 | rxvt_screen::select_visual (int bitdepth) |
268 | rxvt_screen::select_visual (int id) |
267 | { |
269 | { |
268 | #if XFT |
|
|
269 | XVisualInfo vinfo; |
270 | XVisualInfo vinfo; |
|
|
271 | vinfo.visualid = id; |
|
|
272 | int n; |
|
|
273 | |
|
|
274 | if (XVisualInfo *vi = XGetVisualInfo (dpy, VisualIDMask, &vinfo, &n)) |
|
|
275 | { |
|
|
276 | depth = vi->depth; |
|
|
277 | visual = vi->visual; |
|
|
278 | |
|
|
279 | XFree (vi); |
|
|
280 | |
|
|
281 | cmap = XCreateColormap (dpy, display->root, visual, AllocNone); |
|
|
282 | } |
|
|
283 | else |
|
|
284 | rxvt_warn ("no visual found for requested id 0x%02x, using default visual.\n", id); |
|
|
285 | } |
|
|
286 | |
|
|
287 | void |
|
|
288 | rxvt_screen::select_depth (int bitdepth) |
|
|
289 | { |
|
|
290 | XVisualInfo vinfo; |
270 | |
291 | |
271 | if (XMatchVisualInfo (dpy, display->screen, bitdepth, TrueColor, &vinfo)) |
292 | if (XMatchVisualInfo (dpy, display->screen, bitdepth, TrueColor, &vinfo)) |
272 | { |
|
|
273 | depth = bitdepth; |
|
|
274 | visual = vinfo.visual; |
293 | select_visual (vinfo.visualid); |
275 | cmap = XCreateColormap (dpy, display->root, visual, AllocNone); |
294 | else |
276 | } |
295 | rxvt_warn ("no visual found for requested depth %d, using default visual.\n", bitdepth); |
277 | #endif |
|
|
278 | } |
296 | } |
|
|
297 | |
|
|
298 | #endif |
279 | |
299 | |
280 | void |
300 | void |
281 | rxvt_screen::clear () |
301 | rxvt_screen::clear () |
282 | { |
302 | { |
283 | #if XFT |
303 | #if XFT |
… | |
… | |
430 | bool rxvt_display::ref_init () |
450 | bool rxvt_display::ref_init () |
431 | { |
451 | { |
432 | #ifdef LOCAL_X_IS_UNIX |
452 | #ifdef LOCAL_X_IS_UNIX |
433 | if (id[0] == ':') |
453 | if (id[0] == ':') |
434 | { |
454 | { |
435 | if (!(val = rxvt_temp_buf<char> (5 + strlen (id) + 1))) |
455 | char *val = rxvt_temp_buf<char> (5 + strlen (id) + 1); |
436 | return false; |
456 | |
437 | strcpy (val, "unix/"); |
457 | strcpy (val, "unix/"); |
438 | strcat (val, id); |
458 | strcat (val, id); |
|
|
459 | |
439 | dpy = XOpenDisplay (val); |
460 | dpy = XOpenDisplay (val); |
440 | } |
461 | } |
441 | else |
462 | else |
442 | #endif |
463 | #endif |
443 | dpy = 0; |
464 | dpy = 0; |
… | |
… | |
449 | return false; |
470 | return false; |
450 | |
471 | |
451 | screen = DefaultScreen (dpy); |
472 | screen = DefaultScreen (dpy); |
452 | root = DefaultRootWindow (dpy); |
473 | root = DefaultRootWindow (dpy); |
453 | |
474 | |
454 | assert (ARRAY_LENGTH(xa_names) == NUM_XA); |
475 | assert (ecb_array_length (xa_names) == NUM_XA); |
455 | XInternAtoms (dpy, (char **)xa_names, NUM_XA, False, xa); |
476 | XInternAtoms (dpy, (char **)xa_names, NUM_XA, False, xa); |
456 | |
477 | |
457 | XrmSetDatabase (dpy, get_resources (false)); |
478 | XrmSetDatabase (dpy, get_resources (false)); |
458 | |
479 | |
459 | #ifdef POINTER_BLANK |
480 | #ifdef POINTER_BLANK |
… | |
… | |
465 | blank_cursor = XCreateGlyphCursor (dpy, f, f, ' ', ' ', |
486 | blank_cursor = XCreateGlyphCursor (dpy, f, f, ' ', ' ', |
466 | &blackcolour, &blackcolour); |
487 | &blackcolour, &blackcolour); |
467 | XUnloadFont (dpy, f); |
488 | XUnloadFont (dpy, f); |
468 | #endif |
489 | #endif |
469 | |
490 | |
|
|
491 | flags = 0; |
|
|
492 | #if XRENDER |
|
|
493 | int major, minor; |
|
|
494 | if (XRenderQueryVersion (dpy, &major, &minor)) |
|
|
495 | if (major > 0 || (major == 0 && minor >= 10)) |
|
|
496 | { |
|
|
497 | flags |= DISPLAY_HAS_RENDER; |
|
|
498 | |
|
|
499 | #if 0 |
|
|
500 | if (major > 0 || (major == 0 && minor >= 11)) |
|
|
501 | flags |= DISPLAY_HAS_RENDER_MUL; |
|
|
502 | #endif |
|
|
503 | |
|
|
504 | if (XFilters *filters = XRenderQueryFilters (dpy, root)) |
|
|
505 | { |
|
|
506 | for (int i = 0; i < filters->nfilter; i++) |
|
|
507 | if (!strcmp (filters->filter [i], FilterConvolution)) |
|
|
508 | flags |= DISPLAY_HAS_RENDER_CONV; |
|
|
509 | |
|
|
510 | XFree (filters); |
|
|
511 | } |
|
|
512 | } |
|
|
513 | #endif |
|
|
514 | |
470 | int fd = XConnectionNumber (dpy); |
515 | int fd = XConnectionNumber (dpy); |
471 | |
516 | |
472 | // try to detect whether we have a local connection. |
517 | // try to detect whether we have a local connection. |
473 | // assume unix domain socket == local, everything else not |
518 | // assume unix domain socket == local, everything else not |
474 | // TODO: might want to check for inet/127.0.0.1 |
519 | // TODO: might want to check for inet/127.0.0.1 |
… | |
… | |
511 | #ifdef POINTER_BLANK |
556 | #ifdef POINTER_BLANK |
512 | XFreeCursor (dpy, blank_cursor); |
557 | XFreeCursor (dpy, blank_cursor); |
513 | #endif |
558 | #endif |
514 | x_ev.stop (); |
559 | x_ev.stop (); |
515 | flush_ev.stop (); |
560 | flush_ev.stop (); |
516 | #ifdef USE_XIM |
561 | #if USE_XIM |
517 | xims.clear (); |
562 | xims.clear (); |
518 | #endif |
563 | #endif |
519 | XrmDestroyDatabase (XrmGetDatabase (dpy)); |
564 | XrmDestroyDatabase (XrmGetDatabase (dpy)); |
520 | XCloseDisplay (dpy); |
565 | XCloseDisplay (dpy); |
521 | } |
566 | } |
522 | |
567 | |
523 | #ifdef USE_XIM |
568 | #if USE_XIM |
524 | void rxvt_display::im_change_cb () |
569 | void rxvt_display::im_change_cb () |
525 | { |
570 | { |
526 | for (im_watcher **i = imw.begin (); i != imw.end (); ++i) |
571 | for (im_watcher **i = imw.begin (); i != imw.end (); ++i) |
527 | (*i)->call (); |
572 | (*i)->call (); |
528 | } |
573 | } |
… | |
… | |
564 | do |
609 | do |
565 | { |
610 | { |
566 | XEvent xev; |
611 | XEvent xev; |
567 | XNextEvent (dpy, &xev); |
612 | XNextEvent (dpy, &xev); |
568 | |
613 | |
569 | #ifdef USE_XIM |
614 | #if USE_XIM |
570 | if (!XFilterEvent (&xev, None)) |
615 | if (!XFilterEvent (&xev, None)) |
571 | { |
616 | { |
572 | if (xev.type == PropertyNotify |
617 | if (xev.type == PropertyNotify |
573 | && xev.xany.window == root |
618 | && xev.xany.window == root |
574 | && xev.xproperty.atom == xa[XA_XIM_SERVERS]) |
619 | && xev.xproperty.atom == xa[XA_XIM_SERVERS]) |
… | |
… | |
582 | if (!xw[i]) |
627 | if (!xw[i]) |
583 | xw.erase_unordered (i); |
628 | xw.erase_unordered (i); |
584 | else if (xw[i]->window == xev.xany.window) |
629 | else if (xw[i]->window == xev.xany.window) |
585 | xw[i]->call (xev); |
630 | xw[i]->call (xev); |
586 | } |
631 | } |
587 | #ifdef USE_XIM |
632 | #if USE_XIM |
588 | } |
633 | } |
589 | #endif |
634 | #endif |
590 | } |
635 | } |
591 | while (XEventsQueued (dpy, QueuedAlready)); |
636 | while (XEventsQueued (dpy, QueuedAlready)); |
592 | |
637 | |
… | |
… | |
623 | } |
668 | } |
624 | |
669 | |
625 | cur_owner = owner; |
670 | cur_owner = owner; |
626 | } |
671 | } |
627 | |
672 | |
628 | #ifdef USE_XIM |
673 | #if USE_XIM |
629 | |
674 | |
630 | void rxvt_display::reg (im_watcher *w) |
675 | void rxvt_display::reg (im_watcher *w) |
631 | { |
676 | { |
632 | imw.push_back (w); |
677 | imw.push_back (w); |
633 | } |
678 | } |
… | |
… | |
668 | Atom rxvt_display::atom (const char *name) |
713 | Atom rxvt_display::atom (const char *name) |
669 | { |
714 | { |
670 | return XInternAtom (dpy, name, False); |
715 | return XInternAtom (dpy, name, False); |
671 | } |
716 | } |
672 | |
717 | |
|
|
718 | Pixmap |
|
|
719 | rxvt_display::get_pixmap_property (Atom property) |
|
|
720 | { |
|
|
721 | Pixmap pixmap = None; |
|
|
722 | |
|
|
723 | int aformat; |
|
|
724 | unsigned long nitems, bytes_after; |
|
|
725 | Atom atype; |
|
|
726 | unsigned char *prop; |
|
|
727 | int result = XGetWindowProperty (dpy, root, property, |
|
|
728 | 0L, 1L, False, XA_PIXMAP, &atype, &aformat, |
|
|
729 | &nitems, &bytes_after, &prop); |
|
|
730 | if (result == Success) |
|
|
731 | { |
|
|
732 | if (atype == XA_PIXMAP) |
|
|
733 | pixmap = *(Pixmap *)prop; |
|
|
734 | XFree (prop); |
|
|
735 | } |
|
|
736 | |
|
|
737 | return pixmap; |
|
|
738 | } |
|
|
739 | |
673 | ///////////////////////////////////////////////////////////////////////////// |
740 | ///////////////////////////////////////////////////////////////////////////// |
674 | |
741 | |
675 | template class refcache<rxvt_display>; |
742 | template class refcache<rxvt_display>; |
676 | refcache<rxvt_display> displays; |
743 | refcache<rxvt_display> displays; |
677 | |
744 | |
… | |
… | |
686 | |
753 | |
687 | bool |
754 | bool |
688 | rxvt_color::alloc (rxvt_screen *screen, const rgba &color) |
755 | rxvt_color::alloc (rxvt_screen *screen, const rgba &color) |
689 | { |
756 | { |
690 | //TODO: only supports 24 bit |
757 | //TODO: only supports 24 bit |
691 | int alpha = color.a >= 0xff00 ? 0xffff : color.a; |
758 | unsigned int alpha = color.a >= 0xff00 ? 0xffff : color.a; |
692 | |
759 | |
693 | #if XFT |
760 | #if XFT |
694 | XRenderPictFormat *format; |
761 | XRenderPictFormat *format; |
695 | |
762 | |
696 | // FUCKING Xft gets it wrong, of course, so work around it. |
763 | // FUCKING Xft gets it wrong, of course, so work around it. |
… | |
… | |
703 | c.color.red = color.r; |
770 | c.color.red = color.r; |
704 | c.color.green = color.g; |
771 | c.color.green = color.g; |
705 | c.color.blue = color.b; |
772 | c.color.blue = color.b; |
706 | c.color.alpha = alpha; |
773 | c.color.alpha = alpha; |
707 | |
774 | |
|
|
775 | // Xft wants premultiplied alpha, but abuses the alpha channel |
|
|
776 | // as blend factor, and doesn't allow us to set the alpha channel |
|
|
777 | c.color.red = c.color.red * alpha / 0xffff; |
|
|
778 | c.color.green = c.color.green * alpha / 0xffff; |
|
|
779 | c.color.blue = c.color.blue * alpha / 0xffff; |
|
|
780 | |
708 | c.pixel = insert_component (color.r, format->direct.redMask , format->direct.red ) |
781 | c.pixel = insert_component (c.color.red , format->direct.redMask , format->direct.red ) |
709 | | insert_component (color.g, format->direct.greenMask, format->direct.green) |
782 | | insert_component (c.color.green, format->direct.greenMask, format->direct.green) |
710 | | insert_component (color.b, format->direct.blueMask , format->direct.blue ) |
783 | | insert_component (c.color.blue , format->direct.blueMask , format->direct.blue ) |
711 | | insert_component (alpha , format->direct.alphaMask, format->direct.alpha); |
784 | | insert_component (alpha , format->direct.alphaMask, format->direct.alpha); |
712 | |
785 | |
713 | return true; |
786 | return true; |
714 | } |
787 | } |
715 | else |
788 | else |
716 | { |
789 | { |
… | |
… | |
719 | d.red = color.r; |
792 | d.red = color.r; |
720 | d.green = color.g; |
793 | d.green = color.g; |
721 | d.blue = color.b; |
794 | d.blue = color.b; |
722 | d.alpha = alpha; |
795 | d.alpha = alpha; |
723 | |
796 | |
724 | return XftColorAllocValue (screen->dpy, screen->visual, screen->cmap, &d, &c); |
797 | if (XftColorAllocValue (screen->dpy, screen->visual, screen->cmap, &d, &c)) |
|
|
798 | return true; |
725 | } |
799 | } |
726 | #else |
800 | #else |
727 | c.red = color.r; |
801 | c.red = color.r; |
728 | c.green = color.g; |
802 | c.green = color.g; |
729 | c.blue = color.b; |
803 | c.blue = color.b; |
730 | |
804 | |
731 | if (screen->visual->c_class == TrueColor) |
805 | if (screen->visual->c_class == TrueColor) |
732 | { |
806 | { |
733 | c.pixel = (color.r >> (16 - rxvt_popcount (screen->visual->red_mask )) << rxvt_ctz (screen->visual->red_mask )) |
807 | c.pixel = (color.r >> (16 - ecb_popcount32 (screen->visual->red_mask )) << ecb_ctz32 (screen->visual->red_mask )) |
734 | | (color.g >> (16 - rxvt_popcount (screen->visual->green_mask)) << rxvt_ctz (screen->visual->green_mask)) |
808 | | (color.g >> (16 - ecb_popcount32 (screen->visual->green_mask)) << ecb_ctz32 (screen->visual->green_mask)) |
735 | | (color.b >> (16 - rxvt_popcount (screen->visual->blue_mask )) << rxvt_ctz (screen->visual->blue_mask )); |
809 | | (color.b >> (16 - ecb_popcount32 (screen->visual->blue_mask )) << ecb_ctz32 (screen->visual->blue_mask )); |
736 | |
810 | |
737 | return true; |
811 | return true; |
738 | } |
812 | } |
739 | else if (XAllocColor (screen->dpy, screen->cmap, &c)) |
813 | else if (XAllocColor (screen->dpy, screen->cmap, &c)) |
740 | return true; |
814 | return true; |
741 | else |
815 | #endif |
|
|
816 | |
742 | c.pixel = (color.r + color.g + color.b) > 128*3 |
817 | c.pixel = (color.r + color.g + color.b) > 128*3 |
743 | ? WhitePixelOfScreen (DefaultScreenOfDisplay (screen->dpy)) |
818 | ? WhitePixelOfScreen (DefaultScreenOfDisplay (screen->dpy)) |
744 | : BlackPixelOfScreen (DefaultScreenOfDisplay (screen->dpy)); |
819 | : BlackPixelOfScreen (DefaultScreenOfDisplay (screen->dpy)); |
745 | #endif |
|
|
746 | |
820 | |
747 | return false; |
821 | return false; |
748 | } |
822 | } |
749 | |
823 | |
750 | bool |
824 | bool |
… | |
… | |
835 | |
909 | |
836 | return got; |
910 | return got; |
837 | } |
911 | } |
838 | |
912 | |
839 | void |
913 | void |
840 | rxvt_color::get (rgba &color) |
914 | rxvt_color::get (rgba &color) const |
841 | { |
915 | { |
842 | #if XFT |
916 | #if XFT |
843 | color.r = c.color.red; |
917 | color.r = c.color.red; |
844 | color.g = c.color.green; |
918 | color.g = c.color.green; |
845 | color.b = c.color.blue; |
919 | color.b = c.color.blue; |
… | |
… | |
851 | color.a = rgba::MAX_CC; |
925 | color.a = rgba::MAX_CC; |
852 | #endif |
926 | #endif |
853 | } |
927 | } |
854 | |
928 | |
855 | void |
929 | void |
856 | rxvt_color::get (XColor &color) |
930 | rxvt_color::get (XColor &color) const |
857 | { |
931 | { |
858 | rgba c; |
932 | rgba c; |
859 | get (c); |
933 | get (c); |
860 | |
934 | |
861 | color.red = c.r; |
935 | color.red = c.r; |
… | |
… | |
905 | |
979 | |
906 | incr_buf = 0; |
980 | incr_buf = 0; |
907 | incr_buf_size = incr_buf_fill = 0; |
981 | incr_buf_size = incr_buf_fill = 0; |
908 | selection_wait = Sel_normal; |
982 | selection_wait = Sel_normal; |
909 | selection_type = selnum; |
983 | selection_type = selnum; |
|
|
984 | cb_sv = 0; |
910 | } |
985 | } |
911 | |
986 | |
912 | void |
987 | void |
913 | rxvt_selection::stop () |
988 | rxvt_selection::stop () |
914 | { |
989 | { |
… | |
… | |
954 | } |
1029 | } |
955 | |
1030 | |
956 | void |
1031 | void |
957 | rxvt_selection::finish (char *data, unsigned int len) |
1032 | rxvt_selection::finish (char *data, unsigned int len) |
958 | { |
1033 | { |
959 | if (term) |
1034 | if (!cb_sv) |
960 | { |
1035 | { |
961 | if (data) |
1036 | if (data) |
962 | term->paste (data, len); |
1037 | term->paste (data, len); |
963 | |
1038 | |
964 | term->selection_req = 0; |
1039 | term->selection_req = 0; |
… | |
… | |
1171 | handle_selection (xev.xproperty.window, xev.xproperty.atom, true); |
1246 | handle_selection (xev.xproperty.window, xev.xproperty.atom, true); |
1172 | break; |
1247 | break; |
1173 | |
1248 | |
1174 | case SelectionNotify: |
1249 | case SelectionNotify: |
1175 | if (selection_wait == Sel_normal |
1250 | if (selection_wait == Sel_normal |
1176 | && xev.xselection.time == request_time |
1251 | && xev.xselection.time == request_time) |
1177 | && xev.xselection.property == request_prop) |
|
|
1178 | { |
1252 | { |
1179 | timer_ev.stop (); |
1253 | timer_ev.stop (); |
1180 | handle_selection (xev.xselection.requestor, xev.xselection.property, true); |
1254 | handle_selection (xev.xselection.requestor, xev.xselection.property, true); |
1181 | } |
1255 | } |
1182 | break; |
1256 | break; |