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 | |
897 | rxvt_selection::rxvt_selection (rxvt_display *disp, int selnum, Time tm, Window win, Atom prop, sel_cb cb, void *ptr) |
897 | rxvt_selection::rxvt_selection (rxvt_display *disp, int selnum, Time tm, Window win, Atom prop, rxvt_term *term, void *cb_sv) |
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), cb_sv (cb_sv) |
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.; |
… | |
… | |
905 | |
905 | |
906 | incr_buf = 0; |
906 | incr_buf = 0; |
907 | incr_buf_size = incr_buf_fill = 0; |
907 | incr_buf_size = incr_buf_fill = 0; |
908 | selection_wait = Sel_normal; |
908 | selection_wait = Sel_normal; |
909 | selection_type = selnum; |
909 | selection_type = selnum; |
|
|
910 | } |
|
|
911 | |
|
|
912 | void |
|
|
913 | rxvt_selection::stop () |
|
|
914 | { |
|
|
915 | free (incr_buf); |
|
|
916 | incr_buf = 0; |
|
|
917 | timer_ev.stop (); |
|
|
918 | x_ev.stop (display); |
|
|
919 | } |
|
|
920 | |
|
|
921 | rxvt_selection::~rxvt_selection () |
|
|
922 | { |
|
|
923 | stop (); |
910 | } |
924 | } |
911 | |
925 | |
912 | void |
926 | void |
913 | rxvt_selection::run () |
927 | rxvt_selection::run () |
914 | { |
928 | { |
… | |
… | |
926 | |
940 | |
927 | // fallback to CUT_BUFFER0 if the requested property has no owner |
941 | // fallback to CUT_BUFFER0 if the requested property has no owner |
928 | handle_selection (display->root, XA_CUT_BUFFER0, false); |
942 | handle_selection (display->root, XA_CUT_BUFFER0, false); |
929 | } |
943 | } |
930 | |
944 | |
931 | rxvt_selection::~rxvt_selection () |
945 | void |
|
|
946 | rxvt_selection::finish (char *data, unsigned int len) |
932 | { |
947 | { |
|
|
948 | if (term) |
|
|
949 | { |
|
|
950 | if (data) |
|
|
951 | term->paste (data, len); |
|
|
952 | |
|
|
953 | term->selection_req = 0; |
|
|
954 | delete this; |
|
|
955 | } |
|
|
956 | #if ENABLE_PERL |
|
|
957 | else |
|
|
958 | { |
933 | stop (); |
959 | stop (); |
934 | } |
960 | abort (); //TODO |
935 | |
961 | } |
936 | void |
962 | #endif |
937 | rxvt_selection::stop () |
|
|
938 | { |
|
|
939 | free (incr_buf); |
|
|
940 | incr_buf = 0; |
|
|
941 | timer_ev.stop (); |
|
|
942 | x_ev.stop (display); |
|
|
943 | } |
963 | } |
944 | |
964 | |
945 | bool |
965 | bool |
946 | rxvt_selection::request (Atom target, int selnum) |
966 | rxvt_selection::request (Atom target, int selnum) |
947 | { |
967 | { |
… | |
… | |
1112 | bailout: |
1132 | bailout: |
1113 | XFree (ct.value); |
1133 | XFree (ct.value); |
1114 | |
1134 | |
1115 | if (selection_wait == Sel_normal) |
1135 | if (selection_wait == Sel_normal) |
1116 | { |
1136 | { |
1117 | stop (); |
1137 | finish (data, data_len); |
1118 | request_cb (data, data_len, this, user_data); |
|
|
1119 | free (data); |
1138 | free (data); |
1120 | } |
1139 | } |
1121 | } |
1140 | } |
1122 | |
1141 | |
1123 | void |
1142 | void |
1124 | rxvt_selection::timer_cb (ev::timer &w, int revents) |
1143 | rxvt_selection::timer_cb (ev::timer &w, int revents) |
1125 | { |
1144 | { |
1126 | if (selection_wait == Sel_incr) |
1145 | if (selection_wait == Sel_incr) |
1127 | rxvt_warn ("data loss: timeout on INCR selection paste, ignoring.\n"); |
1146 | rxvt_warn ("data loss: timeout on INCR selection paste, ignoring.\n"); |
1128 | |
1147 | |
1129 | stop (); |
1148 | finish (); |
1130 | request_cb (NULL, 0, this, user_data); |
|
|
1131 | } |
1149 | } |
1132 | |
1150 | |
1133 | void |
1151 | void |
1134 | rxvt_selection::x_cb (XEvent &xev) |
1152 | rxvt_selection::x_cb (XEvent &xev) |
1135 | { |
1153 | { |