comparison src/ui.c @ 1719:0670d0df210a v7.2.017

updated for version 7.2-017
author vimboss
date Sun, 14 Sep 2008 13:58:34 +0000
parents afb64d9f5b8e
children f10fe14748e2
comparison
equal deleted inserted replaced
1718:a27c581d2618 1719:0670d0df210a
2018 else 2018 else
2019 cbd = &clip_star; 2019 cbd = &clip_star;
2020 2020
2021 if (value == NULL || *length == 0) 2021 if (value == NULL || *length == 0)
2022 { 2022 {
2023 clip_free_selection(cbd); /* ??? [what's the query?] */ 2023 clip_free_selection(cbd); /* nothing received, clear register */
2024 *(int *)success = FALSE; 2024 *(int *)success = FALSE;
2025 return; 2025 return;
2026 } 2026 }
2027 motion_type = MCHAR; 2027 motion_type = MCHAR;
2028 p = (char_u *)value; 2028 p = (char_u *)value;
2074 int status; 2074 int status;
2075 2075
2076 text_prop.value = (unsigned char *)value; 2076 text_prop.value = (unsigned char *)value;
2077 text_prop.encoding = *type; 2077 text_prop.encoding = *type;
2078 text_prop.format = *format; 2078 text_prop.format = *format;
2079 text_prop.nitems = STRLEN(value); 2079 text_prop.nitems = len;
2080 status = XmbTextPropertyToTextList(X_DISPLAY, &text_prop, 2080 status = XmbTextPropertyToTextList(X_DISPLAY, &text_prop,
2081 &text_list, &n_text); 2081 &text_list, &n_text);
2082 if (status != Success || n_text < 1) 2082 if (status != Success || n_text < 1)
2083 { 2083 {
2084 *(int *)success = FALSE; 2084 *(int *)success = FALSE;
2129 case 1: type = vim_atom; break; 2129 case 1: type = vim_atom; break;
2130 case 2: type = compound_text_atom; break; 2130 case 2: type = compound_text_atom; break;
2131 case 3: type = text_atom; break; 2131 case 3: type = text_atom; break;
2132 default: type = XA_STRING; 2132 default: type = XA_STRING;
2133 } 2133 }
2134 success = FALSE; 2134 success = MAYBE;
2135 XtGetSelectionValue(myShell, cbd->sel_atom, type, 2135 XtGetSelectionValue(myShell, cbd->sel_atom, type,
2136 clip_x11_request_selection_cb, (XtPointer)&success, CurrentTime); 2136 clip_x11_request_selection_cb, (XtPointer)&success, CurrentTime);
2137 2137
2138 /* Make sure the request for the selection goes out before waiting for 2138 /* Make sure the request for the selection goes out before waiting for
2139 * a response. */ 2139 * a response. */
2143 * Wait for result of selection request, otherwise if we type more 2143 * Wait for result of selection request, otherwise if we type more
2144 * characters, then they will appear before the one that requested the 2144 * characters, then they will appear before the one that requested the
2145 * paste! Don't worry, we will catch up with any other events later. 2145 * paste! Don't worry, we will catch up with any other events later.
2146 */ 2146 */
2147 start_time = time(NULL); 2147 start_time = time(NULL);
2148 for (;;) 2148 while (success == MAYBE)
2149 { 2149 {
2150 if (XCheckTypedEvent(dpy, SelectionNotify, &event)) 2150 if (XCheckTypedEvent(dpy, SelectionNotify, &event)
2151 || XCheckTypedEvent(dpy, SelectionRequest, &event)
2152 || XCheckTypedEvent(dpy, PropertyNotify, &event))
2151 { 2153 {
2152 /* this is where clip_x11_request_selection_cb() is actually 2154 /* This is where clip_x11_request_selection_cb() should be
2153 * called */ 2155 * called. It may actually happen a bit later, so we loop
2156 * until "success" changes.
2157 * We may get a SelectionRequest here and if we don't handle
2158 * it we hang. KDE klipper does this, for example.
2159 * We need to handle a PropertyNotify for large selections. */
2154 XtDispatchEvent(&event); 2160 XtDispatchEvent(&event);
2155 break; 2161 continue;
2156 } 2162 }
2157 if (XCheckTypedEvent(dpy, SelectionRequest, &event))
2158 /* We may get a SelectionRequest here and if we don't handle
2159 * it we hang. KDE klipper does this, for example. */
2160 XtDispatchEvent(&event);
2161 2163
2162 /* Time out after 2 to 3 seconds to avoid that we hang when the 2164 /* Time out after 2 to 3 seconds to avoid that we hang when the
2163 * other process doesn't respond. Note that the SelectionNotify 2165 * other process doesn't respond. Note that the SelectionNotify
2164 * event may still come later when the selection owner comes back 2166 * event may still come later when the selection owner comes back
2165 * to life and the text gets inserted unexpectedly (by xterm). 2167 * to life and the text gets inserted unexpectedly. Don't know
2166 * Don't know how to avoid that :-(. */ 2168 * why that happens or how to avoid that :-(. */
2167 if (time(NULL) > start_time + 2) 2169 if (time(NULL) > start_time + 2)
2168 { 2170 {
2169 timed_out = TRUE; 2171 timed_out = TRUE;
2170 break; 2172 break;
2171 } 2173 }
2175 2177
2176 /* Wait for 1 msec to avoid that we eat up all CPU time. */ 2178 /* Wait for 1 msec to avoid that we eat up all CPU time. */
2177 ui_delay(1L, TRUE); 2179 ui_delay(1L, TRUE);
2178 } 2180 }
2179 2181
2180 if (success) 2182 if (success == TRUE)
2181 return; 2183 return;
2182 2184
2183 /* don't do a retry with another type after timing out, otherwise we 2185 /* don't do a retry with another type after timing out, otherwise we
2184 * hang for 15 seconds. */ 2186 * hang for 15 seconds. */
2185 if (timed_out) 2187 if (timed_out)