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.136 by root, Wed Jun 6 20:22:04 2012 UTC vs.
Revision 1.150 by sf-exg, Sat Sep 12 13:47:58 2015 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 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",
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
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 >= 10))
479 flags |= DISPLAY_HAS_RENDER_10;
480
481 if (major > 0 || (major == 0 && minor >= 11)) 497 if (major > 0 || (major == 0 && minor >= 11))
498 {
482 flags |= DISPLAY_HAS_RENDER_MUL; 499 flags |= DISPLAY_HAS_RENDER;
483 500
484 XFilters *filters = XRenderQueryFilters (dpy, root); 501 if (XFilters *filters = XRenderQueryFilters (dpy, root))
485 if (filters)
486 { 502 {
487 for (int i = 0; i < filters->nfilter; i++) 503 for (int i = 0; i < filters->nfilter; i++)
488 if (!strcmp (filters->filter[i], FilterConvolution)) 504 if (!strcmp (filters->filter [i], FilterConvolution))
489 flags |= DISPLAY_HAS_RENDER_CONV; 505 flags |= DISPLAY_HAS_RENDER_CONV;
490 506
491 XFree (filters); 507 XFree (filters);
492 } 508 }
493 } 509 }
494#endif 510#endif
495 511
496 int fd = XConnectionNumber (dpy); 512 int fd = XConnectionNumber (dpy);
497 513
498 // try to detect whether we have a local connection. 514 // try to detect whether we have a local connection.
739 unsigned int alpha = color.a >= 0xff00 ? 0xffff : color.a; 755 unsigned int alpha = color.a >= 0xff00 ? 0xffff : color.a;
740 756
741#if XFT 757#if XFT
742 XRenderPictFormat *format; 758 XRenderPictFormat *format;
743 759
760 // not needed by XftColorAlloc, but by the other paths (ours
761 // and fallback), so just set all components here.
762 c.color.red = color.r;
763 c.color.green = color.g;
764 c.color.blue = color.b;
765 c.color.alpha = alpha;
766
744 // FUCKING Xft gets it wrong, of course, so work around it. 767 // FUCKING Xft gets it wrong, of course, so work around it.
745 // Transparency users should eat shit and die, and then 768 // Transparency users should eat shit and die, and then
746 // XRenderQueryPictIndexValues themselves plenty. 769 // XRenderQueryPictIndexValues themselves plenty.
747 if ((screen->visual->c_class == TrueColor) 770 if ((screen->visual->c_class == TrueColor)
748 && (format = XRenderFindVisualFormat (screen->dpy, screen->visual))) 771 && (format = XRenderFindVisualFormat (screen->dpy, screen->visual)))
749 { 772 {
750 // the fun lies in doing everything manually... 773 // the fun lies in doing everything manually...
751 c.color.red = color.r;
752 c.color.green = color.g;
753 c.color.blue = color.b;
754 c.color.alpha = alpha;
755 774
756 // Xft wants premultiplied alpha, but abuses the alpha channel 775 // Xft wants premultiplied alpha, but abuses the alpha channel
757 // as blend factor, and doesn't allow us to set the alpha channel 776 // as blend factor, and doesn't allow us to set the alpha channel
758 c.color.red = c.color.red * alpha / 0xffff; 777 c.color.red = c.color.red * alpha / 0xffff;
759 c.color.green = c.color.green * alpha / 0xffff; 778 c.color.green = c.color.green * alpha / 0xffff;
773 d.red = color.r; 792 d.red = color.r;
774 d.green = color.g; 793 d.green = color.g;
775 d.blue = color.b; 794 d.blue = color.b;
776 d.alpha = alpha; 795 d.alpha = alpha;
777 796
797 // XftColorAlloc always returns 100% transparent pixels(!)
778 if (XftColorAllocValue (screen->dpy, screen->visual, screen->cmap, &d, &c)) 798 if (XftColorAllocValue (screen->dpy, screen->visual, screen->cmap, &d, &c))
779 return true; 799 return true;
780 } 800 }
781#else 801#else
782 c.red = color.r; 802 c.red = color.r;
793 } 813 }
794 else if (XAllocColor (screen->dpy, screen->cmap, &c)) 814 else if (XAllocColor (screen->dpy, screen->cmap, &c))
795 return true; 815 return true;
796#endif 816#endif
797 817
798 c.pixel = (color.r + color.g + color.b) > 128*3 818 c.pixel = (color.r * 2 + color.g * 3 + color.b) >= 0x8000 * 6
799 ? WhitePixelOfScreen (DefaultScreenOfDisplay (screen->dpy)) 819 ? WhitePixelOfScreen (DefaultScreenOfDisplay (screen->dpy))
800 : BlackPixelOfScreen (DefaultScreenOfDisplay (screen->dpy)); 820 : BlackPixelOfScreen (DefaultScreenOfDisplay (screen->dpy));
801 821
802 return false; 822 return false;
803} 823}
805bool 825bool
806rxvt_color::set (rxvt_screen *screen, const char *name) 826rxvt_color::set (rxvt_screen *screen, const char *name)
807{ 827{
808 rgba c; 828 rgba c;
809 char eos; 829 char eos;
810 int skip; 830 int skip = 0;
811 831
812 c.a = rgba::MAX_CC; 832 c.a = rgba::MAX_CC;
813 833
814 // parse the nonstandard "[alphapercent]" prefix 834 // parse the nonstandard "[alphapercent]" prefix
815 if (1 <= sscanf (name, "[%hd]%n", &c.a, &skip)) 835 if (1 <= sscanf (name, "[%hd]%n", &c.a, &skip))
861 881
862 // many kilobytes transfer per colour, but pseudocolor isn't worth 882 // many kilobytes transfer per colour, but pseudocolor isn't worth
863 // many extra optimisations. 883 // many extra optimisations.
864 XQueryColors (screen->dpy, screen->cmap, colors, cmap_size); 884 XQueryColors (screen->dpy, screen->cmap, colors, cmap_size);
865 885
886 while (cmap_size)
887 {
866 int diff = 0x7fffffffUL; 888 int diff = 0x7fffffffL;
867 XColor *best = colors; 889 XColor *best = colors;
868 890
869 for (int i = 0; i < cmap_size; i++) 891 for (int i = 0; i < cmap_size; i++)
870 {
871 int d = (squared_diff<int> (color.r >> 2, colors [i].red >> 2))
872 + (squared_diff<int> (color.g >> 2, colors [i].green >> 2))
873 + (squared_diff<int> (color.b >> 2, colors [i].blue >> 2));
874
875 if (d < diff)
876 { 892 {
893 // simple weighted rgb distance sucks, but keeps it simple
894 int d = abs (color.r - colors [i].red ) * 2
895 + abs (color.g - colors [i].green) * 3
896 + abs (color.b - colors [i].blue );
897
898 if (d < diff)
899 {
877 diff = d; 900 diff = d;
878 best = colors + i; 901 best = colors + i;
902 }
879 } 903 }
880 }
881 904
882 //rxvt_warn ("could not allocate %04x %04x %04x, getting %04x %04x %04x instead (%d)\n", 905 //rxvt_warn ("could not allocate %04x %04x %04x, getting %04x %04x %04x instead (%d,%d)\n",
883 // color.r, color.g, color.b, best->red, best->green, best->blue, diff); 906 // color.r, color.g, color.b, best->red, best->green, best->blue, diff, best - colors);
884 907
885 got = alloc (screen, rgba (best->red, best->green, best->blue)); 908 got = alloc (screen, rgba (best->red, best->green, best->blue));
909
910 if (got)
911 break;
912
913 *best = colors [--cmap_size];
914 }
886 915
887 delete [] colors; 916 delete [] colors;
888 } 917 }
889#endif 918#endif
890 919
893 922
894void 923void
895rxvt_color::get (rgba &color) const 924rxvt_color::get (rgba &color) const
896{ 925{
897#if XFT 926#if XFT
927
898 color.r = c.color.red; 928 color.r = c.color.red;
899 color.g = c.color.green; 929 color.g = c.color.green;
900 color.b = c.color.blue; 930 color.b = c.color.blue;
901 color.a = c.color.alpha; 931 color.a = c.color.alpha;
932
933 if (IN_RANGE_INC (color.a, 0x0001, 0xfffe))
934 {
935 color.r = color.r * 0xffff / color.a;
936 color.g = color.g * 0xffff / color.a;
937 color.b = color.b * 0xffff / color.a;
938 }
939
902#else 940#else
941
903 color.r = c.red; 942 color.r = c.red;
904 color.g = c.green; 943 color.g = c.green;
905 color.b = c.blue; 944 color.b = c.blue;
906 color.a = rgba::MAX_CC; 945 color.a = rgba::MAX_CC;
946
907#endif 947#endif
908} 948}
909 949
910void 950void
911rxvt_color::get (XColor &color) const 951rxvt_color::get (XColor &color) const

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines