… | |
… | |
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 |
… | |
… | |
22 | *----------------------------------------------------------------------*/ |
22 | *----------------------------------------------------------------------*/ |
23 | |
23 | |
24 | #include "../config.h" |
24 | #include "../config.h" |
25 | #include <rxvt.h> |
25 | #include <rxvt.h> |
26 | #include <rxvttoolkit.h> |
26 | #include <rxvttoolkit.h> |
|
|
27 | |
|
|
28 | #include <stdlib.h> |
27 | |
29 | |
28 | #include <unistd.h> |
30 | #include <unistd.h> |
29 | #include <fcntl.h> |
31 | #include <fcntl.h> |
30 | |
32 | |
31 | #include <sys/utsname.h> |
33 | #include <sys/utsname.h> |
… | |
… | |
66 | #endif |
68 | #endif |
67 | #if USE_XIM |
69 | #if USE_XIM |
68 | "WM_LOCALE_NAME", |
70 | "WM_LOCALE_NAME", |
69 | "XIM_SERVERS", |
71 | "XIM_SERVERS", |
70 | #endif |
72 | #endif |
71 | #ifdef ENABLE_TRANSPARENCY |
73 | #if HAVE_IMG || ENABLE_PERL |
72 | "_XROOTPMAP_ID", |
74 | "_XROOTPMAP_ID", |
73 | "ESETROOT_PMAP_ID", |
75 | "ESETROOT_PMAP_ID", |
74 | #endif |
76 | #endif |
75 | #if ENABLE_XEMBED |
77 | #if ENABLE_XEMBED |
76 | "_XEMBED", |
78 | "_XEMBED", |
… | |
… | |
153 | put (*this->begin ()); |
155 | put (*this->begin ()); |
154 | } |
156 | } |
155 | |
157 | |
156 | ///////////////////////////////////////////////////////////////////////////// |
158 | ///////////////////////////////////////////////////////////////////////////// |
157 | |
159 | |
158 | #ifdef USE_XIM |
160 | #if USE_XIM |
159 | |
161 | |
160 | static void |
162 | static void |
161 | #if XIMCB_PROTO_BROKEN |
163 | #if XIMCB_PROTO_BROKEN |
162 | im_destroy_cb (XIC unused1, XPointer client_data, XPointer unused3) |
164 | im_destroy_cb (XIC unused1, XPointer client_data, XPointer unused3) |
163 | #else |
165 | #else |
… | |
… | |
260 | depth = DefaultDepthOfScreen (screen); |
262 | depth = DefaultDepthOfScreen (screen); |
261 | visual = DefaultVisualOfScreen (screen); |
263 | visual = DefaultVisualOfScreen (screen); |
262 | cmap = DefaultColormapOfScreen (screen); |
264 | cmap = DefaultColormapOfScreen (screen); |
263 | } |
265 | } |
264 | |
266 | |
|
|
267 | #if ENABLE_FRILLS |
|
|
268 | |
265 | void |
269 | void |
266 | rxvt_screen::select_visual (int bitdepth) |
270 | rxvt_screen::select_visual (int id) |
267 | { |
271 | { |
268 | #if XFT |
|
|
269 | XVisualInfo vinfo; |
272 | XVisualInfo vinfo; |
|
|
273 | vinfo.visualid = id; |
|
|
274 | int n; |
|
|
275 | |
|
|
276 | if (XVisualInfo *vi = XGetVisualInfo (dpy, VisualIDMask, &vinfo, &n)) |
|
|
277 | { |
|
|
278 | depth = vi->depth; |
|
|
279 | visual = vi->visual; |
|
|
280 | |
|
|
281 | XFree (vi); |
|
|
282 | |
|
|
283 | cmap = XCreateColormap (dpy, display->root, visual, AllocNone); |
|
|
284 | } |
|
|
285 | else |
|
|
286 | rxvt_warn ("no visual found for requested id 0x%02x, using default visual.\n", id); |
|
|
287 | } |
|
|
288 | |
|
|
289 | void |
|
|
290 | rxvt_screen::select_depth (int bitdepth) |
|
|
291 | { |
|
|
292 | XVisualInfo vinfo; |
270 | |
293 | |
271 | if (XMatchVisualInfo (dpy, display->screen, bitdepth, TrueColor, &vinfo)) |
294 | if (XMatchVisualInfo (dpy, display->screen, bitdepth, TrueColor, &vinfo)) |
272 | { |
|
|
273 | depth = bitdepth; |
|
|
274 | visual = vinfo.visual; |
295 | select_visual (vinfo.visualid); |
275 | cmap = XCreateColormap (dpy, display->root, visual, AllocNone); |
296 | else |
276 | } |
297 | rxvt_warn ("no visual found for requested depth %d, using default visual.\n", bitdepth); |
277 | #endif |
|
|
278 | } |
298 | } |
|
|
299 | |
|
|
300 | #endif |
279 | |
301 | |
280 | void |
302 | void |
281 | rxvt_screen::clear () |
303 | rxvt_screen::clear () |
282 | { |
304 | { |
283 | #if XFT |
305 | #if XFT |
… | |
… | |
470 | |
492 | |
471 | flags = 0; |
493 | flags = 0; |
472 | #if XRENDER |
494 | #if XRENDER |
473 | int major, minor; |
495 | int major, minor; |
474 | if (XRenderQueryVersion (dpy, &major, &minor)) |
496 | if (XRenderQueryVersion (dpy, &major, &minor)) |
475 | { |
|
|
476 | flags |= DISPLAY_HAS_RENDER; |
|
|
477 | |
|
|
478 | if (major > 0 || (major == 0 && minor >= 11)) |
497 | if (major > 0 || (major == 0 && minor >= 11)) |
|
|
498 | { |
479 | flags |= DISPLAY_HAS_RENDER_MUL; |
499 | flags |= DISPLAY_HAS_RENDER; |
480 | |
500 | |
481 | XFilters *filters = XRenderQueryFilters (dpy, root); |
501 | if (XFilters *filters = XRenderQueryFilters (dpy, root)) |
482 | if (filters) |
|
|
483 | { |
502 | { |
484 | for (int i = 0; i < filters->nfilter; i++) |
503 | for (int i = 0; i < filters->nfilter; i++) |
485 | if (!strcmp (filters->filter[i], FilterConvolution)) |
504 | if (!strcmp (filters->filter [i], FilterConvolution)) |
486 | flags |= DISPLAY_HAS_RENDER_CONV; |
505 | flags |= DISPLAY_HAS_RENDER_CONV; |
487 | |
506 | |
488 | XFree (filters); |
507 | XFree (filters); |
489 | } |
508 | } |
490 | } |
509 | } |
491 | #endif |
510 | #endif |
492 | |
511 | |
493 | int fd = XConnectionNumber (dpy); |
512 | int fd = XConnectionNumber (dpy); |
494 | |
513 | |
495 | // try to detect whether we have a local connection. |
514 | // try to detect whether we have a local connection. |
… | |
… | |
534 | #ifdef POINTER_BLANK |
553 | #ifdef POINTER_BLANK |
535 | XFreeCursor (dpy, blank_cursor); |
554 | XFreeCursor (dpy, blank_cursor); |
536 | #endif |
555 | #endif |
537 | x_ev.stop (); |
556 | x_ev.stop (); |
538 | flush_ev.stop (); |
557 | flush_ev.stop (); |
539 | #ifdef USE_XIM |
558 | #if USE_XIM |
540 | xims.clear (); |
559 | xims.clear (); |
541 | #endif |
560 | #endif |
542 | XrmDestroyDatabase (XrmGetDatabase (dpy)); |
561 | XrmDestroyDatabase (XrmGetDatabase (dpy)); |
543 | XCloseDisplay (dpy); |
562 | XCloseDisplay (dpy); |
544 | } |
563 | } |
545 | |
564 | |
546 | #ifdef USE_XIM |
565 | #if USE_XIM |
547 | void rxvt_display::im_change_cb () |
566 | void rxvt_display::im_change_cb () |
548 | { |
567 | { |
549 | for (im_watcher **i = imw.begin (); i != imw.end (); ++i) |
568 | for (im_watcher **i = imw.begin (); i != imw.end (); ++i) |
550 | (*i)->call (); |
569 | (*i)->call (); |
551 | } |
570 | } |
… | |
… | |
587 | do |
606 | do |
588 | { |
607 | { |
589 | XEvent xev; |
608 | XEvent xev; |
590 | XNextEvent (dpy, &xev); |
609 | XNextEvent (dpy, &xev); |
591 | |
610 | |
592 | #ifdef USE_XIM |
611 | #if USE_XIM |
593 | if (!XFilterEvent (&xev, None)) |
612 | if (!XFilterEvent (&xev, None)) |
594 | { |
613 | { |
595 | if (xev.type == PropertyNotify |
614 | if (xev.type == PropertyNotify |
596 | && xev.xany.window == root |
615 | && xev.xany.window == root |
597 | && xev.xproperty.atom == xa[XA_XIM_SERVERS]) |
616 | && xev.xproperty.atom == xa[XA_XIM_SERVERS]) |
… | |
… | |
605 | if (!xw[i]) |
624 | if (!xw[i]) |
606 | xw.erase_unordered (i); |
625 | xw.erase_unordered (i); |
607 | else if (xw[i]->window == xev.xany.window) |
626 | else if (xw[i]->window == xev.xany.window) |
608 | xw[i]->call (xev); |
627 | xw[i]->call (xev); |
609 | } |
628 | } |
610 | #ifdef USE_XIM |
629 | #if USE_XIM |
611 | } |
630 | } |
612 | #endif |
631 | #endif |
613 | } |
632 | } |
614 | while (XEventsQueued (dpy, QueuedAlready)); |
633 | while (XEventsQueued (dpy, QueuedAlready)); |
615 | |
634 | |
… | |
… | |
646 | } |
665 | } |
647 | |
666 | |
648 | cur_owner = owner; |
667 | cur_owner = owner; |
649 | } |
668 | } |
650 | |
669 | |
651 | #ifdef USE_XIM |
670 | #if USE_XIM |
652 | |
671 | |
653 | void rxvt_display::reg (im_watcher *w) |
672 | void rxvt_display::reg (im_watcher *w) |
654 | { |
673 | { |
655 | imw.push_back (w); |
674 | imw.push_back (w); |
656 | } |
675 | } |
… | |
… | |
689 | #endif |
708 | #endif |
690 | |
709 | |
691 | Atom rxvt_display::atom (const char *name) |
710 | Atom rxvt_display::atom (const char *name) |
692 | { |
711 | { |
693 | return XInternAtom (dpy, name, False); |
712 | return XInternAtom (dpy, name, False); |
|
|
713 | } |
|
|
714 | |
|
|
715 | Pixmap |
|
|
716 | rxvt_display::get_pixmap_property (Atom property) |
|
|
717 | { |
|
|
718 | Pixmap pixmap = None; |
|
|
719 | |
|
|
720 | int aformat; |
|
|
721 | unsigned long nitems, bytes_after; |
|
|
722 | Atom atype; |
|
|
723 | unsigned char *prop; |
|
|
724 | int result = XGetWindowProperty (dpy, root, property, |
|
|
725 | 0L, 1L, False, XA_PIXMAP, &atype, &aformat, |
|
|
726 | &nitems, &bytes_after, &prop); |
|
|
727 | if (result == Success) |
|
|
728 | { |
|
|
729 | if (atype == XA_PIXMAP) |
|
|
730 | pixmap = *(Pixmap *)prop; |
|
|
731 | XFree (prop); |
|
|
732 | } |
|
|
733 | |
|
|
734 | return pixmap; |
694 | } |
735 | } |
695 | |
736 | |
696 | ///////////////////////////////////////////////////////////////////////////// |
737 | ///////////////////////////////////////////////////////////////////////////// |
697 | |
738 | |
698 | template class refcache<rxvt_display>; |
739 | template class refcache<rxvt_display>; |
… | |
… | |
748 | d.red = color.r; |
789 | d.red = color.r; |
749 | d.green = color.g; |
790 | d.green = color.g; |
750 | d.blue = color.b; |
791 | d.blue = color.b; |
751 | d.alpha = alpha; |
792 | d.alpha = alpha; |
752 | |
793 | |
|
|
794 | // XftColorAlloc always returns 100% transparent pixels(!) |
753 | if (XftColorAllocValue (screen->dpy, screen->visual, screen->cmap, &d, &c)) |
795 | if (XftColorAllocValue (screen->dpy, screen->visual, screen->cmap, &d, &c)) |
754 | return true; |
796 | return true; |
755 | } |
797 | } |
756 | #else |
798 | #else |
757 | c.red = color.r; |
799 | c.red = color.r; |
… | |
… | |
768 | } |
810 | } |
769 | else if (XAllocColor (screen->dpy, screen->cmap, &c)) |
811 | else if (XAllocColor (screen->dpy, screen->cmap, &c)) |
770 | return true; |
812 | return true; |
771 | #endif |
813 | #endif |
772 | |
814 | |
|
|
815 | //TODO: set c.color* or c.* |
773 | c.pixel = (color.r + color.g + color.b) > 128*3 |
816 | c.pixel = (color.r * 2 + color.g * 3 + color.b) >= 0x8000 * 6 |
774 | ? WhitePixelOfScreen (DefaultScreenOfDisplay (screen->dpy)) |
817 | ? WhitePixelOfScreen (DefaultScreenOfDisplay (screen->dpy)) |
775 | : BlackPixelOfScreen (DefaultScreenOfDisplay (screen->dpy)); |
818 | : BlackPixelOfScreen (DefaultScreenOfDisplay (screen->dpy)); |
776 | |
819 | |
777 | return false; |
820 | return false; |
778 | } |
821 | } |
… | |
… | |
836 | |
879 | |
837 | // many kilobytes transfer per colour, but pseudocolor isn't worth |
880 | // many kilobytes transfer per colour, but pseudocolor isn't worth |
838 | // many extra optimisations. |
881 | // many extra optimisations. |
839 | XQueryColors (screen->dpy, screen->cmap, colors, cmap_size); |
882 | XQueryColors (screen->dpy, screen->cmap, colors, cmap_size); |
840 | |
883 | |
|
|
884 | while (cmap_size) |
|
|
885 | { |
841 | int diff = 0x7fffffffUL; |
886 | int diff = 0x7fffffffL; |
842 | XColor *best = colors; |
887 | XColor *best = colors; |
843 | |
888 | |
844 | for (int i = 0; i < cmap_size; i++) |
889 | for (int i = 0; i < cmap_size; i++) |
845 | { |
|
|
846 | int d = (squared_diff<int> (color.r >> 2, colors [i].red >> 2)) |
|
|
847 | + (squared_diff<int> (color.g >> 2, colors [i].green >> 2)) |
|
|
848 | + (squared_diff<int> (color.b >> 2, colors [i].blue >> 2)); |
|
|
849 | |
|
|
850 | if (d < diff) |
|
|
851 | { |
890 | { |
|
|
891 | // simple weighted rgb distance sucks, but keeps it simple |
|
|
892 | int d = abs (color.r - colors [i].red ) * 2 |
|
|
893 | + abs (color.g - colors [i].green) * 3 |
|
|
894 | + abs (color.b - colors [i].blue ); |
|
|
895 | |
|
|
896 | if (d < diff) |
|
|
897 | { |
852 | diff = d; |
898 | diff = d; |
853 | best = colors + i; |
899 | best = colors + i; |
|
|
900 | } |
854 | } |
901 | } |
855 | } |
|
|
856 | |
902 | |
857 | //rxvt_warn ("could not allocate %04x %04x %04x, getting %04x %04x %04x instead (%d)\n", |
903 | //rxvt_warn ("could not allocate %04x %04x %04x, getting %04x %04x %04x instead (%d,%d)\n", |
858 | // color.r, color.g, color.b, best->red, best->green, best->blue, diff); |
904 | // color.r, color.g, color.b, best->red, best->green, best->blue, diff, best - colors); |
859 | |
905 | |
860 | got = alloc (screen, rgba (best->red, best->green, best->blue)); |
906 | got = alloc (screen, rgba (best->red, best->green, best->blue)); |
|
|
907 | |
|
|
908 | if (got) |
|
|
909 | break; |
|
|
910 | |
|
|
911 | *best = colors [--cmap_size]; |
|
|
912 | } |
861 | |
913 | |
862 | delete [] colors; |
914 | delete [] colors; |
863 | } |
915 | } |
864 | #endif |
916 | #endif |
865 | |
917 | |
866 | return got; |
918 | return got; |
867 | } |
919 | } |
868 | |
920 | |
869 | void |
921 | void |
870 | rxvt_color::get (rgba &color) |
922 | rxvt_color::get (rgba &color) const |
871 | { |
923 | { |
872 | #if XFT |
924 | #if XFT |
|
|
925 | //TODO premultiplied alpha?? |
873 | color.r = c.color.red; |
926 | color.r = c.color.red; |
874 | color.g = c.color.green; |
927 | color.g = c.color.green; |
875 | color.b = c.color.blue; |
928 | color.b = c.color.blue; |
876 | color.a = c.color.alpha; |
929 | color.a = c.color.alpha; |
877 | #else |
930 | #else |
… | |
… | |
881 | color.a = rgba::MAX_CC; |
934 | color.a = rgba::MAX_CC; |
882 | #endif |
935 | #endif |
883 | } |
936 | } |
884 | |
937 | |
885 | void |
938 | void |
886 | rxvt_color::get (XColor &color) |
939 | rxvt_color::get (XColor &color) const |
887 | { |
940 | { |
888 | rgba c; |
941 | rgba c; |
889 | get (c); |
942 | get (c); |
890 | |
943 | |
891 | color.red = c.r; |
944 | color.red = c.r; |