4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=ISO-8859-1
7 Content-Transfer-Encoding: 8bit
11 Problem: While waiting for the X selection Vim consumes a lot of CPU time
12 and hangs until a response is received.
13 Solution: Sleep a bit when the selection event hasn't been received yet.
14 Time out after a couple of seconds to avoid a hang when the
15 selection owner isn't responding.
19 *** ../vim-7.2.012/src/ui.c Mon Jul 14 21:47:49 2008
20 --- src/ui.c Sun Sep 7 16:54:35 2008
28 + int timed_out = FALSE;
35 case 3: type = text_atom; break;
36 default: type = XA_STRING;
39 XtGetSelectionValue(myShell, cbd->sel_atom, type,
40 clip_x11_request_selection_cb, (XtPointer)&success, CurrentTime);
44 * characters, then they will appear before the one that requested the
45 * paste! Don't worry, we will catch up with any other events later.
49 if (XCheckTypedEvent(dpy, SelectionNotify, &event))
51 if (XCheckTypedEvent(dpy, SelectionRequest, &event))
52 /* We may get a SelectionRequest here and if we don't handle
53 * it we hang. KDE klipper does this, for example. */
54 XtDispatchEvent(&event);
56 /* Do we need this? Probably not. */
59 ! /* Bernhard Walle solved a slow paste response in an X terminal by
60 ! * adding: usleep(10000); here. */
63 - /* this is where clip_x11_request_selection_cb() is actually called */
64 - XtDispatchEvent(&event);
70 /* Final fallback position - use the X CUT_BUFFER0 store */
72 * characters, then they will appear before the one that requested the
73 * paste! Don't worry, we will catch up with any other events later.
75 + start_time = time(NULL);
78 if (XCheckTypedEvent(dpy, SelectionNotify, &event))
80 + /* this is where clip_x11_request_selection_cb() is actually
82 + XtDispatchEvent(&event);
85 if (XCheckTypedEvent(dpy, SelectionRequest, &event))
86 /* We may get a SelectionRequest here and if we don't handle
87 * it we hang. KDE klipper does this, for example. */
88 XtDispatchEvent(&event);
90 + /* Time out after 2 to 3 seconds to avoid that we hang when the
91 + * other process doesn't respond. Note that the SelectionNotify
92 + * event may still come later when the selection owner comes back
93 + * to life and the text gets inserted unexpectedly (by xterm).
94 + * Don't know how to avoid that :-(. */
95 + if (time(NULL) > start_time + 2)
101 /* Do we need this? Probably not. */
104 ! /* Wait for 1 msec to avoid that we eat up all CPU time. */
105 ! ui_delay(1L, TRUE);
111 + /* don't do a retry with another type after timing out, otherwise we
112 + * hang for 15 seconds. */
117 /* Final fallback position - use the X CUT_BUFFER0 store */
118 *** ../vim-7.2.012/src/version.c Sun Sep 7 15:49:45 2008
119 --- src/version.c Sun Sep 7 21:45:55 2008
123 { /* Add new patch number below this line */
129 The users that I support would double-click on a landmine to find out
130 what happens. -- A system administrator
132 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
133 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
134 \\\ download, build and distribute -- http://www.A-A-P.org ///
135 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///