问题陈述
我使用 scrot
截取屏幕截图,除非我有多个监视器或显示器,否则效果很好。在那种情况下 scrot
将不同显示器的屏幕截图合并为一个输出。
来自联机帮助页,scrot
支持选项 -m
:
-m, --multidisp
For multiple heads, grab shot from each and join them together.
所以我想象默认行为是NOT将它们连接在一起。然而,这种情况并非如此。即使没有 -m
选项我得到加入的屏幕截图。
我看好scrot
应该能够做到这一点,因为它支持 -u
选项:
-u, --focused
Use the currently focused window.
效果很好。
我还查看了另一个名为 maim
的 CLI 工具- 但我还是不知道如何分别截取不同显示器的屏幕截图。
所以我排除的解决方案应该像这样工作:
screenshot_command <display_name> # and other options
只截屏显示<display_name>
.
到目前为止我尝试的解决方案
maim
支持 curios looking 选项 -x
:
-x, --xdisplay=hostname:number.screen_number
Sets the xdisplay to use.
所以我尝试了maim -x 0.0 | xclip -selection clipboard -t image/png
,但这不起作用。我不知道这个选项是如何使用的,因为没有足够的文档。
两者都是 scrot
和 maim
还支持选项 -s
:
-s, --select
Interactively select a window or rectangle with the mouse.
所以我在想一个非常丑陋/hacky的解决方案,使用xdotool
(或类似)选择所需的显示并与选项 -s
一起使用至 maim
或 scrot
可以完成这项工作。但我宁愿不走这条路,除非没有其他直接的解决方案。
疯狂的猜测
我想知道这个问题是否可能是因为我添加新监视器的方式?我通常使用如下命令添加我的第二个显示器:
xrandr --output eDP-1 --auto --output HDMI-1-4 --auto --right-of eDP-1
所以我想知道,可能是scrot
或 maim
只有一个显示器。我想是因为 xdpyinfo | grep -A4 '^screen'
的输出ONE 显示器看起来像:
$ xdpyinfo | grep -A4 '^screen'
screen #0:
dimensions: 1920x1080 pixels (506x285 millimeters)
resolution: 96x96 dots per inch
depths (7): 24, 1, 4, 8, 15, 16, 32
root window id: 0x1ba
用两个显示器看起来是这样的:
$ xdpyinfo | grep -A4 '^screen'
screen #0:
dimensions: 3280x1080 pixels (865x285 millimeters)
resolution: 96x96 dots per inch
depths (7): 24, 1, 4, 8, 15, 16, 32
root window id: 0x1ba
如果这确实是我出现问题的原因,那么我应该如何添加我的第二台显示器?
最佳答案
另一种解决方案是 MSS .
安装非常简单(不需要昂贵的 Python 模块):
$ python3 -m pip install --user -U mss
它将添加一个新的 mss
可执行文件,您可以随时调用。
例如,要获取每个监视器的屏幕截图,只需键入:
$ mss
/home/USER/monitor-1.png
/home/USER/monitor-2.png
/home/USER/monitor-3.png
如果只想捕获第一个监视器:
$ mss --monitor 1
/home/USER/monitor-1.png
要在一张图片中捕获所有监视器的屏幕截图(如 scrot 所做的那样):
$ mss --monitor -1
/home/USER/monitor-0.png
截至目前,帮助人员显示:
$ mss --help
usage: mss [-h] [-c COORDINATES] [-l {0,1,2,3,4,5,6,7,8,9}] [-m MONITOR]
[-o OUTPUT] [-q] [-v]
optional arguments:
-h, --help show this help message and exit
-c COORDINATES, --coordinates COORDINATES
the part of the screen to capture: top, left, width,
height
-l {0,1,2,3,4,5,6,7,8,9}, --level {0,1,2,3,4,5,6,7,8,9}
the PNG compression level
-m MONITOR, --monitor MONITOR
the monitor to screen shot
-o OUTPUT, --output OUTPUT
the output file name
-q, --quiet do not print created files
-v, --version show program's version number and exit
关于command-line-interface - 分别截取多个显示器的命令行工具,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58123181/