Caffeinated Bitstream

Bits, bytes, and words.

GNOME Terminal friendly clipboard patch

The presence of multiple "clipboard" selection buffers in the X Window System has long been a source of irritation with me, and I frequently end up pasting the wrong thing. A few years ago, I hacked the xterm terminal emulator program to always copy into both buffers, and this solved the problem for me. However, I've been playing around with GNOME Terminal lately, so I recently patched its source code to do something similar.

Background

The root of the problem is that there are two different "selection buffers" that are commonly used in the X Window System:

CLIPBOARD
The "CLIPBOARD" selection buffer is used for the cut-and-paste functions that most users are familiar with: Selecting the "cut", "copy" or "paste" menu items from the application's "Edit" menu, or using the corresponding CTRL-X, CTRL-C, or CTRL-V shortcut keys. This selection buffer is the standard means of performing cut-and-paste operations in most modern applications. However, this selection buffer is unfortunately not used when you merely highlight some text in the GNOME Terminal.
PRIMARY
The "PRIMARY" selection buffer receives data when the user highlights text with the mouse. The text in this buffer is pasted when the user presses the middle mouse button in an application's text entry field. This cut-and-paste buffer is a legacy function which new users are generally not told about, in the interests of avoiding mass confusion. Most modern applications support this buffer.

The annoyance is that text highlighted in GNOME Terminal (and thus stored in PRIMARY) can be pasted into another application by clicking the middle mouse button, but cannot be pasted with CTRL-V. Likewise, text copied from the terminal with SHIFT-CTRL-C (or Edit->Copy) might not be available for pasting with the middle mouse button. I frequently get into situations where I have one bit of text in PRIMARY, and another in CLIPBOARD, and I inevitably use the wrong paste function.

A patch for GNOME Terminal 2.22.3

The attached patch modifies the terminal source code to always copy selected text into CLIPBOARD shortly after it has been copied into PRIMARY. Thus, when you highlight a bit of text in the terminal, it can be pasted into another application with either the middle mouse button or CTRL-V.

This patch is for the GNOME Terminal 2.22.3 source code. I'm sure the patch won't work on more recent versions because they've rearranged a few things, but the basic concept should still work. The patch for xterm I wrote a few years ago is also still available.