Clipboard integration with X: data loss on quit

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Clipboard integration with X: data loss on quit

Sarah Strong
When you quit vim in X11-based systems, you lose any data that was
copied from vim to the system clipboard. You can find more information
about this bug and how to fix it at
https://wiki.ubuntu.com/ClipboardPersistence.

Steps to Reproduce:
Pre-requisite: Machine running an X11-based window manager, without
extended clipboard manager such as Klipper. Tested on Ubuntu Lucid.

1. Copy text to system clipboard in vim using the + register. For
instance, you can grab a line with <Esc>"+yy
2. Paste it to another window, this works as expected.
3. Quit vim.
4. Try to paste, there is now nothing in the clipboard.

This is also reproducible in vim-gtk and vim-gnome.
Note that copying done with a right-click in vim or gvim does work,
because that's not handled by vim directly.

I'm trying to fix the bug by adding calls to
gtk_clipboard_set_can_store and gtk_clipboard_store to gui_gtk_x11.c,
but I haven't had much luck so far. I'd really appreciate any input I
could get from more experienced developers.

Thanks!
- Sarah Strong

--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|

Re: Clipboard integration with X: data loss on quit

Peter Odding-3
Hi Sara,

> When you quit vim in X11-based systems, you lose any data that was
> copied from vim to the system clipboard. You can find more information
> about this bug and how to fix it at
> https://wiki.ubuntu.com/ClipboardPersistence.

I'm not 100% sure but I think this is an X11 security measure. So I'd
check that out before diving too deep into the Vim sources...

  - Peter Odding

--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|

Re: Clipboard integration with X: data loss on quit

Sarah Strong
>> When you quit vim in X11-based systems, you lose any data that was
>> copied from vim to the system clipboard. You can find more information
>> about this bug and how to fix it at
>> https://wiki.ubuntu.com/ClipboardPersistence.
>
> I'm not 100% sure but I think this is an X11 security measure. So I'd check
> that out before diving too deep into the Vim sources...

It isn't, but taking a conservative approach to copies by only copying
a reference to the data until it's actually pasted is a deliberate
choice by X for performance reasons. That's why the ClipboardManager
specification exists - to allow applications like vim to say "I'm a
user-facing application and I'd like my contents to be available after
I've quit," without changing X's basic approach. You can check out
http://en.wikipedia.org/wiki/Clipboard_manager and
http://freedesktop.org/wiki/ClipboardManager for more information.

Thanks!
-Sarah Strong

--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|

Re: Clipboard integration with X: data loss on quit

Tony Mechelynck
On 18/06/10 16:15, Sarah Strong wrote:

>>> When you quit vim in X11-based systems, you lose any data that was
>>> copied from vim to the system clipboard. You can find more information
>>> about this bug and how to fix it at
>>> https://wiki.ubuntu.com/ClipboardPersistence.
>>
>> I'm not 100% sure but I think this is an X11 security measure. So I'd check
>> that out before diving too deep into the Vim sources...
>
> It isn't, but taking a conservative approach to copies by only copying
> a reference to the data until it's actually pasted is a deliberate
> choice by X for performance reasons. That's why the ClipboardManager
> specification exists - to allow applications like vim to say "I'm a
> user-facing application and I'd like my contents to be available after
> I've quit," without changing X's basic approach. You can check out
> http://en.wikipedia.org/wiki/Clipboard_manager and
> http://freedesktop.org/wiki/ClipboardManager for more information.
>
> Thanks!
> -Sarah Strong
>

According to the help, Vim does save register + when quitting, as follows:

> *x11-cut-buffer*
> There are, by default, 8 cut-buffers: CUT_BUFFER0 to CUT_BUFFER7.  Vim only
> uses CUT_BUFFER0, which is the one that xterm uses by default.
>
> Whenever Vim is about to become unavailable (either via exiting or becoming
> suspended), and thus unable to respond to another application's selection
> request, it writes the contents of any owned selection to CUT_BUFFER0.  If the
> "+ CLIPBOARD selection is owned by Vim, then this is written in preference,
> otherwise if the "* PRIMARY selection is owned by Vim, then that is written.


Best regards,
Tony.
--
If you want to know what god thinks of money, just look at the people
he gave it to.
                -- Dorthy Parker

--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|

Re: Clipboard integration with X: data loss on quit

Sarah Strong
Thanks for the information! The whole section on x11 clipboard
integration can be found for quick reference at
http://vim.dindinx.net/vim7/html/gui_x11.txt.php#x11-selection

Since this is behaviour declared in the help but not working, it's a
bona fide bug then. I found one confirmation with workaround in the
wild:
http://stackoverflow.com/questions/2831024/vim-terminal-copy-to-x-clipboard-and-paste-while-suspeneded

Would anyone running a Gnome-based system like to confirm the bug? The
bug doesn't have anything to do with Gnome, it's an X issue. I'm
trying to fix the problem, however, by using gtk functions and
specifically targeting Gnome settings daemon's clipboard manager for
testing because it fully supports the freedesktop.org ClipboardManager
specification.

-Sarah Strong
Tony: sorry for the repost, I replied to you privately by mistake.
Thanks so much for your help!

--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|

Re: Clipboard integration with X: data loss on quit

James Vega-3
In reply to this post by Tony Mechelynck
On Fri, Jun 18, 2010 at 11:16 AM, Tony Mechelynck
<[hidden email]> wrote:

> According to the help, Vim does save register + when quitting, as follows:
>
>>                                                        *x11-cut-buffer*
>> There are, by default, 8 cut-buffers: CUT_BUFFER0 to CUT_BUFFER7.  Vim
>> only
>> uses CUT_BUFFER0, which is the one that xterm uses by default.
>>
>> Whenever Vim is about to become unavailable (either via exiting or
>> becoming
>> suspended), and thus unable to respond to another application's selection
>> request, it writes the contents of any owned selection to CUT_BUFFER0.  If
>> the
>> "+ CLIPBOARD selection is owned by Vim, then this is written in
>> preference,
>> otherwise if the "* PRIMARY selection is owned by Vim, then that is
>> written.

That is different than what Sarah is talking about.  The above quoted
behavior is useful for applications that still pay attention to
CUT_BUFFERs, but X's CUT_BUFFERs are deprecated for various reasons
(such as only handling latin-1 encoded data).  Because of that, many
applications/libraries do not even provide a means for interacting with
CUT_BUFFERs (Gtk included).

The proposal Sarah is referencing checks for the existence of a
clipboard manager and, if it exists, transfers the clipboard's contents
to that clipboard manager.

--
James
GPG Key: 1024D/61326D40 2003-09-02 James Vega <[hidden email]>

--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php