Article Title: Use clipboard in tightVNC. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Test Platform:
TightVNC 1.3.0
Ubuntu 10.04
Vncviewer on Windows
In X window system, data is transmitted between forms, using "selection", that is, the "Clipboard"
X window system supports arbitrary selection.
Among them, the most important thing is PRIMARY selection, then CLIPBOARD selection, and the obsolete CUT_BUFFER (0 ~ 7 ).
In VNC, CUT_BUFFER0 is used between the server and the client to transmit data.
In X, we often use CLIPBOARD selection to copy and paste strings. Therefore, to allow the VNC client and server to copy strings, We need to copy the "CLIPBOARD" and "CUT_BUFFER0" to each other.
Currently, I use the autocutsel tool to complete this task. It can automatically copy each other between CLIPBOARD and CUT_BUFFER0.
The command format is as follows:
$ Autocutsel-s PRIMARY/CLIPBOARD-cutbuffer 0
If the "-f" option is added, it can be run in the background. Therefore, it is recommended to load it into the X startup script.
Note:
In the X environment, run the following command to view the content in CUT_BUFFER0:
$ Xprop-root CUT_BUFFER0
Reference:
Http://supermmx.org/blog/20060908_vnc_copy_paste
The original article is as follows:
[VNC] (Virtual Network Computing) is used for development in the company. The server is Solaris or Linux, and the client is basically Windows. Copy and paste between two systems is often used. Success or failure involves several aspects, such as the server mechanism, the used terminal (application), and The VNC client. When using it, I encountered some problems more or less. When my consistent style came back, I wanted to figure out the principle and mechanism of this thing, so that I could afford my own worries.
Since there is only one method for my own applications, that is, Windows is connected to * nix, so we only consider this situation. Different situations may vary, so we will not go into it here. Windows has been used for a long time and is familiar with it. It has a global buffer zone (Clipboard, Clipboard). When a program selects a piece of data, select copy, copy the selected text to the buffer and save it. Then, select and paste it in another program to extract the corresponding data from the buffer and insert it into the body.
X Window calls this "selection", which supports two methods: Primary selection and Clipboard selection. In fact, there is another Secondary choice, but it is out of date. Unlike Windows, there is no global buffer to store the copied information. The working method is as follows: when a program selects something, it will say "I am the current selected owner". If you want to paste it in another program, send a request to the selected owner to obtain the data. Then the owner sends data to the requester. The process can be considered as inter-process communication.
The clipboard option is used to copy, paste, and cut menus. It looks the same as the copy and paste method in Windows, click Copy (or the shortcut key can also be used). At this time, the ownership should be declared, and a copy of the object to be copied should be saved internally. When other programs are pasted, the saved items are sent.
The master selection is slightly different. When you select anything (mouse or keyboard), the current program declares ownership (without explicit copying) and saves one copy. When other programs use the middle mouse button (or double-click both the left and right to simulate the paste), the data is sent.
So to sum up, the internal implementation method of X for a program:
Use the mouse or keyboard to select a piece of text: declare the master selection (Primary) Ownership (a copy may be saved internally)
Copy (menu or shortcut key): Save a copy internally and declare the ownership of the Clipboard (Clipboard ).
Paste (menu or shortcut key): Get the data in the clipboard and insert it to the appropriate position
Middle mouse button (or double bond simulation): Get the data selected by the master and insert it to the appropriate position.
Another program requests the master to select data: Send the internally saved Master Selection
Another program requests the Clipboard data: Send the saved Clipboard data
Another program declares master selection ownership: discards the stored master selection data
Another program declares the clipboard ownership: discards the saved Clipboard data.
This is just a simple description. The actual implementation is more complicated. For details, refer to the [ICCCM] documentation.
Most programs on X support the master selection. You can also think that the default is supported. Some Clipboard support is not obvious enough. If there are no menus or shortcut keys, you can only select them with the mouse, for example, most Terminal Emulator, but the shortcut keys are provided. Xterm, rxvt, urxvt, and mrxvt can be copied from the clipboard Using Shift + middle mouse buttons. Emacs uses master selection. More programs use the clipboard.
Now, let's talk about the intermediate bridge VNC. In fact, a Cut Buffer is missing in the middle. This is the earliest implementation method and is not used now. However, it is still in use, for example, a terminal simulator and Emacs such as xterm are updated to both the master selection and the buffer zone. It is generally named CUT_BUFFER0 and can have multiple. The copy and paste data exchange between the VNC Server and Windows is to synchronize the CUT_BUFFER0 and Windows Clipboard through the VNC Viewer. Of course, General VNC Viewer will have options such as whether to synchronize. I have been using rxvt, mrxvt, and Emacs, so I have never been unable to copy and paste each other, and most people do not use gnome-terminal or konsole to copy and paste them.
So how can we make programs that do not use the shear buffer copy and paste with Windows? This requires external programs to help. Xcutsel is a program that copies data between the "select" mechanism and the cut buffer. You can select Primary or Clipboard. In this way, you need to click copy 0 to PRIMARY (or CLIPBOARD) to copy from Windows. to copy from the past, you need to click copy PRIMARY (or CLIPBOARD) to 0 ". Another feature is [autocutsel], which is the same as the previous one, but is automatically executed without manual copying. I have never used it :)
In fact, the best way is to use the recommended method (main selection or clipboard) between the X Window, VNC Server and VNV Viewer to discard the cut buffer. After all, it is outdated.
Here is an additional sentence. I have not read the code above, but I am using second-hand materials. I am sure there is something wrong with it. Please advise.