# HG changeset patch # User Bram Moolenaar # Date 1277179632 -7200 # Node ID 917fff7bc09d4cc19795a92aaffa8e87b07d443b # Parent fb627e94e6c6c209129d353b5b40a678226adefc Fixes for time in clipboard request. Also fix ownership. (David Fries) diff --git a/runtime/doc/todo.txt b/runtime/doc/todo.txt --- a/runtime/doc/todo.txt +++ b/runtime/doc/todo.txt @@ -1088,18 +1088,17 @@ Vim 7.3: - using NSIS 2.46: install on Windows 7 works, but no "Edit with Vim" menu. Use register_shell_extension()? (George Reilly, 2010 May 26) Ron's version: http://dev.ronware.org/p/vim/finfo?name=gvim.nsi -- Patch for conceal from Vince, 2010 Jun 15. And another June 16. - However: more generic patch on the way. +- Patch for conceal feature from Vince, 2010 June 16. + Needs some more testing. - undofile: keep markers where the file was written/read, so that it's easy to go back to a saved version of the file: ":earlier 1f" (f for file)? Also add ":earlier 1d" (d for day). Something like changenr() to see the "file saved" marker? Show "file saved" marker in :undolist - Function to get undo tree: undotree(). List of lists. Each entry is a +- Function to get undo tree: undotree(). List of lists. Each entry is a dictionary: {'nr': 2, 'time': 1234, 'saved': 1} -- Remove support for GTK 1? Patch by James Vega, Jun 11. +- Remove support for GTK 1? Patch by James Vega, Jun 11 (removes too much). Patches to include: -- Patch for X clibboard CurrentTime, (Fries, 2010 Jun 20) - Patch for Lisp support with ECL (Mikael Jansson, 2008 Oct 25) - Minor patches from Dominique Pelle, 2010 May 15 - Gvimext patch to support wide file names. (Szabolcs Horvat 2008 Sep 10) diff --git a/src/gui_gtk_x11.c b/src/gui_gtk_x11.c --- a/src/gui_gtk_x11.c +++ b/src/gui_gtk_x11.c @@ -88,6 +88,7 @@ extern void bonobo_dock_item_set_behavio #ifdef HAVE_X11_SUNKEYSYM_H # include +static guint32 clipboard_event_time = CurrentTime; #endif /* @@ -996,6 +997,7 @@ key_press_event(GtkWidget *widget UNUSED guint state; char_u *s, *d; + clipboard_event_time = event->time; key_sym = event->keyval; state = event->state; #ifndef HAVE_GTK2 /* deprecated */ @@ -1258,6 +1260,7 @@ key_release_event(GtkWidget *widget UNUS GdkEventKey *event, gpointer data UNUSED) { + clipboard_event_time = event->time; /* * GTK+ 2 input methods may do fancy stuff on key release events too. * With the default IM for instance, you can enter any UCS code point @@ -1870,6 +1873,8 @@ button_press_event(GtkWidget *widget, int x, y; int_u vim_modifiers; + clipboard_event_time = event->time; + /* Make sure we have focus now we've been selected */ if (gtk_socket_id != 0 && !GTK_WIDGET_HAS_FOCUS(widget)) gtk_widget_grab_focus(widget); @@ -1989,6 +1994,8 @@ button_release_event(GtkWidget *widget U int x, y; int_u vim_modifiers; + clipboard_event_time = event->time; + /* Remove any motion "machine gun" timers used for automatic further extension of allocation areas if outside of the applications window area .*/ @@ -6883,7 +6890,7 @@ clip_mch_own_selection(VimClipboard *cbd int success; success = gtk_selection_owner_set(gui.drawarea, cbd->gtk_sel_atom, - (guint32)GDK_CURRENT_TIME); + clipboard_event_time); gui_mch_update(); return (success) ? OK : FAIL; } diff --git a/src/os_unix.c b/src/os_unix.c --- a/src/os_unix.c +++ b/src/os_unix.c @@ -6466,6 +6466,7 @@ setup_term_clip() return; x11_setup_atoms(xterm_dpy); + x11_setup_selection(xterm_Shell); if (x11_display == NULL) x11_display = xterm_dpy; diff --git a/src/proto/ui.pro b/src/proto/ui.pro --- a/src/proto/ui.pro +++ b/src/proto/ui.pro @@ -47,6 +47,7 @@ int check_col __ARGS((int col)); int check_row __ARGS((int row)); void open_app_context __ARGS((void)); void x11_setup_atoms __ARGS((Display *dpy)); +void x11_setup_selection __ARGS((Widget myShell)); void clip_x11_request_selection __ARGS((Widget myShell, Display *dpy, VimClipboard *cbd)); void clip_x11_lose_selection __ARGS((Widget myShell, VimClipboard *cbd)); int clip_x11_own_selection __ARGS((Widget myShell, VimClipboard *cbd)); diff --git a/src/ui.c b/src/ui.c --- a/src/ui.c +++ b/src/ui.c @@ -467,11 +467,15 @@ clip_own_selection(cbd) * Also want to check somehow that we are reading from the keyboard rather * than a mapping etc. */ - if (!cbd->owned && cbd->available) +#ifdef FEAT_X11 + /* Always own the selection, we might have lost it without being + * notified. */ + if (cbd->available) { + int was_owned = cbd->owned; + cbd->owned = (clip_gen_own_selection(cbd) == OK); -#ifdef FEAT_X11 - if (cbd == &clip_star) + if (!was_owned && cbd == &clip_star) { /* May have to show a different kind of highlighting for the * selected area. There is no specific redraw command for this, @@ -483,8 +487,12 @@ clip_own_selection(cbd) && hl_attr(HLF_V) != hl_attr(HLF_VNC)) redraw_curbuf_later(INVERTED_ALL); } + } +#else + /* Only own the clibpard when we didn't own it yet. */ + if (!cbd->owned && cbd->available) + cbd->owned = (clip_gen_own_selection(cbd) == OK); #endif - } } void @@ -1967,6 +1975,7 @@ static Atom vimenc_atom; /* Vim's extend static Atom compound_text_atom; static Atom text_atom; static Atom targets_atom; +static Atom timestamp_atom; /* Used to get a timestamp */ void x11_setup_atoms(dpy) @@ -1978,15 +1987,70 @@ x11_setup_atoms(dpy) #endif compound_text_atom = XInternAtom(dpy, "COMPOUND_TEXT", False); text_atom = XInternAtom(dpy, "TEXT", False); - targets_atom = XInternAtom(dpy, "TARGETS", False); + targets_atom = XInternAtom(dpy, "TARGETS", False); clip_star.sel_atom = XA_PRIMARY; - clip_plus.sel_atom = XInternAtom(dpy, "CLIPBOARD", False); + clip_plus.sel_atom = XInternAtom(dpy, "CLIPBOARD", False); + timestamp_atom = XInternAtom(dpy, "TIMESTAMP", False); } /* * X Selection stuff, for cutting and pasting text to other windows. */ +static Boolean clip_x11_convert_selection_cb __ARGS((Widget, Atom *, Atom *, Atom *, XtPointer *, long_u *, int *)); + +static void clip_x11_lose_ownership_cb __ARGS((Widget, Atom *)); + +static void clip_x11_timestamp_cb __ARGS((Widget w, XtPointer n, XEvent *event, Boolean *cont)); + +/* + * Property callback to get a timestamp for XtOwnSelection. + */ + static void +clip_x11_timestamp_cb(w, n, event, cont) + Widget w; + XtPointer n UNUSED; + XEvent *event; + Boolean *cont UNUSED; +{ + Atom actual_type; + int format; + unsigned long nitems, bytes_after; + unsigned char *prop=NULL; + XPropertyEvent *xproperty=&event->xproperty; + + /* Must be a property notify, state can't be Delete (True), has to be + * one of the supported selection types. */ + if (event->type != PropertyNotify || xproperty->state + || (xproperty->atom != clip_star.sel_atom + && xproperty->atom != clip_plus.sel_atom)) + return; + + if (XGetWindowProperty(xproperty->display, xproperty->window, + xproperty->atom, 0, 0, False, timestamp_atom, &actual_type, &format, + &nitems, &bytes_after, &prop)) + return; + + if (prop) + XFree(prop); + + /* Make sure the property type is "TIMESTAMP" and it's 32 bits. */ + if (actual_type != timestamp_atom || format != 32) + return; + + /* Get the selection, using the event timestamp. */ + XtOwnSelection(w, xproperty->atom, xproperty->time, + clip_x11_convert_selection_cb, clip_x11_lose_ownership_cb, NULL); +} + + void +x11_setup_selection(w) + Widget w; +{ + XtAddEventHandler(w, PropertyChangeMask, False, + /*(XtEventHandler)*/clip_x11_timestamp_cb, (XtPointer)NULL); +} + static void clip_x11_request_selection_cb __ARGS((Widget, XtPointer, Atom *, Atom *, XtPointer, long_u *, int *)); static void @@ -2186,8 +2250,6 @@ clip_x11_request_selection(myShell, dpy, yank_cut_buffer0(dpy, cbd); } -static Boolean clip_x11_convert_selection_cb __ARGS((Widget, Atom *, Atom *, Atom *, XtPointer *, long_u *, int *)); - static Boolean clip_x11_convert_selection_cb(w, sel_atom, target, type, value, length, format) Widget w UNUSED; @@ -2315,8 +2377,6 @@ clip_x11_convert_selection_cb(w, sel_ato return True; } -static void clip_x11_lose_ownership_cb __ARGS((Widget, Atom *)); - static void clip_x11_lose_ownership_cb(w, sel_atom) Widget w UNUSED; @@ -2341,10 +2401,13 @@ clip_x11_own_selection(myShell, cbd) Widget myShell; VimClipboard *cbd; { - if (XtOwnSelection(myShell, cbd->sel_atom, CurrentTime, - clip_x11_convert_selection_cb, clip_x11_lose_ownership_cb, - NULL) == False) + /* Get the time by a zero-length append, clip_x11_timestamp_cb will be + * called with the current timestamp. */ + if (!XChangeProperty(XtDisplay(myShell), XtWindow(myShell), cbd->sel_atom, + timestamp_atom, 32, PropModeAppend, NULL, 0)) return FAIL; + /* Flush is required in a terminal as nothing else is doing it. */ + XFlush(XtDisplay(myShell)); return OK; }