The only potential problem with this approach is that you can’t “cross-paste” between windows with the middle button. For example, if you highlight a bunch of text in a GTK app then try to middle-click paste it into your terminal, it won’t work because the primary clipboard will have been cleared. Granted, I can’t really be the judge of whether or not this is an issue. If this approach suits your use case, then it’s probably as a good workaround as any.
Root cause of this problem: The highlight selector of certain gtk applications is directly tied to the state of the primary clipboard. Try this. Put a terminal window and the gtk application side by side. Go the the gtk app and highlight a bunch of text. After that, go to the terminal and run
$ wl-copy -cp
You will see the highlight disappear as soon as that command is run.
Having said that, I think this behavior only affects a subset of the gtk library because not all gtk applications exhibit this behavior (e.g: firefox).
Off the top of my head, here are a few alternative workarounds that I can think of. Please bear in mind that these may or may not work because I don’t really have the time to test them out yet.
Workaround 1: Watch the normal clipboard instead of the primary clipboard. In other words, remove the -p
flag in
$ wl-paste -p --watch wl-copy -cp
This will clear the primary clipboard only after you have copied your selection into your normal clipboard. The downside of this approach is that you will still end up middle-pasting if you highlighted a bunch of text but forgot to copy them. If you only highlight text when you intend to copy them, this workaround will be the simplest and cleanest.
Workaround 2: Assign a keybinding to the middle-mouse button to run a custom command. For example, you can bind the middle-mouse button to run wl-copy -cp
. In hyprland, you can probably do something like
bind=mouse:274,exec,wl-copy -cp
That way, you can still select into the primary clipboard; it just won’t paste a bunch of text when you accidentally pressed the middle-mouse button (probably). You will have to do some testing to see if the middle button still works as intended in other contexts, of course.
Workaround 3: Instead of clearing the primary clipboard directly, you pipe the contents of an empty file (e.g /dev/null
) into the primary clipboard. For example,
$ wl-paste -p --watch wl-copy -p </dev/null
I’m not entirely sure if this will work, tbh. If the -c
flag is what’s causing the highlighted text to disappear (not 100% sure about this), then we can try to empty the primary clipboard contents without using the -c
flag.
Workaround 4: Use the sxhkd
(this works for X11 only) hotkey daemon (or maybe xbindkeys
)
Install sxhkd
and then add the config file ~/.config/.sxhkd/sxhkdrc
with the following contents:
~button2
echo -n | xsel -n -i
~control + c
echo -n | xsel -n -i
~control + x
echo -n | xsel -n -i
Configure sxhkd
daemon to autostart, and you should be able to use the middle click button normally without autopasting.