astrand / xclip

Command line interface to the X11 clipboard
GNU General Public License v2.0
1.04k stars 75 forks source link

Loops feature doesn't work like it should #73

Open kennbr34 opened 4 years ago

kennbr34 commented 4 years ago

The '-loops' feature suggests that you can control how many times the selection can be pasted, but depending on what window you're pasting into, it needs multiple iterations of the loop. In other words, some windows need '-loops 2' or even '-loops 3' to paste the selection one time.

I submitted pull https://github.com/astrand/xclip/pull/72 that 'dloop' should be incremented only on the non-target version of XChangeProperty() (the one using 8-bits) thinking that the whole selection was fully pasted into the window on that call. However I found on some OS and window configurations that didn't hold true. Using Debian 9 and FireFox for example, trying to paste a selection into the address bar requires several calls to the XChangeProperty via targets, and two calls to XChangeProperty with non-target 8-bit version of the call. Therefore if '-loops' was set to '1' it would not get pasted into the address bar.

I'm not sure if I'm just misunderstanding the purpose of the '-loops' feature or if it's just not working correctly, but if it is supposed to limit the amount of times the selection can be pasted, it needs to be able to more accurately count when a selection has actually been pasted despite the discrepancies in how many times xcin() and its associated XChangeProperty() calls are entered.

I'm wondering if there is a way to examine the window property and compare it with what is in the selection buffer in xclip, and only increment 'dloop' once they're both equal?

hackerb9 commented 3 years ago

Certain programs send many more paste requests than they should. For example, middle-click pasting into this very message using Mozilla Firefox triggered 21 paste requests, the first sixteen of which are simply duplicate requests for TARGETS (the list of available targets). Since requests for special targets like TARGETS, TIMESTAMP, and MULTIPLE aren't genuine pastes, they should not increment dloops. This should be fairly easy for us to fix.

However, that still leaves five paste requests for that single middle click. The browser asks for five different targets: text/plain;charset=utf-8, UTF8_STRING, COMPOUND_TEXT, STRING, and text/x-moz-text-internal. Since xclip only holds one format, xclip should decline the other four of those requests and not increment dloops. (This is bug #94).

Once those two problems are solved, we should reevaluate whether the loops feature is still broken.