GuestAdditions, Linux and X11 Clipboard

Discussions related to using VirtualBox on Linux hosts.
Post Reply
annekaelber
Posts: 2
Joined: 30. Oct 2014, 04:44

GuestAdditions, Linux and X11 Clipboard

Post by annekaelber »

I apologize in advance for not having more detailed information to show (i.e. code snippets of the GA version originally found on my guest). I hope this is helpful to someone else; it's my way of 'paying it forward', in return for all the help I've found just searching the forums until I could piece together what I needed to do.

I finally got fed up with not being able to copy/paste between my host (Windows) and guest (Linux). While searching for a solution, I kept seeing answers in the forums saying "you need to install the GuestAdditions". But I do, every time I do an update. When I looked at the GuestAdditions I had installed prior to all of this, the version came back something like 4.1.16 -- I'm running VirtualBox 4.3.30! I followed the directions in this thread to uninstall my GuestAdditions. Thankfully, this very cranky locked thread had a link which ultimately got me to the GuestAdditions for 4.3.30. Even once they were installed, I still had NO ability to copy/paste.

I kept looking and found this thread which has changed my frustrations to a thing of the past (I hope). I had xclipboard up as I worked through the link Nottabox provided at the top of the post, Investigating shared clipboard problems on X11 guests or hosts. After I had typed in the last code entry in the article, I saw the xclipboard update with the text I had copied on my host when I started down this particular rabbit hole.

It's working. I am *so* happy.

Anne.
Shamino
Posts: 3
Joined: 4. Oct 2019, 21:04

Re: GuestAdditions, Linux and X11 Clipboard

Post by Shamino »

I realize that it is more than four years later, but I found this article while searching for a solution to the same problem, so I'm replying in order to share my solution.

As you learned, X11 has three buffers for clipboard-like functionality. The primary selection, the secondary selection and the clipboard. Most of the time, when you select text, it changes the primary selection to what you selected. A middle-click on an X11 text box copies the primary selection to the location where you clipped.

VirtualBox, however, shares the clipboard not the primary selection. If you copy something to the clipboard (e.g. typing Ctrl-C in Firefox or M-w in Emacs), it will be seen by the guest additions and will be made available to the host OS's clipboard (assuming guest additions are installed and clipboard sharing is enabled). But if you just select text, this doesn't happen, because the X11 clipboard buffer has not changed.

This is a particularly annoying problem when working with xterm, because there is no "copy" function. As your article points out, you can configure xterm with "Select to Clipboard", which works. It will cause xterm to change the clipboard whenever it selects text. But I don't consider that a good solution because:
  • I don't want my Windows (host) clipboard changing every time I select text (I suspect this is why the VB guest additions don't try to sync the primary selection to the host clipboard)
  • It only affects xterm. Other apps can also change the primary selection (although most of them seem to have explicit "copy" commands these days)
I wanted something where I can leave the clipboard separate from the selection, except when I want to explicitly update it (e.g. when I want to copy something from an xterm and paste in an app running on the Windows host. After reading a blog post on the subject (sorry for not having a link, the system won't let me put one in my first post), I am doing this via the xsel command.

To do this, make sure you have xsel installed (it's in the "xsel" package on Ubuntu). Then I made a bash alias:

Code: Select all

alias 'clip=xsel | xsel -b'
Now, when I need to copy the selection up to the host, I type (usually from another xterm) "clip" and the selection is transferred.
Post Reply