I use i3wm with Qubes. I use the copy/paste sequence across appvms so frequently that it can become painful on my left hand. i3 is great because it lets me automate and reconfigure so much. However, is there a way to do this with copy/pasting text across VMs?
I’ve tried using xdotool, but it does not seem to work:
I quickly made this script that you can call from i3:
#!/bin/bash
get_id() {
local id=$(xprop -root _NET_ACTIVE_WINDOW)
echo ${id##* } # extract id
}
get_vm() {
local id=$(get_id)
local vm=$(xprop -id $id | grep '_QUBES_VMNAME(STRING)')
local vm=${vm#*\"} # extract vmname
echo ${vm%\"*} # extract vmname
}
main() {
local vm=$(get_vm)
local action=$1
if [[ -n "$vm" ]]; then
if [[ "$action" == "copy" ]]; then
qvm-run --pass-io "$vm" "xsel -b" > /var/run/qubes/qubes-clipboard.bin
notify-send "Clipboard copied!"
elif [[ "$action" == "paste" ]]; then
qvm-run --pass-io "$vm" "xsel -ib" < /var/run/qubes/qubes-clipboard.bin
notify-send "Clipboard pasted!"
fi
fi
}
main $1
It’s not perfect (it’s looking for the clipboard only) but it’s a good base if you want to edit it for your needs. It depends on xsel so you need that in your qubes to work.
It works based on an argument “copy” or “paste” like this: ./script.sh copy ./script.sh paste
This is not quite working. The script runs, I can see the notifications.
However, I think it’s not copying as expected. After copy, I should expect qubes-clipboard.bin to have some contents? Because cat shows it’s empty still.
I do have xsel installed on target qubes, and it works when used from terminal there.
You need to copy what you want to be copied to the clipboard explicitly. There’re different way to copy on Linux, this will only take what’s in the clipboard (not in the primary or secondary selection).
When I run this from dom0 (sleep 4 && ./script copy) and when I put my cursor on the target qube, it does copy what’s in my clipboard (ctrl+c / context menu → copy). Maybe try to play with the -p and -s options of xsel instead of -b.
I’ve tried it, but xsel does not seem to be working the same for me (maybe because of i3?)
I’m having much better luck with xdotool actually. For example, qvm-run -p "$vm" "xdotool key ctrl+c" && xdotool key ctrl+shift+c works great for copy, and I just use Qubes’ native notification system
What I was missing from my original attempts using xdotool, is that I need install it in target qubes as well as dom0, and then I need use xdotool from both appVM and dom0 to achieve my desired effect.
Thanks for the help! I’m still using much of your script and guidance
I’m also using i3 so it’s not coming from there I guess?
I’ll try to use it with a bindsym to see if it’s related or not when I have some time.
Glad you found a way for your own use