summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gui_gtk_x11.c9
-rw-r--r--src/os_unix.c1
-rw-r--r--src/proto/ui.pro1
-rw-r--r--src/ui.c89
4 files changed, 86 insertions, 14 deletions
diff --git a/src/gui_gtk_x11.c b/src/gui_gtk_x11.c
index 2db203b855..5cbe9a3c3a 100644
--- a/src/gui_gtk_x11.c
+++ b/src/gui_gtk_x11.c
@@ -88,6 +88,7 @@ extern void bonobo_dock_item_set_behavior(BonoboDockItem *dock_item, BonoboDockI
#ifdef HAVE_X11_SUNKEYSYM_H
# include <X11/Sunkeysym.h>
+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 UNUSED,
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 UNUSED,
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
index 4cb1d4a7e7..365e965f81 100644
--- 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
index 87cee8b92c..b022baa55d 100644
--- 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
index 9ca902be62..a925def2f2 100644
--- 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);
}
-#endif
}
+#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 extended selection format */
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, cbd)
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_atom, target, type, value, length, format)
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;
}