ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/rxvttoolkit.C
(Generate patch)

Comparing rxvt-unicode/src/rxvttoolkit.C (file contents):
Revision 1.131 by root, Fri Feb 24 07:10:54 2012 UTC vs.
Revision 1.146 by root, Sun Dec 14 04:52:10 2014 UTC

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
160static void 162static void
161#if XIMCB_PROTO_BROKEN 163#if XIMCB_PROTO_BROKEN
162im_destroy_cb (XIC unused1, XPointer client_data, XPointer unused3) 164im_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
265void 269void
266rxvt_screen::select_visual (int bitdepth) 270rxvt_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
289void
290rxvt_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
280void 302void
281rxvt_screen::clear () 303rxvt_screen::clear ()
282{ 304{
283#if XFT 305#if XFT
466 blank_cursor = XCreateGlyphCursor (dpy, f, f, ' ', ' ', 488 blank_cursor = XCreateGlyphCursor (dpy, f, f, ' ', ' ',
467 &blackcolour, &blackcolour); 489 &blackcolour, &blackcolour);
468 XUnloadFont (dpy, f); 490 XUnloadFont (dpy, f);
469#endif 491#endif
470 492
493 flags = 0;
494#if XRENDER
495 int major, minor;
496 if (XRenderQueryVersion (dpy, &major, &minor))
497 if (major > 0 || (major == 0 && minor >= 11))
498 {
499 flags |= DISPLAY_HAS_RENDER;
500
501 if (XFilters *filters = XRenderQueryFilters (dpy, root))
502 {
503 for (int i = 0; i < filters->nfilter; i++)
504 if (!strcmp (filters->filter [i], FilterConvolution))
505 flags |= DISPLAY_HAS_RENDER_CONV;
506
507 XFree (filters);
508 }
509 }
510#endif
511
471 int fd = XConnectionNumber (dpy); 512 int fd = XConnectionNumber (dpy);
472 513
473 // try to detect whether we have a local connection. 514 // try to detect whether we have a local connection.
474 // assume unix domain socket == local, everything else not 515 // assume unix domain socket == local, everything else not
475 // TODO: might want to check for inet/127.0.0.1 516 // TODO: might want to check for inet/127.0.0.1
512#ifdef POINTER_BLANK 553#ifdef POINTER_BLANK
513 XFreeCursor (dpy, blank_cursor); 554 XFreeCursor (dpy, blank_cursor);
514#endif 555#endif
515 x_ev.stop (); 556 x_ev.stop ();
516 flush_ev.stop (); 557 flush_ev.stop ();
517#ifdef USE_XIM 558#if USE_XIM
518 xims.clear (); 559 xims.clear ();
519#endif 560#endif
520 XrmDestroyDatabase (XrmGetDatabase (dpy)); 561 XrmDestroyDatabase (XrmGetDatabase (dpy));
521 XCloseDisplay (dpy); 562 XCloseDisplay (dpy);
522} 563}
523 564
524#ifdef USE_XIM 565#if USE_XIM
525void rxvt_display::im_change_cb () 566void rxvt_display::im_change_cb ()
526{ 567{
527 for (im_watcher **i = imw.begin (); i != imw.end (); ++i) 568 for (im_watcher **i = imw.begin (); i != imw.end (); ++i)
528 (*i)->call (); 569 (*i)->call ();
529} 570}
565 do 606 do
566 { 607 {
567 XEvent xev; 608 XEvent xev;
568 XNextEvent (dpy, &xev); 609 XNextEvent (dpy, &xev);
569 610
570#ifdef USE_XIM 611#if USE_XIM
571 if (!XFilterEvent (&xev, None)) 612 if (!XFilterEvent (&xev, None))
572 { 613 {
573 if (xev.type == PropertyNotify 614 if (xev.type == PropertyNotify
574 && xev.xany.window == root 615 && xev.xany.window == root
575 && xev.xproperty.atom == xa[XA_XIM_SERVERS]) 616 && xev.xproperty.atom == xa[XA_XIM_SERVERS])
583 if (!xw[i]) 624 if (!xw[i])
584 xw.erase_unordered (i); 625 xw.erase_unordered (i);
585 else if (xw[i]->window == xev.xany.window) 626 else if (xw[i]->window == xev.xany.window)
586 xw[i]->call (xev); 627 xw[i]->call (xev);
587 } 628 }
588#ifdef USE_XIM 629#if USE_XIM
589 } 630 }
590#endif 631#endif
591 } 632 }
592 while (XEventsQueued (dpy, QueuedAlready)); 633 while (XEventsQueued (dpy, QueuedAlready));
593 634
624 } 665 }
625 666
626 cur_owner = owner; 667 cur_owner = owner;
627} 668}
628 669
629#ifdef USE_XIM 670#if USE_XIM
630 671
631void rxvt_display::reg (im_watcher *w) 672void rxvt_display::reg (im_watcher *w)
632{ 673{
633 imw.push_back (w); 674 imw.push_back (w);
634} 675}
667#endif 708#endif
668 709
669Atom rxvt_display::atom (const char *name) 710Atom rxvt_display::atom (const char *name)
670{ 711{
671 return XInternAtom (dpy, name, False); 712 return XInternAtom (dpy, name, False);
713}
714
715Pixmap
716rxvt_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;
672} 735}
673 736
674///////////////////////////////////////////////////////////////////////////// 737/////////////////////////////////////////////////////////////////////////////
675 738
676template class refcache<rxvt_display>; 739template class refcache<rxvt_display>;
746 } 809 }
747 else if (XAllocColor (screen->dpy, screen->cmap, &c)) 810 else if (XAllocColor (screen->dpy, screen->cmap, &c))
748 return true; 811 return true;
749#endif 812#endif
750 813
814 //TODO: set c.color* or c.*
751 c.pixel = (color.r + color.g + color.b) > 128*3 815 c.pixel = (color.r * 2 + color.g * 3 + color.b) >= 0x8000 * 6
752 ? WhitePixelOfScreen (DefaultScreenOfDisplay (screen->dpy)) 816 ? WhitePixelOfScreen (DefaultScreenOfDisplay (screen->dpy))
753 : BlackPixelOfScreen (DefaultScreenOfDisplay (screen->dpy)); 817 : BlackPixelOfScreen (DefaultScreenOfDisplay (screen->dpy));
754 818
755 return false; 819 return false;
756} 820}
814 878
815 // many kilobytes transfer per colour, but pseudocolor isn't worth 879 // many kilobytes transfer per colour, but pseudocolor isn't worth
816 // many extra optimisations. 880 // many extra optimisations.
817 XQueryColors (screen->dpy, screen->cmap, colors, cmap_size); 881 XQueryColors (screen->dpy, screen->cmap, colors, cmap_size);
818 882
883 while (cmap_size)
884 {
819 int diff = 0x7fffffffUL; 885 int diff = 0x7fffffffL;
820 XColor *best = colors; 886 XColor *best = colors;
821 887
822 for (int i = 0; i < cmap_size; i++) 888 for (int i = 0; i < cmap_size; i++)
823 {
824 int d = (squared_diff<int> (color.r >> 2, colors [i].red >> 2))
825 + (squared_diff<int> (color.g >> 2, colors [i].green >> 2))
826 + (squared_diff<int> (color.b >> 2, colors [i].blue >> 2));
827
828 if (d < diff)
829 { 889 {
890 // simple weighted rgb distance sucks, but keeps it simple
891 int d = abs (color.r - colors [i].red ) * 2
892 + abs (color.g - colors [i].green) * 3
893 + abs (color.b - colors [i].blue );
894
895 if (d < diff)
896 {
830 diff = d; 897 diff = d;
831 best = colors + i; 898 best = colors + i;
899 }
832 } 900 }
833 }
834 901
835 //rxvt_warn ("could not allocate %04x %04x %04x, getting %04x %04x %04x instead (%d)\n", 902 //rxvt_warn ("could not allocate %04x %04x %04x, getting %04x %04x %04x instead (%d,%d)\n",
836 // color.r, color.g, color.b, best->red, best->green, best->blue, diff); 903 // color.r, color.g, color.b, best->red, best->green, best->blue, diff, best - colors);
837 904
838 got = alloc (screen, rgba (best->red, best->green, best->blue)); 905 got = alloc (screen, rgba (best->red, best->green, best->blue));
906
907 if (got)
908 break;
909
910 *best = colors [--cmap_size];
911 }
839 912
840 delete [] colors; 913 delete [] colors;
841 } 914 }
842#endif 915#endif
843 916
844 return got; 917 return got;
845} 918}
846 919
847void 920void
848rxvt_color::get (rgba &color) 921rxvt_color::get (rgba &color) const
849{ 922{
850#if XFT 923#if XFT
924 //TODO premultiplied alpha??
851 color.r = c.color.red; 925 color.r = c.color.red;
852 color.g = c.color.green; 926 color.g = c.color.green;
853 color.b = c.color.blue; 927 color.b = c.color.blue;
854 color.a = c.color.alpha; 928 color.a = c.color.alpha;
855#else 929#else
859 color.a = rgba::MAX_CC; 933 color.a = rgba::MAX_CC;
860#endif 934#endif
861} 935}
862 936
863void 937void
864rxvt_color::get (XColor &color) 938rxvt_color::get (XColor &color) const
865{ 939{
866 rgba c; 940 rgba c;
867 get (c); 941 get (c);
868 942
869 color.red = c.r; 943 color.red = c.r;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines