QubesOS Screenshot Clipboard Solution

After searching for this for like ever, I wanted to ask here, if someone has a permanent, relatively simple solution to the Clipboard Problem with Screenshots.

On Qubes R4.2.4 I cannot get the Screenshot Application to work at all. Only thing that works is Saving the screenshot in dom0, which I don’t really like. There IS a option to copy it to the clipboard, but I’ve never seen it actually work. Is there some workaround for this? It would surely be more convenient to just copy the image to the system wide clipboard and then paste it in a particular qube, then always having to move the image file from dom0 to a qube and so on.

Thanks

1 Like

AFAIK the Qubes Global Clipboard is text-only.

What I do, and consider “easy” is:

  1. take a screenshot with [Alt-] PrtSc
  2. save it in dom0 (by default in the ~/Pictures directory)
  3. in dom0, to move the file, say “test.png”, to the qube “personal”, for example, I run:
    cat Pictures/test.png | qvm-run --pass-io personal -- 'cat > Pictures/test.png'
  4. edit/process the file in the “personal” qube…

As I don’t do this very often, I did not wrap it up in a script… but it’s trivial to do so (together with some sanity checks).

4 Likes

And… welcome to this Forum!

2 Likes

There’s a contrib package - look at the README
here
: you could leverage that to ape a global clipboard, since I believe it
has the possibility to copy to clipboard in a qube.

In general I dont like copying anything from dom0 to the global
clipboard, and much prefer having to specify the target. That’s me.

I never presume to speak for the Qubes team.
When I comment in the Forum I speak for myself.

2 Likes

Thank you!

2 Likes

Just to be clear: the screenshot application in dom0 is xfce4-screenshooter, the default screenshot application of XFCE.

And if you only want to take and use a screenshot in the same qube, you can use xfce4-screenshooter inside this specific qube.

2 Likes

I often take screenshots and need to place them in various AppVMs. I automated this with a simple script. How it works:

  1. I press PrintScreen
  2. I select the area for which I want to take a screenshot
  3. A menu of currently running VMs appears (excluding e.g. templates or vaults)
  4. I select the target AppVM and click OK

The screenshot file is copied to the selected AppVM, and I can find the file itself in /home/user/QubesIncoming/name.png

How to do it?

  1. Check or install missing software: zenity and xfce4-screenshooter
sudo qubes-dom0-update xfce4-screenshooter
sudo qubes-dom0-update zenity
  1. Execute the commands to create the directory structure and place the previously mentioned script in $HOME/.local/bin/custom-screenshooter
# Run on dom0 as USER
mkdir -p $HOME/.local/bin
cat <<EOF > $HOME/.local/bin/custom-screenshooter
#!/bin/bash

screenshot_file="$HOME/Pictures/Screenshot_$(date +%F_%H-%M-%S).png"
xfce4-screenshooter -r -s "$screenshot_file"
if [[ -f "$screenshot_file" ]]
then
  vms=$(qvm-ls --running --raw-list --fields NAME |grep -vE '^(dom0$)|(debian|default|fedora|sys)-|vault$')
  target_vm=$( echo "$vms" | zenity --list --title="Copy to vm" --column="VM" --height=400 --width=300)
  if [[ -z "$target_vm" ]]
  then
    exit 1
  fi
  qvm-copy-to-vm "$target_vm" "$screenshot_file"
fi

EOF
chmod 700 $HOME/.local/bin/custom-screenshooter

As we know, you can’t copy to dom0 from the clipboard.So how do you copy this script? Copy it to a file in any AppVM and on dom0 copy the contents of the file to dom0:

qvm-run --pass-io YOUR_APPVM "cat /home/user/path/to/this/file.txt" > file.txt
  1. Set the keyboard shortcut. Qubes Application Menu → Settings Icon → Keyboard → Application Shortcuts → Add. In the ‘command’ field type /home/youruser/.local/bin/custom-screenshooter and select the key (e.g. PrintScreen).

Notes:

  • I use xfce4-screenshooter, although another one (e.g. built into kde Spectacle) is better. By better I mean that it allows more functionality, e.g. the ability to edit the screen, such as selecting something on it, simple cropping, etc. The tool is cool, but when I saw how many dependencies it requires - I gave up.
  • I think that such a solution (of course in a more advanced form) could be a nice feature for default qubes OS installations as, for example, a screenshooter configuration option, although it would probably be necessary to carefully consider how to implement it in a safe way.
4 Likes

This is a very convenient and good solution. Thanks a lot! I’ll look into this asap.

#!/bin/bash

id=$(xprop -notype -root _NET_ACTIVE_WINDOW | awk '{print $5}' | tr -d ',')
target_vm=$(xprop -id $id -notype _QUBES_VMNAME | awk '{print $3}' | tr -d '"')
if [[ -z "$target_vm" ]]; then exit 1; fi

screenshot_file="$HOME/Pictures/Screenshot_$(date +%F_%H-%M-%S).png"
xfce4-screenshooter -r -s "$screenshot_file"

if [[ -f "$screenshot_file" ]]
then
  cat "$screenshot_file" | qvm-run --no-autostart -pq "$target_vm" "xclip -selection clipboard -target image/png -i"
  qvm-move-to-vm "$target_vm" "$screenshot_file"
fi

I run this using a Keyboard shortcut Shift+Super+S

No need for zenity to be installed, as this just uses your currently active window vm. And saves on extra clicking.

Moves out of dom0 instead of copies, to avoid cluttering dom0.

Also, if your app-vm has xclip (small pkg), it can copy the image to its clipboard.

So it is just 1 keyboard shortcut, drag mouse, then Ctrl+V to paste.

2 Likes

Just saw this thread and had a better idea, bcs I also always found this annoying (having to copy the screenshot from dom0) - if you install xfce4-screenshotter in every VM you use (in their templates), then you can use this inside the VM you want to screenshot. You could have a i3wm keybind for this that runs a script in dom0 which in turn runs this command inside the currently focused VM.

Not sure how to do this in xfce4, but I assume its possible.

This avoids having to copy the file at all.

1 Like

Will never work. The screen is rendered in dom0 only. Each VM cannot even see it’s own windows. Prevents any screensharing for video chat apps, and also screenshots from within the VM. Which is why only dom0 has the ability to screenshot anything.

This script method automates the moving of the image file, so it won’t leave clutter and no need to manually copy files. Using qubes built in tools to move the file and the raw image to the app-vm filesystem and clipboard respectively.

I just tried it, this works:

user@app-browse:~$ xfce4-screenshooter --fullscreen --save screenshot.jpg
user@app-browse:~$ feh screenshot.jpg 

This is the debian-13-minimal template + the qubes apt packages that are required for networking + chromium browser via apt, nothing else. Oh and xfce4-screenshotter and feh via apt ofc.

PS: Even with your method, if you run i3wm you could detect which window your screenshotting and automatically move it to the respective VM - I didnt read the script, but I assume you have to enter that somehow (no idea if xfce4 can do that too somehow).

Here is the result (from another VM though, but I tried this with a few VMs and it works reliably)

PS: Ah yes, via xprop, ok, that works on xfce4 too, cool approach :slight_smile:

2 Likes

Oh, that indeed works. Maybe I got it wrong or it used to be that way.

One drawback to your method seems to be that when trying to mouse drag a region (rather than active window or entire screen), it does not preview the outline of the box. Not that big of a deal.

One benefit of my method is the ability to capture screenshots across VMs, which is a feature somewhat like the global clipboard.

2 Likes

Correct, yes. I was thinking the same before, as in is that a bug or a feature, as in it can communicate to hacked VM a whats going on in not-hacked VM b.

But for sharing screenshots, that might be desired (provided one assumes that a and b are not hacked xD which one may assume at most times I assume lol).

That xprop and auto-copy solution is nifty though, I will put this into my system I think.. maybe via i3wm sth like windows + s == screenshot inside vm, windows + shift + s == windows via dom0 + copy via xprop window detection.

1 Like

I had missed the previous mention last year by parulin that xfce4-screenshooter works in each VM. Thanks for reminding this thread that it does work.

Yeah, that’s a valid concern for Qubes users.

I think that since these scripted implementations are specific enough and only ever use “region” and never “entire screen”… there is no risk of accidentally sending anything that the user doesn’t explicitly select. And since this is only triggerable from dom0, then the whole system (dom0) would have to be compromised to automatically run and select a region of the screen.
So it’s very similar to global clipboard, which requires user action to copy and paste.

2 Likes

Although.. looking again at xfce4-screenshooter being in the app-vm…

It’s easy to set up a Custom Action `qvm-copy %f` that will bring up the standard dialog to copy it. Of course after that, it’ll be manual steps to copy that image into the clipboard of the target vm.

So xfce4-screenshooter being in each app-vm, is very simple, and no scripts. But for a keyboard shortcut to run it with the -r and -c arguments, there might a need have a script in dom0. In that case, it’ll need to get the active window to know which VMNAME to run it in.

So my method only has the benefit of being global to take screenshots across any VM, and being able to see the preview of the region you are selecting.

1 Like