4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
11 Problem: X11 clipboard doesn't work in Athena/Motif GUI. First selection
12 after a shell command doesn't work.
13 Solution: When using the GUI use XtLastTimestampProcessed() instead of
14 changing a property. (partly by Toni Ronkko)
15 When executing a shell command disown the selection.
16 Files: src/ui.c, src/os_unix.c
19 *** ../vim-7.3.010/src/ui.c 2010-08-15 21:57:31.000000000 +0200
20 --- src/ui.c 2010-09-21 22:08:22.000000000 +0200
25 /* Always own the selection, we might have lost it without being
29 int was_owned = cbd->owned;
33 /* Always own the selection, we might have lost it without being
34 ! * notified, e.g. during a ":sh" command. */
37 int was_owned = cbd->owned;
42 static Boolean clip_x11_convert_selection_cb __ARGS((Widget, Atom *, Atom *, Atom *, XtPointer *, long_u *, int *));
44 static void clip_x11_lose_ownership_cb __ARGS((Widget, Atom *));
46 static void clip_x11_timestamp_cb __ARGS((Widget w, XtPointer n, XEvent *event, Boolean *cont));
49 * Property callback to get a timestamp for XtOwnSelection.
53 static Boolean clip_x11_convert_selection_cb __ARGS((Widget, Atom *, Atom *, Atom *, XtPointer *, long_u *, int *));
54 static void clip_x11_lose_ownership_cb __ARGS((Widget, Atom *));
55 static void clip_x11_timestamp_cb __ARGS((Widget w, XtPointer n, XEvent *event, Boolean *cont));
56 + static void clip_x11_request_selection_cb __ARGS((Widget, XtPointer, Atom *, Atom *, XtPointer, long_u *, int *));
59 * Property callback to get a timestamp for XtOwnSelection.
64 /* Get the selection, using the event timestamp. */
65 ! XtOwnSelection(w, xproperty->atom, xproperty->time,
66 ! clip_x11_convert_selection_cb, clip_x11_lose_ownership_cb, NULL);
73 /* Get the selection, using the event timestamp. */
74 ! if (XtOwnSelection(w, xproperty->atom, xproperty->time,
75 ! clip_x11_convert_selection_cb, clip_x11_lose_ownership_cb,
78 ! /* Set the "owned" flag now, there may have been a call to
79 ! * lose_ownership_cb in between. */
80 ! if (xproperty->atom == clip_plus.sel_atom)
81 ! clip_plus.owned = TRUE;
83 ! clip_star.owned = TRUE;
90 /*(XtEventHandler)*/clip_x11_timestamp_cb, (XtPointer)NULL);
93 - static void clip_x11_request_selection_cb __ARGS((Widget, XtPointer, Atom *, Atom *, XtPointer, long_u *, int *));
96 clip_x11_request_selection_cb(w, success, sel_atom, type, value, length,
103 clip_x11_lose_selection(myShell, cbd)
107 XtDisownSelection(myShell, cbd->sel_atom, CurrentTime);
111 clip_x11_lose_selection(myShell, cbd)
115 XtDisownSelection(myShell, cbd->sel_atom, CurrentTime);
120 clip_x11_own_selection(myShell, cbd)
124 ! /* Get the time by a zero-length append, clip_x11_timestamp_cb will be
125 ! * called with the current timestamp. */
126 ! if (!XChangeProperty(XtDisplay(myShell), XtWindow(myShell), cbd->sel_atom,
127 ! timestamp_atom, 32, PropModeAppend, NULL, 0))
129 /* Flush is required in a terminal as nothing else is doing it. */
130 XFlush(XtDisplay(myShell));
135 clip_x11_own_selection(myShell, cbd)
139 ! /* When using the GUI we have proper timestamps, use the one of the last
140 ! * event. When in the console we don't get events (the terminal gets
141 ! * them), Get the time by a zero-length append, clip_x11_timestamp_cb will
142 ! * be called with the current timestamp. */
146 ! if (XtOwnSelection(myShell, cbd->sel_atom,
147 ! XtLastTimestampProcessed(XtDisplay(myShell)),
148 ! clip_x11_convert_selection_cb, clip_x11_lose_ownership_cb,
155 + if (!XChangeProperty(XtDisplay(myShell), XtWindow(myShell),
156 + cbd->sel_atom, timestamp_atom, 32, PropModeAppend, NULL, 0))
159 /* Flush is required in a terminal as nothing else is doing it. */
160 XFlush(XtDisplay(myShell));
162 *** ../vim-7.3.010/src/os_unix.c 2010-08-15 21:57:30.000000000 +0200
163 --- src/os_unix.c 2010-09-21 21:59:25.000000000 +0200
170 + # if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
171 + static void loose_clipboard __ARGS((void));
174 + * Called when Vim is going to sleep or execute a shell command.
175 + * We can't respond to requests for the X selections. Lose them, otherwise
176 + * other applications will hang. But first copy the text to cut buffer 0.
181 + if (clip_star.owned || clip_plus.owned)
183 + x11_export_final_selection();
184 + if (clip_star.owned)
185 + clip_lose_selection(&clip_star);
186 + if (clip_plus.owned)
187 + clip_lose_selection(&clip_plus);
188 + if (x11_display != NULL)
189 + XFlush(x11_display);
195 * If the machine has job control, use it to suspend the program,
196 * otherwise fake it by starting a new shell.
199 out_flush(); /* needed to disable mouse on some systems */
201 # if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
202 ! /* Since we are going to sleep, we can't respond to requests for the X
203 ! * selections. Lose them, otherwise other applications will hang. But
204 ! * first copy the text to cut buffer 0. */
205 ! if (clip_star.owned || clip_plus.owned)
207 ! x11_export_final_selection();
208 ! if (clip_star.owned)
209 ! clip_lose_selection(&clip_star);
210 ! if (clip_plus.owned)
211 ! clip_lose_selection(&clip_plus);
212 ! if (x11_display != NULL)
213 ! XFlush(x11_display);
217 # if defined(_REENTRANT) && defined(SIGCONT)
219 out_flush(); /* needed to disable mouse on some systems */
221 # if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
225 # if defined(_REENTRANT) && defined(SIGCONT)
229 if (options & SHELL_COOKED)
230 settmode(TMODE_COOK); /* set to normal mode */
232 + # if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
238 x = system(""); /* this starts an interactive shell in emx */
242 int did_settmode = FALSE; /* settmode(TMODE_RAW) called */
245 if (options & SHELL_COOKED)
246 settmode(TMODE_COOK); /* set to normal mode */
248 ! newcmd = vim_strsave(p_sh);
249 ! if (newcmd == NULL) /* out of memory */
253 * Do this loop twice:
256 int did_settmode = FALSE; /* settmode(TMODE_RAW) called */
258 + newcmd = vim_strsave(p_sh);
259 + if (newcmd == NULL) /* out of memory */
263 if (options & SHELL_COOKED)
264 settmode(TMODE_COOK); /* set to normal mode */
266 ! # if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
271 * Do this loop twice:
272 *** ../vim-7.3.010/src/version.c 2010-09-21 17:34:26.000000000 +0200
273 --- src/version.c 2010-09-21 20:45:02.000000000 +0200
277 { /* Add new patch number below this line */
283 hundred-and-one symptoms of being an internet addict:
284 184. You no longer ask prospective dates what their sign is, instead
285 your line is "Hi, what's your URL?"
287 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
288 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
289 \\\ download, build and distribute -- http://www.A-A-P.org ///
290 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///