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.118 by sf-exg, Sat Feb 12 00:50:04 2011 UTC vs.
Revision 1.148 by root, Wed Dec 17 14:25:01 2014 UTC

1/*----------------------------------------------------------------------* 1/*----------------------------------------------------------------------*
2 * File: rxvttoolkit.C 2 * File: rxvttoolkit.C
3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
4 * 4 *
5 * All portions of code are copyright by their respective author/s. 5 * All portions of code are copyright by their respective author/s.
6 * Copyright (c) 2003-2007 Marc Lehmann <pcg@goof.com> 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;
449 return false; 472 return false;
450 473
451 screen = DefaultScreen (dpy); 474 screen = DefaultScreen (dpy);
452 root = DefaultRootWindow (dpy); 475 root = DefaultRootWindow (dpy);
453 476
454 assert (ARRAY_LENGTH(xa_names) == NUM_XA); 477 assert (ecb_array_length (xa_names) == NUM_XA);
455 XInternAtoms (dpy, (char **)xa_names, NUM_XA, False, xa); 478 XInternAtoms (dpy, (char **)xa_names, NUM_XA, False, xa);
456 479
457 XrmSetDatabase (dpy, get_resources (false)); 480 XrmSetDatabase (dpy, get_resources (false));
458 481
459#ifdef POINTER_BLANK 482#ifdef POINTER_BLANK
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;
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;
695 766
696 // FUCKING Xft gets it wrong, of course, so work around it. 767 // FUCKING Xft gets it wrong, of course, so work around it.
697 // Transparency users should eat shit and die, and then 768 // Transparency users should eat shit and die, and then
698 // XRenderQueryPictIndexValues themselves plenty. 769 // XRenderQueryPictIndexValues themselves plenty.
699 if ((screen->visual->c_class == TrueColor) 770 if ((screen->visual->c_class == TrueColor)
700 && (format = XRenderFindVisualFormat (screen->dpy, screen->visual))) 771 && (format = XRenderFindVisualFormat (screen->dpy, screen->visual)))
701 { 772 {
702 // the fun lies in doing everything manually... 773 // the fun lies in doing everything manually...
703 c.color.red = color.r;
704 c.color.green = color.g;
705 c.color.blue = color.b;
706 c.color.alpha = alpha;
707 774
775 // Xft wants premultiplied alpha, but abuses the alpha channel
776 // as blend factor, and doesn't allow us to set the alpha channel
777 c.color.red = c.color.red * alpha / 0xffff;
778 c.color.green = c.color.green * alpha / 0xffff;
779 c.color.blue = c.color.blue * alpha / 0xffff;
780
708 c.pixel = insert_component (color.r, format->direct.redMask , format->direct.red ) 781 c.pixel = insert_component (c.color.red , format->direct.redMask , format->direct.red )
709 | insert_component (color.g, format->direct.greenMask, format->direct.green) 782 | insert_component (c.color.green, format->direct.greenMask, format->direct.green)
710 | insert_component (color.b, format->direct.blueMask , format->direct.blue ) 783 | insert_component (c.color.blue , format->direct.blueMask , format->direct.blue )
711 | insert_component (alpha , format->direct.alphaMask, format->direct.alpha); 784 | insert_component (alpha , format->direct.alphaMask, format->direct.alpha);
712 785
713 return true; 786 return true;
714 } 787 }
715 else 788 else
716 { 789 {
719 d.red = color.r; 792 d.red = color.r;
720 d.green = color.g; 793 d.green = color.g;
721 d.blue = color.b; 794 d.blue = color.b;
722 d.alpha = alpha; 795 d.alpha = alpha;
723 796
797 // XftColorAlloc always returns 100% transparent pixels(!)
724 return XftColorAllocValue (screen->dpy, screen->visual, screen->cmap, &d, &c); 798 if (XftColorAllocValue (screen->dpy, screen->visual, screen->cmap, &d, &c))
799 return true;
725 } 800 }
726#else 801#else
727 c.red = color.r; 802 c.red = color.r;
728 c.green = color.g; 803 c.green = color.g;
729 c.blue = color.b; 804 c.blue = color.b;
730 805
731 if (screen->visual->c_class == TrueColor) 806 if (screen->visual->c_class == TrueColor)
732 { 807 {
733 c.pixel = (color.r >> (16 - rxvt_popcount (screen->visual->red_mask )) << rxvt_ctz (screen->visual->red_mask )) 808 c.pixel = (color.r >> (16 - ecb_popcount32 (screen->visual->red_mask )) << ecb_ctz32 (screen->visual->red_mask ))
734 | (color.g >> (16 - rxvt_popcount (screen->visual->green_mask)) << rxvt_ctz (screen->visual->green_mask)) 809 | (color.g >> (16 - ecb_popcount32 (screen->visual->green_mask)) << ecb_ctz32 (screen->visual->green_mask))
735 | (color.b >> (16 - rxvt_popcount (screen->visual->blue_mask )) << rxvt_ctz (screen->visual->blue_mask )); 810 | (color.b >> (16 - ecb_popcount32 (screen->visual->blue_mask )) << ecb_ctz32 (screen->visual->blue_mask ));
736 811
737 return true; 812 return true;
738 } 813 }
739 else if (XAllocColor (screen->dpy, screen->cmap, &c)) 814 else if (XAllocColor (screen->dpy, screen->cmap, &c))
740 return true; 815 return true;
741 else 816#endif
817
742 c.pixel = (color.r + color.g + color.b) > 128*3 818 c.pixel = (color.r * 2 + color.g * 3 + color.b) >= 0x8000 * 6
743 ? WhitePixelOfScreen (DefaultScreenOfDisplay (screen->dpy)) 819 ? WhitePixelOfScreen (DefaultScreenOfDisplay (screen->dpy))
744 : BlackPixelOfScreen (DefaultScreenOfDisplay (screen->dpy)); 820 : BlackPixelOfScreen (DefaultScreenOfDisplay (screen->dpy));
745#endif
746 821
747 return false; 822 return false;
748} 823}
749 824
750bool 825bool
806 881
807 // many kilobytes transfer per colour, but pseudocolor isn't worth 882 // many kilobytes transfer per colour, but pseudocolor isn't worth
808 // many extra optimisations. 883 // many extra optimisations.
809 XQueryColors (screen->dpy, screen->cmap, colors, cmap_size); 884 XQueryColors (screen->dpy, screen->cmap, colors, cmap_size);
810 885
886 while (cmap_size)
887 {
811 int diff = 0x7fffffffUL; 888 int diff = 0x7fffffffL;
812 XColor *best = colors; 889 XColor *best = colors;
813 890
814 for (int i = 0; i < cmap_size; i++) 891 for (int i = 0; i < cmap_size; i++)
815 {
816 int d = (squared_diff<int> (color.r >> 2, colors [i].red >> 2))
817 + (squared_diff<int> (color.g >> 2, colors [i].green >> 2))
818 + (squared_diff<int> (color.b >> 2, colors [i].blue >> 2));
819
820 if (d < diff)
821 { 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 {
822 diff = d; 900 diff = d;
823 best = colors + i; 901 best = colors + i;
902 }
824 } 903 }
825 }
826 904
827 //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",
828 // 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);
829 907
830 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 }
831 915
832 delete [] colors; 916 delete [] colors;
833 } 917 }
834#endif 918#endif
835 919
836 return got; 920 return got;
837} 921}
838 922
839void 923void
840rxvt_color::get (rgba &color) 924rxvt_color::get (rgba &color) const
841{ 925{
842#if XFT 926#if XFT
927 //TODO premultiplied alpha??
843 color.r = c.color.red; 928 color.r = c.color.red;
844 color.g = c.color.green; 929 color.g = c.color.green;
845 color.b = c.color.blue; 930 color.b = c.color.blue;
846 color.a = c.color.alpha; 931 color.a = c.color.alpha;
847#else 932#else
851 color.a = rgba::MAX_CC; 936 color.a = rgba::MAX_CC;
852#endif 937#endif
853} 938}
854 939
855void 940void
856rxvt_color::get (XColor &color) 941rxvt_color::get (XColor &color) const
857{ 942{
858 rgba c; 943 rgba c;
859 get (c); 944 get (c);
860 945
861 color.red = c.r; 946 color.red = c.r;
892 lerp (c.a, to.a, percent) 977 lerp (c.a, to.a, percent)
893 ) 978 )
894 ); 979 );
895} 980}
896 981
897rxvt_selection::rxvt_selection (rxvt_display *disp, int selnum, Time tm, Window win, Atom prop, sel_cb cb, void *ptr) 982rxvt_selection::rxvt_selection (rxvt_display *disp, int selnum, Time tm, Window win, Atom prop, rxvt_term *term)
898: display (disp), request_time (tm), request_win (win), request_prop (prop), request_cb (cb), user_data (ptr) 983: display (disp), request_time (tm), request_win (win), request_prop (prop), term (term)
899{ 984{
900 assert (selnum >= Sel_Primary && selnum <= Sel_Clipboard); 985 assert (selnum >= Sel_Primary && selnum <= Sel_Clipboard);
901 986
902 timer_ev.set<rxvt_selection, &rxvt_selection::timer_cb> (this); 987 timer_ev.set<rxvt_selection, &rxvt_selection::timer_cb> (this);
903 timer_ev.repeat = 10.; 988 timer_ev.repeat = 10.;
905 990
906 incr_buf = 0; 991 incr_buf = 0;
907 incr_buf_size = incr_buf_fill = 0; 992 incr_buf_size = incr_buf_fill = 0;
908 selection_wait = Sel_normal; 993 selection_wait = Sel_normal;
909 selection_type = selnum; 994 selection_type = selnum;
995 cb_sv = 0;
996}
997
998void
999rxvt_selection::stop ()
1000{
1001 free (incr_buf);
1002 incr_buf = 0;
1003 timer_ev.stop ();
1004 x_ev.stop (display);
1005}
1006
1007rxvt_selection::~rxvt_selection ()
1008{
1009 stop ();
910} 1010}
911 1011
912void 1012void
913rxvt_selection::run () 1013rxvt_selection::run ()
914{ 1014{
915 int selnum = selection_type; 1015 int selnum = selection_type;
1016
1017#if ENABLE_FRILLS
1018 if (selnum == Sel_Primary && display->selection_owner)
1019 {
1020 /* internal selection */
1021 char *str = rxvt_wcstombs (display->selection_owner->selection.text, display->selection_owner->selection.len);
1022 finish (str, strlen (str));
1023 free (str);
1024 return;
1025 }
1026#endif
916 1027
917#if X_HAVE_UTF8_STRING 1028#if X_HAVE_UTF8_STRING
918 selection_type = Sel_UTF8String; 1029 selection_type = Sel_UTF8String;
919 if (request (display->xa[XA_UTF8_STRING], selnum)) 1030 if (request (display->xa[XA_UTF8_STRING], selnum))
920 return; 1031 return;
926 1037
927 // fallback to CUT_BUFFER0 if the requested property has no owner 1038 // fallback to CUT_BUFFER0 if the requested property has no owner
928 handle_selection (display->root, XA_CUT_BUFFER0, false); 1039 handle_selection (display->root, XA_CUT_BUFFER0, false);
929} 1040}
930 1041
931rxvt_selection::~rxvt_selection ()
932{
933 stop ();
934}
935
936void 1042void
937rxvt_selection::stop () 1043rxvt_selection::finish (char *data, unsigned int len)
938{ 1044{
939 free (incr_buf); 1045 if (!cb_sv)
940 incr_buf = 0; 1046 {
941 timer_ev.stop (); 1047 if (data)
942 x_ev.stop (display); 1048 term->paste (data, len);
1049
1050 term->selection_req = 0;
1051 delete this;
1052 }
1053#if ENABLE_PERL
1054 else
1055 {
1056 stop (); // we do not really trust perl callbacks
1057 rxvt_perl.selection_finish (this, data, len);
1058 }
1059#endif
943} 1060}
944 1061
945bool 1062bool
946rxvt_selection::request (Atom target, int selnum) 1063rxvt_selection::request (Atom target, int selnum)
947{ 1064{
1112bailout: 1229bailout:
1113 XFree (ct.value); 1230 XFree (ct.value);
1114 1231
1115 if (selection_wait == Sel_normal) 1232 if (selection_wait == Sel_normal)
1116 { 1233 {
1117 stop (); 1234 finish (data, data_len);
1118 request_cb (data, data_len, this);
1119 free (data); 1235 free (data);
1120 } 1236 }
1121} 1237}
1122 1238
1123void 1239void
1124rxvt_selection::timer_cb (ev::timer &w, int revents) 1240rxvt_selection::timer_cb (ev::timer &w, int revents)
1125{ 1241{
1126 if (selection_wait == Sel_incr) 1242 if (selection_wait == Sel_incr)
1127 rxvt_warn ("data loss: timeout on INCR selection paste, ignoring.\n"); 1243 rxvt_warn ("data loss: timeout on INCR selection paste, ignoring.\n");
1128 1244
1129 stop (); 1245 finish ();
1130 request_cb (NULL, 0, this);
1131} 1246}
1132 1247
1133void 1248void
1134rxvt_selection::x_cb (XEvent &xev) 1249rxvt_selection::x_cb (XEvent &xev)
1135{ 1250{
1142 handle_selection (xev.xproperty.window, xev.xproperty.atom, true); 1257 handle_selection (xev.xproperty.window, xev.xproperty.atom, true);
1143 break; 1258 break;
1144 1259
1145 case SelectionNotify: 1260 case SelectionNotify:
1146 if (selection_wait == Sel_normal 1261 if (selection_wait == Sel_normal
1147 && xev.xselection.time == request_time 1262 && xev.xselection.time == request_time)
1148 && xev.xselection.property == request_prop)
1149 { 1263 {
1150 timer_ev.stop (); 1264 timer_ev.stop ();
1151 handle_selection (xev.xselection.requestor, xev.xselection.property, true); 1265 handle_selection (xev.xselection.requestor, xev.xselection.property, true);
1152 } 1266 }
1153 break; 1267 break;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines