简体   繁体   中英

Programmatically make a screenshot of a terminal window in Gnome/Wayland

I work on a terminal font and I'd like to take screenshots of various terminals (at least xterm, gnome-terminal and konsole) running a rendering test application. Executing the command is not a problem , but the usual, portable X way of doing it, the xwd command, doesn't seem to be very script-friendly and only works on X apps (xterm, in this case) and (unsurprisingly) ignores events from Wayland windows.

Figured it out (ish). All that's needed is to add a gnome-screenshot -w to the program I want to run. In my specific case, I added a script that ran the rendering test, then slept for two seconds (so that Konsole drops the window size widget) and then ran the screenshot command:

#!/bin/sh

./test_font_rendering.py
sleep 2 # Needed for Konsole to clear the window size

# Capture the active window to a file given as a parameter
gnome-screenshot -w -f $1.png

So, in order to generate the samples, you'd need something like:

gnome-terminal -- bash -c './test_font_rendering.sh gnome-terminal'
xterm -e './test_font_rendering.sh xterm'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM