Kon*_*nos 6 xorg screenshot x-server xephyr
我想在一台台式 PC 上同时从多个 X 服务器截取屏幕截图。
我有多个用户登录不同的终端(tty1,tty2,tty3,tty4)谁开始与多个Xservers文件startx /usr/bin/openbox-session -- :1(和:2,:3,:4分别)。所以我可以用Ctrl+Alt+F8, +F9, +F10,访问它们中的每一个+F11。
该桌面上只有一台显示器。
我想为这些 X 服务器中的每一个截取屏幕截图,最好使用scrot,但目前我每次尝试时都会得到一个黑色/空白图像。只有当我在那个 X 服务器上处于活动状态时,我才能得到正确的屏幕截图。
例如,如果我打开Ctrl+Alt+F8并运行,scrot test.png我会得到一个正确的屏幕截图;如果我理解正确,我不必设置$DISPLAY,因为在Ctrl+Alt+F8我得到echo $DISPLAY> :1。但是,如果我跑sleep 10; scrot test.png,去Ctrl+Alt+F7,然后我得到一个黑色的图像。
如何同时从这些终端中的每一个获取多个屏幕截图?
对我有用的是Xephyr. 此解决方案的唯一问题似乎是当我运行极快的xdotool命令时,它的响应速度不如 X。
为了将来参考,我对四个用户和终端中的每一个都做了:
在 中~/.profile,我将每个用户设置为在系统启动后自动登录,例如:
if [[ -z $DISPLAY ]] && [[ $(tty) = /dev/tty1 ]]; then
sleep 30 # for some reason it crashes if I do not let
# it sleep for a while, not necessarily so long.
# I guess it has to do with my "normal" X at DISPLAY=:0 .
# Thus for tty2 I let it sleep 40 seconds,
# for tty3 50 seconds and so on.
startx
fi
Run Code Online (Sandbox Code Playgroud)
在 中~/.Xsession,我在其中启动了一个 Xserver/客户端(带有 blackbox)和 Xephyr(带有 openbox),例如:
Xephyr -fullscreen -screen 1920x1200 :11 &
exec blackbox &
sleep 3 # Perhaps sleeping is redundant.
DISPLAY=:11 /usr/bin/openbox-session
Run Code Online (Sandbox Code Playgroud)
我希望“最终”窗口管理器是openbox-session. 我想openbox同时用于 Xserver 和Xephyr,但会 exec openbox & DISPLAY=:11 /usr/bin/openbox-session崩溃,而exec openbox & DISPLAY=:11 /usr/bin/openbox 不会。
这样,用户:11可以截图,而监视器显示:0。(或者:13,:14等)。
我没有尝试XVnc,但我感觉它可能比Xephyr; 如果我错了,请纠正我。
您可以使用命令行工具xwd来抓取 X 显示,如下所示:
$ xwd -display :1 -root -out 1.xwd
Run Code Online (Sandbox Code Playgroud)
你可以像这样循环 1 到 4:
$ for i in {1..4};do xwd -display :$i -root $i.xwd; done
Run Code Online (Sandbox Code Playgroud)
注意:生成的.xwd文件是一种特殊类型的 X Windows 转储文件。
$ file 1.xwd
1.xwd: XWD X Window Dump image data, "xwdump", 4160x1440x24
Run Code Online (Sandbox Code Playgroud)
您可以xwud像这样显示它们:
$ xwud -in 1.xwd
Run Code Online (Sandbox Code Playgroud)
或者你可以使用 ImageMagick 的display命令来查看它们:
$ display 1.xwd
Run Code Online (Sandbox Code Playgroud)
你也可以使用 ImagMagick 的import命令来做类似的事情:
$ import -window root -display :0.0 -screen /tmp/0.png
Run Code Online (Sandbox Code Playgroud)
或者按照@mikeserv 在评论中的建议,尝试设置$DISPLAY以便scrot可以正确找到活动的 X 显示:
$ DISPLAY=:1 scrot 1.png
Run Code Online (Sandbox Code Playgroud)
这可以像这样循环:
$ for i in {1..4};do DISPLAY=:$i scrot $i.png; done
Run Code Online (Sandbox Code Playgroud)
我对问题中的问题的理解如下:
\n\n您正在使用文本控制台 tty,
\n因此您运行屏幕截图命令的 tty 上没有运行 X。
您可以为 X 显示运行命令行屏幕截图命令。
您已为屏幕截图命令指定了 X 显示,例如
\n DISPLAY=:2 scrot out.png。
屏幕截图命令不会给您错误
\n 但你会得到一个黑色图像作为输出。
问题可能是 X 服务器没有将图像绘制到某个图像缓冲区中,并且屏幕截图是从该空缓冲区中获取的。但它也可能是一个合成窗口管理器,例如compiz,它不是绘画。至少如果您捕获单个窗口,这可能是问题所在。我认为值得尝试使用非合成窗口管理器,例如metacity.
如果这不能解决问题,还有一种完全不同的方法:
\n\n在一台显示器上将所有 X 服务器作为嵌套 X 服务器运行。每个嵌套的 X 服务器都在窗口中显示其屏幕输出。然后,您可以制作嵌套显示的全屏屏幕截图,或主显示上的窗口屏幕截图。
\n\n作为嵌套 X 服务器的实现,Xephyr似乎是最新的。还有较旧的Xnest和Xvfb:
NAME\n Xephyr - X server outputting to a window on a pre-existing X display\n\n DESCRIPTION\n Xephyr is a kdrive server that outputs to a window on a pre-existing "host" X dis\xe2\x80\x90\n play. Think Xnest but with support for modern extensions like composite, damage\n and randr.\n\n Unlike Xnest which is an X proxy, i.e. limited to the capabilities of the host X\n server, Xephyr is a real X server which uses the host X server window as "frame\xe2\x80\x90\n buffer" via fast SHM XImages.\nRun Code Online (Sandbox Code Playgroud)\n\n以类似的方式,可以使用 Xvnc(来自 vnc4server 包),另外提供通过 VNC 协议的访问:
\n\n从Xvnc4:
NAME\n Xvnc - the X VNC server\n\n DESCRIPTION\n Xvnc is the X VNC (Virtual Network Computing) server. It is based on a standard X\n server, but it has a "virtual" screen rather than a physical one. X applications\n display themselves on it as if it were a normal X display, but they can only be\n accessed via a VNC viewer - see vncviewer(1).\n\n So Xvnc is really two servers in one. To the applications it is an X server, and to\n the remote VNC users it is a VNC server. By convention we have arranged that the\n VNC server display number will be the same as the X server display number, which\n means you can use eg. snoopy:2 to refer to display 2 on machine "snoopy" in both\n the X world and the VNC world.\nRun Code Online (Sandbox Code Playgroud)\n\n(在 Ubuntu 中Xvnc作为包提供vnc4server)