7

Right click on the text field the popup mouse menu shows that the clipboard is blank, but when press the wheel in the middle of the mouse the previous selected text is pasted.

Why is this and how can I clear that text?

Gnome 3.6.2 + opensuse 12.3

1

1 Answer 1

8

It's because there are actually two clipboards: GNOME has one and X.org has one.

You can paste the text which is on GNOME's clipboard by right clicking an text area and then selecting "paste".

X's clipboard works as the following: when you select text by keeping mouse's left button klicked and move mouse, it is copied to X's clipboard. Then you can paste it by clicking mouse's middle button.

Excerpt from archlinux's wiki page clipboard:

Of the three selections, users should only be concerned with PRIMARY and CLIPBOARD. SECONDARY is only used inconsistently and was intended as an alternate to PRIMARY. Different applications may treat PRIMARY and CLIPBOARD differently; however, there is a degree of consensus that CLIPBOARD should be used for Windows-style clipboard operations, while PRIMARY should exist as a "quick" option, where text can be selected using the mouse or keyboard, then pasted using the middle mouse button (or some emulation of it).

Therefore, the clipboard of GNOME is type CLIPBOARD and the clipboard of X is type PRIMARY.

Delete the contents of X clipboard

Excerpt from xclip's man page:

-i, -in
read text into X selection from standard input or files (default)

Therefore, to clear the contents of X clipboard, use the following command:

$ xclip -i /dev/null

Delete the contents of CLIPBOARD clipboard (GNOME's clipboard)

$ touch blank
$ xclip -selection clipboard blank

References

4
  • 1
    See the links I provided on the Q, they explain the multiple clipboards very well and they're wihin the U&L site.
    – slm
    Jan 12, 2014 at 9:15
  • @slm You're right, the A's of those Q's explain clipboard better than my answer.
    – user37607
    Jan 12, 2014 at 9:19
  • Add them into your A if you like as references, I can remove them so they're more inline with your A. This Q isn't a duplicate and your A should be the correct one if you can add a method to delete the contents of the clipboard. The 2 links show how to do that so just add this bit to your A.
    – slm
    Jan 12, 2014 at 9:20
  • As the middle button is also the scrolling wheel on my mouse, scrolling makes accidental copies of X clipboard in my code. This can be avoided by clearing the X clipboard as explained so the question and the answer are very valuable to me, thank you. Jan 18, 2021 at 21:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .