Counting paste events with xclip

0

xclip is a command line interface to the X clipboard. When I was trying to set up a security function with this tool, I observed some effects I don't understand.

What I did is I piping strings into xclip with the loops option set to 1 (xclip exits after a single paste event with loops set to 1), like this:

echo test | xclip -loops 1 -display :0 -selection c -verbose

Then, when I tried to paste on my Linux Mate desktop, I observed the following: Pasting into a web form or the Firefox search bar worked like a charm with loops set to 1, but pasting into the address bar of Firefox was not possible like this.

In order to paste to the Firefox address bar, it was necessary to increase loops to 2, i.e. two paste events were "consumed". Pasting into the address bar of Google Chrome consumed 4 paste events. Even pasting into a simple text editor like Pluma required 2 paste events.

But why is this? Why is it sometimes necessary to provide the clipboard content several times in order to successfully paste into an application, and why do applications behave so different?

SYN-cook

Posted 2016-12-29T02:42:37.200

Reputation: 1

IIRC there's some scheme to cater for different buffer sizes, so applications may as well try to read the selection multiple times until they reach the right buffer size. Also, sometimes software is written inefficiently, and can call the same subroutine multiple times by accident. – dirkt – 2016-12-29T10:21:06.353

@dirkt Thanks for your hint with the buffer sizes. I'm not sure if this is significant, but I have just tried to paste texts of different size (up to 7.5MB) - it's all the same effect. – SYN-cook – 2016-12-29T17:52:20.577

If you want details (which I don't remember, it's too long), the protocol is here, and I guess it should be possible to trace the events somehow.

– dirkt – 2016-12-29T21:31:15.243

Answers

0

I'm guessing that the answer is similar to this: https://stackoverflow.com/a/24332080/266747 -- essentially, firefox may be reading from the PRIMARY clipboard multiple times to gather all of the available TARGETS (although that doesn't necessarily make sense in the context of the address bar).

This is what @dirkt said in the comments, but I ran across the stackoverflow link while trying to answer the same question myself, so I thought I'd share.

Barton Chittenden

Posted 2016-12-29T02:42:37.200

Reputation: 1 698