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.117 by sf-exg, Sat Feb 12 00:30:00 2011 UTC vs.
Revision 1.123 by sf-exg, Thu Mar 24 23:55:31 2011 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 2 of the License, or
892 lerp (c.a, to.a, percent) 892 lerp (c.a, to.a, percent)
893 ) 893 )
894 ); 894 );
895} 895}
896 896
897rxvt_selection::rxvt_selection (rxvt_display *disp, int selnum, Time tm, Window win, Atom prop, sel_cb cb, void *ptr) 897rxvt_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) 898: display (disp), request_time (tm), request_win (win), request_prop (prop), term (term)
899{ 899{
900 assert (selnum >= Sel_Primary && selnum <= Sel_Clipboard); 900 assert (selnum >= Sel_Primary && selnum <= Sel_Clipboard);
901 901
902 timer_ev.set<rxvt_selection, &rxvt_selection::timer_cb> (this); 902 timer_ev.set<rxvt_selection, &rxvt_selection::timer_cb> (this);
903 timer_ev.repeat = 10.; 903 timer_ev.repeat = 10.;
908 selection_wait = Sel_normal; 908 selection_wait = Sel_normal;
909 selection_type = selnum; 909 selection_type = selnum;
910} 910}
911 911
912void 912void
913rxvt_selection::stop ()
914{
915 free (incr_buf);
916 incr_buf = 0;
917 timer_ev.stop ();
918 x_ev.stop (display);
919}
920
921rxvt_selection::~rxvt_selection ()
922{
923 stop ();
924}
925
926void
913rxvt_selection::run () 927rxvt_selection::run ()
914{ 928{
915 int selnum = selection_type; 929 int selnum = selection_type;
930
931#if ENABLE_FRILLS
932 if (selnum == Sel_Primary && display->selection_owner)
933 {
934 /* internal selection */
935 char *str = rxvt_wcstombs (display->selection_owner->selection.text, display->selection_owner->selection.len);
936 finish (str, strlen (str));
937 free (str);
938 return;
939 }
940#endif
916 941
917#if X_HAVE_UTF8_STRING 942#if X_HAVE_UTF8_STRING
918 selection_type = Sel_UTF8String; 943 selection_type = Sel_UTF8String;
919 if (request (display->xa[XA_UTF8_STRING], selnum)) 944 if (request (display->xa[XA_UTF8_STRING], selnum))
920 return; 945 return;
926 951
927 // fallback to CUT_BUFFER0 if the requested property has no owner 952 // fallback to CUT_BUFFER0 if the requested property has no owner
928 handle_selection (display->root, XA_CUT_BUFFER0, false); 953 handle_selection (display->root, XA_CUT_BUFFER0, false);
929} 954}
930 955
931rxvt_selection::~rxvt_selection ()
932{
933 stop ();
934}
935
936void 956void
937rxvt_selection::stop () 957rxvt_selection::finish (char *data, unsigned int len)
938{ 958{
939 free (incr_buf); 959 if (term)
940 incr_buf = 0; 960 {
941 timer_ev.stop (); 961 if (data)
942 x_ev.stop (display); 962 term->paste (data, len);
963
964 term->selection_req = 0;
965 delete this;
966 }
967#if ENABLE_PERL
968 else
969 {
970 stop (); // we do not really trust perl callbacks
971 rxvt_perl.selection_finish (this, data, len);
972 }
973#endif
943} 974}
944 975
945bool 976bool
946rxvt_selection::request (Atom target, int selnum) 977rxvt_selection::request (Atom target, int selnum)
947{ 978{
1112bailout: 1143bailout:
1113 XFree (ct.value); 1144 XFree (ct.value);
1114 1145
1115 if (selection_wait == Sel_normal) 1146 if (selection_wait == Sel_normal)
1116 { 1147 {
1117 stop (); 1148 finish (data, data_len);
1118 request_cb (data, data_len, this, user_data);
1119 free (data); 1149 free (data);
1120 } 1150 }
1121} 1151}
1122 1152
1123void 1153void
1124rxvt_selection::timer_cb (ev::timer &w, int revents) 1154rxvt_selection::timer_cb (ev::timer &w, int revents)
1125{ 1155{
1126 if (selection_wait == Sel_incr) 1156 if (selection_wait == Sel_incr)
1127 rxvt_warn ("data loss: timeout on INCR selection paste, ignoring.\n"); 1157 rxvt_warn ("data loss: timeout on INCR selection paste, ignoring.\n");
1128 1158
1129 stop (); 1159 finish ();
1130 request_cb (NULL, 0, this, user_data);
1131} 1160}
1132 1161
1133void 1162void
1134rxvt_selection::x_cb (XEvent &xev) 1163rxvt_selection::x_cb (XEvent &xev)
1135{ 1164{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines