One Klipper feature to fix many bugs: Introducing more flexibility in actions
Posted by Esben Mose Hansen
One very common request for Klipper is "do stuff with the clipboard". E.g.
- Search google for something selected.
- Count the number of words, lines whatever for the current clipboard
- Strip the clipboard of special formatting
Now, as you might know, Klipper has actions. An action is like a filter that looks for patterns in the clipboard. An example pattern could be "bug: followed by a number". If the pattern matches, the action springs into life offering to do one of several commands in a small popup. Each command offers something, like "find the KDE bug with this number" or "find Debian bug with this number" or what have you. Now, a small popup appearing whenever you copy something is annoying for many, and thus you have the option of disabling the automagic popup and instead invoking the scanning manually by pressing ctrl-alt-r (by defeault).
As the attentive reader will note, the first item on the list above is almost satisfied by actions: Simply define a pattern that matches (nearly) everything and have it invoke a command to search google. The snag appears if you like the automagic popup, as even the most avid popup lover would be somewhat frustrated to have the popup appear at every copy! So I have added an option to actions, so that they can be configured to only trigger on a manual invocation by deselecting the "Automatic" checkbox in the configuration dialog.
.
The two remaining items on the list just need one more thing: The output of a command should go back on the clipboard. For this purpose, I made it so any command's output can either be Ignored (old, default), Add'ed to the clipboard history or Replace the original. That way, the user can set up an action to run something through wc -c to get the character count right onto the clipboard. Neat!
During the course of fixing this, I also fixed an unfortunate interaction. Sometime back, the bright idea was born that clipboard snippets could be run through KDE's magic system of handling URL's. In that way, if e.g. a file on the harddisk was copied to the clipboard, Klipper could offer to open the file in an appropriate program. Neat! Unfortunately, a bug was introduced so that this only worked if at least one normal action was present. And then all the default actions were removed because they were "old and unneeded". Apparently, a lot of distributions, including the pecked-on Kubuntu, actually caught this and continues to install the old file full of actions, but a few (like SuSE I think) did not and thus revealed the bug. Much confusion ensured, until a user noticed that adding a dummy action fixed the problem. Ah well, it is fixed now. I would also like to resurrect some actions, perhaps disabled, so the user has a few examples to go by.
Next up: Making klipper work with Eclipse. Which calls for me to install that exotic IDE. Wouldn't it just be easier if everyone switched to KDevelop instead ;)? Which is by the way really awsome these days, beta or no.

If you see this, the comment system works again
Woohoo. Reposting time then. ;)
Just wanted to write that Eclipse had been a pain in the * for me due to it glitchy way with copy/paste. I love my klipper’s merged clipboard/selection, and Eclipse broke it in every way possible so to not get crazy I always had to pretend to work like under Windows or something.
Not sure however if you can fix Eclipse’s behavior in klipper though. One would think it’s an issue within Eclipse, not klipper, isn’t it?
Also GTK apps seem to like to report machine made text selection as selections while KDE sanely reports only user made selection. Like with Eclipse, is there any special casing to avoid that behavior possible at all within klipper?
Thanks alot for working on klipper!
It appears to be an error in GTK: As I recall, the
set_clipboard_with_textis broken, instead
set_clipboard_with_ownershould be used. There is a patch on Eclipse’s bugzilla to fix this, so I don’t think it is worth it to consider trying to work around it for Klipper.