… | |
… | |
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.; |
904 | x_ev.set<rxvt_selection, &rxvt_selection::x_cb> (this); |
904 | x_ev.set<rxvt_selection, &rxvt_selection::x_cb> (this); |
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; |
|
|
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 (); |
|
|
924 | } |
|
|
925 | |
|
|
926 | void |
|
|
927 | rxvt_selection::run () |
|
|
928 | { |
|
|
929 | int selnum = selection_type; |
909 | |
930 | |
910 | #if X_HAVE_UTF8_STRING |
931 | #if X_HAVE_UTF8_STRING |
911 | selection_type = Sel_UTF8String; |
932 | selection_type = Sel_UTF8String; |
912 | if (request (display->xa[XA_UTF8_STRING], selnum)) |
933 | if (request (display->xa[XA_UTF8_STRING], selnum)) |
913 | return; |
934 | return; |
… | |
… | |
919 | |
940 | |
920 | // fallback to CUT_BUFFER0 if the requested property has no owner |
941 | // fallback to CUT_BUFFER0 if the requested property has no owner |
921 | handle_selection (display->root, XA_CUT_BUFFER0, false); |
942 | handle_selection (display->root, XA_CUT_BUFFER0, false); |
922 | } |
943 | } |
923 | |
944 | |
924 | rxvt_selection::~rxvt_selection () |
945 | void |
|
|
946 | rxvt_selection::finish (char *data, unsigned int len) |
925 | { |
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 | { |
926 | stop (); |
959 | stop (); |
927 | } |
960 | abort (); //TODO |
928 | |
961 | } |
929 | void |
962 | #endif |
930 | rxvt_selection::stop () |
|
|
931 | { |
|
|
932 | free (incr_buf); |
|
|
933 | incr_buf = 0; |
|
|
934 | timer_ev.stop (); |
|
|
935 | x_ev.stop (display); |
|
|
936 | } |
963 | } |
937 | |
964 | |
938 | bool |
965 | bool |
939 | rxvt_selection::request (Atom target, int selnum) |
966 | rxvt_selection::request (Atom target, int selnum) |
940 | { |
967 | { |
… | |
… | |
1105 | bailout: |
1132 | bailout: |
1106 | XFree (ct.value); |
1133 | XFree (ct.value); |
1107 | |
1134 | |
1108 | if (selection_wait == Sel_normal) |
1135 | if (selection_wait == Sel_normal) |
1109 | { |
1136 | { |
1110 | stop (); |
1137 | finish (data, data_len); |
1111 | request_cb (data, data_len, this, user_data); |
|
|
1112 | free (data); |
1138 | free (data); |
1113 | } |
1139 | } |
1114 | } |
1140 | } |
1115 | |
1141 | |
1116 | void |
1142 | void |
1117 | rxvt_selection::timer_cb (ev::timer &w, int revents) |
1143 | rxvt_selection::timer_cb (ev::timer &w, int revents) |
1118 | { |
1144 | { |
1119 | if (selection_wait == Sel_incr) |
1145 | if (selection_wait == Sel_incr) |
1120 | rxvt_warn ("data loss: timeout on INCR selection paste, ignoring.\n"); |
1146 | rxvt_warn ("data loss: timeout on INCR selection paste, ignoring.\n"); |
1121 | |
1147 | |
1122 | stop (); |
1148 | finish (); |
1123 | request_cb (NULL, 0, this, user_data); |
|
|
1124 | } |
1149 | } |
1125 | |
1150 | |
1126 | void |
1151 | void |
1127 | rxvt_selection::x_cb (XEvent &xev) |
1152 | rxvt_selection::x_cb (XEvent &xev) |
1128 | { |
1153 | { |