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.140 by sf-exg, Sat Dec 29 14:23:35 2012 UTC vs.
Revision 1.147 by root, Wed Dec 17 13:16:18 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#if BG_IMAGE_FROM_ROOT || ENABLE_PERL 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",
279 XFree (vi); 281 XFree (vi);
280 282
281 cmap = XCreateColormap (dpy, display->root, visual, AllocNone); 283 cmap = XCreateColormap (dpy, display->root, visual, AllocNone);
282 } 284 }
283 else 285 else
284 rxvt_warn ("cannot requested visual id 0x%02x, using default visual.\n", id); 286 rxvt_warn ("no visual found for requested id 0x%02x, using default visual.\n", id);
285} 287}
286 288
287void 289void
288rxvt_screen::select_depth (int bitdepth) 290rxvt_screen::select_depth (int bitdepth)
289{ 291{
490 492
491 flags = 0; 493 flags = 0;
492#if XRENDER 494#if XRENDER
493 int major, minor; 495 int major, minor;
494 if (XRenderQueryVersion (dpy, &major, &minor)) 496 if (XRenderQueryVersion (dpy, &major, &minor))
495 if (major > 0 || (major == 0 && minor >= 10)) 497 if (major > 0 || (major == 0 && minor >= 11))
496 { 498 {
497 flags |= DISPLAY_HAS_RENDER; 499 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 500
504 if (XFilters *filters = XRenderQueryFilters (dpy, root)) 501 if (XFilters *filters = XRenderQueryFilters (dpy, root))
505 { 502 {
506 for (int i = 0; i < filters->nfilter; i++) 503 for (int i = 0; i < filters->nfilter; i++)
507 if (!strcmp (filters->filter [i], FilterConvolution)) 504 if (!strcmp (filters->filter [i], FilterConvolution))
792 d.red = color.r; 789 d.red = color.r;
793 d.green = color.g; 790 d.green = color.g;
794 d.blue = color.b; 791 d.blue = color.b;
795 d.alpha = alpha; 792 d.alpha = alpha;
796 793
794 // XftColorAlloc always returns 100% transparent pixels(!)
797 if (XftColorAllocValue (screen->dpy, screen->visual, screen->cmap, &d, &c)) 795 if (XftColorAllocValue (screen->dpy, screen->visual, screen->cmap, &d, &c))
798 return true; 796 return true;
799 } 797 }
800#else 798#else
801 c.red = color.r; 799 c.red = color.r;
812 } 810 }
813 else if (XAllocColor (screen->dpy, screen->cmap, &c)) 811 else if (XAllocColor (screen->dpy, screen->cmap, &c))
814 return true; 812 return true;
815#endif 813#endif
816 814
815 //TODO: set c.color* or c.*
817 c.pixel = (color.r + color.g + color.b) > 128*3 816 c.pixel = (color.r * 2 + color.g * 3 + color.b) >= 0x8000 * 6
818 ? WhitePixelOfScreen (DefaultScreenOfDisplay (screen->dpy)) 817 ? WhitePixelOfScreen (DefaultScreenOfDisplay (screen->dpy))
819 : BlackPixelOfScreen (DefaultScreenOfDisplay (screen->dpy)); 818 : BlackPixelOfScreen (DefaultScreenOfDisplay (screen->dpy));
820 819
821 return false; 820 return false;
822} 821}
880 879
881 // many kilobytes transfer per colour, but pseudocolor isn't worth 880 // many kilobytes transfer per colour, but pseudocolor isn't worth
882 // many extra optimisations. 881 // many extra optimisations.
883 XQueryColors (screen->dpy, screen->cmap, colors, cmap_size); 882 XQueryColors (screen->dpy, screen->cmap, colors, cmap_size);
884 883
884 while (cmap_size)
885 {
885 int diff = 0x7fffffffUL; 886 int diff = 0x7fffffffL;
886 XColor *best = colors; 887 XColor *best = colors;
887 888
888 for (int i = 0; i < cmap_size; i++) 889 for (int i = 0; i < cmap_size; i++)
889 {
890 int d = (squared_diff<int> (color.r >> 2, colors [i].red >> 2))
891 + (squared_diff<int> (color.g >> 2, colors [i].green >> 2))
892 + (squared_diff<int> (color.b >> 2, colors [i].blue >> 2));
893
894 if (d < diff)
895 { 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 {
896 diff = d; 898 diff = d;
897 best = colors + i; 899 best = colors + i;
900 }
898 } 901 }
899 }
900 902
901 //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",
902 // 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);
903 905
904 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 }
905 913
906 delete [] colors; 914 delete [] colors;
907 } 915 }
908#endif 916#endif
909 917
912 920
913void 921void
914rxvt_color::get (rgba &color) const 922rxvt_color::get (rgba &color) const
915{ 923{
916#if XFT 924#if XFT
925 //TODO premultiplied alpha??
917 color.r = c.color.red; 926 color.r = c.color.red;
918 color.g = c.color.green; 927 color.g = c.color.green;
919 color.b = c.color.blue; 928 color.b = c.color.blue;
920 color.a = c.color.alpha; 929 color.a = c.color.alpha;
921#else 930#else

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines