… | |
… | |
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 |
… | |
… | |
470 | |
490 | |
471 | flags = 0; |
491 | flags = 0; |
472 | #if XRENDER |
492 | #if XRENDER |
473 | int major, minor; |
493 | int major, minor; |
474 | if (XRenderQueryVersion (dpy, &major, &minor)) |
494 | if (XRenderQueryVersion (dpy, &major, &minor)) |
475 | { |
|
|
476 | flags |= DISPLAY_HAS_RENDER; |
|
|
477 | |
|
|
478 | if (major > 0 || (major == 0 && minor >= 11)) |
495 | if (major > 0 || (major == 0 && minor >= 11)) |
|
|
496 | { |
479 | flags |= DISPLAY_HAS_RENDER_MUL; |
497 | flags |= DISPLAY_HAS_RENDER; |
480 | |
498 | |
481 | XFilters *filters = XRenderQueryFilters (dpy, root); |
499 | if (XFilters *filters = XRenderQueryFilters (dpy, root)) |
482 | if (filters) |
|
|
483 | { |
500 | { |
484 | for (int i = 0; i < filters->nfilter; i++) |
501 | for (int i = 0; i < filters->nfilter; i++) |
485 | if (!strcmp (filters->filter[i], FilterConvolution)) |
502 | if (!strcmp (filters->filter [i], FilterConvolution)) |
486 | flags |= DISPLAY_HAS_RENDER_CONV; |
503 | flags |= DISPLAY_HAS_RENDER_CONV; |
487 | |
504 | |
488 | XFree (filters); |
505 | XFree (filters); |
489 | } |
506 | } |
490 | } |
507 | } |
491 | #endif |
508 | #endif |
492 | |
509 | |
493 | int fd = XConnectionNumber (dpy); |
510 | int fd = XConnectionNumber (dpy); |
494 | |
511 | |
495 | // try to detect whether we have a local connection. |
512 | // try to detect whether we have a local connection. |
… | |
… | |
534 | #ifdef POINTER_BLANK |
551 | #ifdef POINTER_BLANK |
535 | XFreeCursor (dpy, blank_cursor); |
552 | XFreeCursor (dpy, blank_cursor); |
536 | #endif |
553 | #endif |
537 | x_ev.stop (); |
554 | x_ev.stop (); |
538 | flush_ev.stop (); |
555 | flush_ev.stop (); |
539 | #ifdef USE_XIM |
556 | #if USE_XIM |
540 | xims.clear (); |
557 | xims.clear (); |
541 | #endif |
558 | #endif |
542 | XrmDestroyDatabase (XrmGetDatabase (dpy)); |
559 | XrmDestroyDatabase (XrmGetDatabase (dpy)); |
543 | XCloseDisplay (dpy); |
560 | XCloseDisplay (dpy); |
544 | } |
561 | } |
545 | |
562 | |
546 | #ifdef USE_XIM |
563 | #if USE_XIM |
547 | void rxvt_display::im_change_cb () |
564 | void rxvt_display::im_change_cb () |
548 | { |
565 | { |
549 | for (im_watcher **i = imw.begin (); i != imw.end (); ++i) |
566 | for (im_watcher **i = imw.begin (); i != imw.end (); ++i) |
550 | (*i)->call (); |
567 | (*i)->call (); |
551 | } |
568 | } |
… | |
… | |
587 | do |
604 | do |
588 | { |
605 | { |
589 | XEvent xev; |
606 | XEvent xev; |
590 | XNextEvent (dpy, &xev); |
607 | XNextEvent (dpy, &xev); |
591 | |
608 | |
592 | #ifdef USE_XIM |
609 | #if USE_XIM |
593 | if (!XFilterEvent (&xev, None)) |
610 | if (!XFilterEvent (&xev, None)) |
594 | { |
611 | { |
595 | if (xev.type == PropertyNotify |
612 | if (xev.type == PropertyNotify |
596 | && xev.xany.window == root |
613 | && xev.xany.window == root |
597 | && xev.xproperty.atom == xa[XA_XIM_SERVERS]) |
614 | && xev.xproperty.atom == xa[XA_XIM_SERVERS]) |
… | |
… | |
605 | if (!xw[i]) |
622 | if (!xw[i]) |
606 | xw.erase_unordered (i); |
623 | xw.erase_unordered (i); |
607 | else if (xw[i]->window == xev.xany.window) |
624 | else if (xw[i]->window == xev.xany.window) |
608 | xw[i]->call (xev); |
625 | xw[i]->call (xev); |
609 | } |
626 | } |
610 | #ifdef USE_XIM |
627 | #if USE_XIM |
611 | } |
628 | } |
612 | #endif |
629 | #endif |
613 | } |
630 | } |
614 | while (XEventsQueued (dpy, QueuedAlready)); |
631 | while (XEventsQueued (dpy, QueuedAlready)); |
615 | |
632 | |
… | |
… | |
646 | } |
663 | } |
647 | |
664 | |
648 | cur_owner = owner; |
665 | cur_owner = owner; |
649 | } |
666 | } |
650 | |
667 | |
651 | #ifdef USE_XIM |
668 | #if USE_XIM |
652 | |
669 | |
653 | void rxvt_display::reg (im_watcher *w) |
670 | void rxvt_display::reg (im_watcher *w) |
654 | { |
671 | { |
655 | imw.push_back (w); |
672 | imw.push_back (w); |
656 | } |
673 | } |
… | |
… | |
858 | |
875 | |
859 | // many kilobytes transfer per colour, but pseudocolor isn't worth |
876 | // many kilobytes transfer per colour, but pseudocolor isn't worth |
860 | // many extra optimisations. |
877 | // many extra optimisations. |
861 | XQueryColors (screen->dpy, screen->cmap, colors, cmap_size); |
878 | XQueryColors (screen->dpy, screen->cmap, colors, cmap_size); |
862 | |
879 | |
|
|
880 | while (cmap_size) |
|
|
881 | { |
863 | int diff = 0x7fffffffUL; |
882 | int diff = 0x7fffffffUL; |
864 | XColor *best = colors; |
883 | XColor *best = colors; |
865 | |
884 | |
866 | for (int i = 0; i < cmap_size; i++) |
885 | for (int i = 0; i < cmap_size; i++) |
867 | { |
|
|
868 | int d = (squared_diff<int> (color.r >> 2, colors [i].red >> 2)) |
|
|
869 | + (squared_diff<int> (color.g >> 2, colors [i].green >> 2)) |
|
|
870 | + (squared_diff<int> (color.b >> 2, colors [i].blue >> 2)); |
|
|
871 | |
|
|
872 | if (d < diff) |
|
|
873 | { |
886 | { |
|
|
887 | int d = (squared_diff<int> (color.r >> 2, colors [i].red >> 2)) |
|
|
888 | + (squared_diff<int> (color.g >> 2, colors [i].green >> 2)) |
|
|
889 | + (squared_diff<int> (color.b >> 2, colors [i].blue >> 2)); |
|
|
890 | |
|
|
891 | if (d < diff) |
|
|
892 | { |
874 | diff = d; |
893 | diff = d; |
875 | best = colors + i; |
894 | best = colors + i; |
|
|
895 | } |
876 | } |
896 | } |
877 | } |
|
|
878 | |
897 | |
879 | //rxvt_warn ("could not allocate %04x %04x %04x, getting %04x %04x %04x instead (%d)\n", |
898 | //rxvt_warn ("could not allocate %04x %04x %04x, getting %04x %04x %04x instead (%d,%d)\n", |
880 | // color.r, color.g, color.b, best->red, best->green, best->blue, diff); |
899 | // color.r, color.g, color.b, best->red, best->green, best->blue, diff, best - colors); |
881 | |
900 | |
882 | got = alloc (screen, rgba (best->red, best->green, best->blue)); |
901 | got = alloc (screen, rgba (best->red, best->green, best->blue)); |
|
|
902 | |
|
|
903 | if (got) |
|
|
904 | break; |
|
|
905 | |
|
|
906 | *best = colors [--cmap_size]; |
|
|
907 | } |
883 | |
908 | |
884 | delete [] colors; |
909 | delete [] colors; |
885 | } |
910 | } |
886 | #endif |
911 | #endif |
887 | |
912 | |
888 | return got; |
913 | return got; |
889 | } |
914 | } |
890 | |
915 | |
891 | void |
916 | void |
892 | rxvt_color::get (rgba &color) |
917 | rxvt_color::get (rgba &color) const |
893 | { |
918 | { |
894 | #if XFT |
919 | #if XFT |
895 | color.r = c.color.red; |
920 | color.r = c.color.red; |
896 | color.g = c.color.green; |
921 | color.g = c.color.green; |
897 | color.b = c.color.blue; |
922 | color.b = c.color.blue; |
… | |
… | |
903 | color.a = rgba::MAX_CC; |
928 | color.a = rgba::MAX_CC; |
904 | #endif |
929 | #endif |
905 | } |
930 | } |
906 | |
931 | |
907 | void |
932 | void |
908 | rxvt_color::get (XColor &color) |
933 | rxvt_color::get (XColor &color) const |
909 | { |
934 | { |
910 | rgba c; |
935 | rgba c; |
911 | get (c); |
936 | get (c); |
912 | |
937 | |
913 | color.red = c.r; |
938 | color.red = c.r; |