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.127 by sf-exg, Mon May 30 18:39:03 2011 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#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
430bool rxvt_display::ref_init () 452bool rxvt_display::ref_init ()
431{ 453{
432#ifdef LOCAL_X_IS_UNIX 454#ifdef LOCAL_X_IS_UNIX
433 if (id[0] == ':') 455 if (id[0] == ':')
434 { 456 {
435 if (!(val = rxvt_temp_buf<char> (5 + strlen (id) + 1))) 457 char *val = rxvt_temp_buf<char> (5 + strlen (id) + 1);
436 return false; 458
437 strcpy (val, "unix/"); 459 strcpy (val, "unix/");
438 strcat (val, id); 460 strcat (val, id);
461
439 dpy = XOpenDisplay (val); 462 dpy = XOpenDisplay (val);
440 } 463 }
441 else 464 else
442#endif 465#endif
443 dpy = 0; 466 dpy = 0;
465 blank_cursor = XCreateGlyphCursor (dpy, f, f, ' ', ' ', 488 blank_cursor = XCreateGlyphCursor (dpy, f, f, ' ', ' ',
466 &blackcolour, &blackcolour); 489 &blackcolour, &blackcolour);
467 XUnloadFont (dpy, f); 490 XUnloadFont (dpy, f);
468#endif 491#endif
469 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
470 int fd = XConnectionNumber (dpy); 512 int fd = XConnectionNumber (dpy);
471 513
472 // try to detect whether we have a local connection. 514 // try to detect whether we have a local connection.
473 // assume unix domain socket == local, everything else not 515 // assume unix domain socket == local, everything else not
474 // TODO: might want to check for inet/127.0.0.1 516 // TODO: might want to check for inet/127.0.0.1
511#ifdef POINTER_BLANK 553#ifdef POINTER_BLANK
512 XFreeCursor (dpy, blank_cursor); 554 XFreeCursor (dpy, blank_cursor);
513#endif 555#endif
514 x_ev.stop (); 556 x_ev.stop ();
515 flush_ev.stop (); 557 flush_ev.stop ();
516#ifdef USE_XIM 558#if USE_XIM
517 xims.clear (); 559 xims.clear ();
518#endif 560#endif
519 XrmDestroyDatabase (XrmGetDatabase (dpy)); 561 XrmDestroyDatabase (XrmGetDatabase (dpy));
520 XCloseDisplay (dpy); 562 XCloseDisplay (dpy);
521} 563}
522 564
523#ifdef USE_XIM 565#if USE_XIM
524void rxvt_display::im_change_cb () 566void rxvt_display::im_change_cb ()
525{ 567{
526 for (im_watcher **i = imw.begin (); i != imw.end (); ++i) 568 for (im_watcher **i = imw.begin (); i != imw.end (); ++i)
527 (*i)->call (); 569 (*i)->call ();
528} 570}
564 do 606 do
565 { 607 {
566 XEvent xev; 608 XEvent xev;
567 XNextEvent (dpy, &xev); 609 XNextEvent (dpy, &xev);
568 610
569#ifdef USE_XIM 611#if USE_XIM
570 if (!XFilterEvent (&xev, None)) 612 if (!XFilterEvent (&xev, None))
571 { 613 {
572 if (xev.type == PropertyNotify 614 if (xev.type == PropertyNotify
573 && xev.xany.window == root 615 && xev.xany.window == root
574 && xev.xproperty.atom == xa[XA_XIM_SERVERS]) 616 && xev.xproperty.atom == xa[XA_XIM_SERVERS])
582 if (!xw[i]) 624 if (!xw[i])
583 xw.erase_unordered (i); 625 xw.erase_unordered (i);
584 else if (xw[i]->window == xev.xany.window) 626 else if (xw[i]->window == xev.xany.window)
585 xw[i]->call (xev); 627 xw[i]->call (xev);
586 } 628 }
587#ifdef USE_XIM 629#if USE_XIM
588 } 630 }
589#endif 631#endif
590 } 632 }
591 while (XEventsQueued (dpy, QueuedAlready)); 633 while (XEventsQueued (dpy, QueuedAlready));
592 634
623 } 665 }
624 666
625 cur_owner = owner; 667 cur_owner = owner;
626} 668}
627 669
628#ifdef USE_XIM 670#if USE_XIM
629 671
630void rxvt_display::reg (im_watcher *w) 672void rxvt_display::reg (im_watcher *w)
631{ 673{
632 imw.push_back (w); 674 imw.push_back (w);
633} 675}
668Atom rxvt_display::atom (const char *name) 710Atom rxvt_display::atom (const char *name)
669{ 711{
670 return XInternAtom (dpy, name, False); 712 return XInternAtom (dpy, name, False);
671} 713}
672 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;
735}
736
673///////////////////////////////////////////////////////////////////////////// 737/////////////////////////////////////////////////////////////////////////////
674 738
675template class refcache<rxvt_display>; 739template class refcache<rxvt_display>;
676refcache<rxvt_display> displays; 740refcache<rxvt_display> displays;
677 741
686 750
687bool 751bool
688rxvt_color::alloc (rxvt_screen *screen, const rgba &color) 752rxvt_color::alloc (rxvt_screen *screen, const rgba &color)
689{ 753{
690 //TODO: only supports 24 bit 754 //TODO: only supports 24 bit
691 int alpha = color.a >= 0xff00 ? 0xffff : color.a; 755 unsigned int alpha = color.a >= 0xff00 ? 0xffff : color.a;
692 756
693#if XFT 757#if XFT
694 XRenderPictFormat *format; 758 XRenderPictFormat *format;
695 759
696 // FUCKING Xft gets it wrong, of course, so work around it. 760 // FUCKING Xft gets it wrong, of course, so work around it.
725 d.red = color.r; 789 d.red = color.r;
726 d.green = color.g; 790 d.green = color.g;
727 d.blue = color.b; 791 d.blue = color.b;
728 d.alpha = alpha; 792 d.alpha = alpha;
729 793
794 // XftColorAlloc always returns 100% transparent pixels(!)
730 return XftColorAllocValue (screen->dpy, screen->visual, screen->cmap, &d, &c); 795 if (XftColorAllocValue (screen->dpy, screen->visual, screen->cmap, &d, &c))
796 return true;
731 } 797 }
732#else 798#else
733 c.red = color.r; 799 c.red = color.r;
734 c.green = color.g; 800 c.green = color.g;
735 c.blue = color.b; 801 c.blue = color.b;
742 808
743 return true; 809 return true;
744 } 810 }
745 else if (XAllocColor (screen->dpy, screen->cmap, &c)) 811 else if (XAllocColor (screen->dpy, screen->cmap, &c))
746 return true; 812 return true;
747 else 813#endif
814
815 //TODO: set c.color* or c.*
748 c.pixel = (color.r + color.g + color.b) > 128*3 816 c.pixel = (color.r * 2 + color.g * 3 + color.b) >= 0x8000 * 6
749 ? WhitePixelOfScreen (DefaultScreenOfDisplay (screen->dpy)) 817 ? WhitePixelOfScreen (DefaultScreenOfDisplay (screen->dpy))
750 : BlackPixelOfScreen (DefaultScreenOfDisplay (screen->dpy)); 818 : BlackPixelOfScreen (DefaultScreenOfDisplay (screen->dpy));
751#endif
752 819
753 return false; 820 return false;
754} 821}
755 822
756bool 823bool
812 879
813 // many kilobytes transfer per colour, but pseudocolor isn't worth 880 // many kilobytes transfer per colour, but pseudocolor isn't worth
814 // many extra optimisations. 881 // many extra optimisations.
815 XQueryColors (screen->dpy, screen->cmap, colors, cmap_size); 882 XQueryColors (screen->dpy, screen->cmap, colors, cmap_size);
816 883
884 while (cmap_size)
885 {
817 int diff = 0x7fffffffUL; 886 int diff = 0x7fffffffL;
818 XColor *best = colors; 887 XColor *best = colors;
819 888
820 for (int i = 0; i < cmap_size; i++) 889 for (int i = 0; i < cmap_size; i++)
821 {
822 int d = (squared_diff<int> (color.r >> 2, colors [i].red >> 2))
823 + (squared_diff<int> (color.g >> 2, colors [i].green >> 2))
824 + (squared_diff<int> (color.b >> 2, colors [i].blue >> 2));
825
826 if (d < diff)
827 { 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 {
828 diff = d; 898 diff = d;
829 best = colors + i; 899 best = colors + i;
900 }
830 } 901 }
831 }
832 902
833 //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",
834 // 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);
835 905
836 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 }
837 913
838 delete [] colors; 914 delete [] colors;
839 } 915 }
840#endif 916#endif
841 917
842 return got; 918 return got;
843} 919}
844 920
845void 921void
846rxvt_color::get (rgba &color) 922rxvt_color::get (rgba &color) const
847{ 923{
848#if XFT 924#if XFT
925 //TODO premultiplied alpha??
849 color.r = c.color.red; 926 color.r = c.color.red;
850 color.g = c.color.green; 927 color.g = c.color.green;
851 color.b = c.color.blue; 928 color.b = c.color.blue;
852 color.a = c.color.alpha; 929 color.a = c.color.alpha;
853#else 930#else
857 color.a = rgba::MAX_CC; 934 color.a = rgba::MAX_CC;
858#endif 935#endif
859} 936}
860 937
861void 938void
862rxvt_color::get (XColor &color) 939rxvt_color::get (XColor &color) const
863{ 940{
864 rgba c; 941 rgba c;
865 get (c); 942 get (c);
866 943
867 color.red = c.r; 944 color.red = c.r;
911 988
912 incr_buf = 0; 989 incr_buf = 0;
913 incr_buf_size = incr_buf_fill = 0; 990 incr_buf_size = incr_buf_fill = 0;
914 selection_wait = Sel_normal; 991 selection_wait = Sel_normal;
915 selection_type = selnum; 992 selection_type = selnum;
993 cb_sv = 0;
916} 994}
917 995
918void 996void
919rxvt_selection::stop () 997rxvt_selection::stop ()
920{ 998{
960} 1038}
961 1039
962void 1040void
963rxvt_selection::finish (char *data, unsigned int len) 1041rxvt_selection::finish (char *data, unsigned int len)
964{ 1042{
965 if (term) 1043 if (!cb_sv)
966 { 1044 {
967 if (data) 1045 if (data)
968 term->paste (data, len); 1046 term->paste (data, len);
969 1047
970 term->selection_req = 0; 1048 term->selection_req = 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines