We can "turn on" the X tty manually from command line, without ctrl-alt-F(x).
If X is on tty 7, and you login a text terminal
chvt 7 ; DISPLAY=0.0 xwd -root > screendump.xwd ; chvt 1
However, xhost + localhost must be issue within the xsession, else xwd cannot connect to x server.
This allow you to do it from ssh session.
PS: In theory, with MTD, it should be possible to do screen capture from video card memory. Thus without first "waking" the X session.
As far as I know (but I'm no X expert), visibility is only tracked through VisibilityNotify
events, it isn't a state that you can query like IsViewable
. You'd need to get KDE to spit it out, I don't know if it can do that.
You may be solve your problem by sending the window a VisibilityNotify(state=VisibilityUnobscured)
event. I don't know if that's enough, you may also need to send a MapNotify
event. Here's some untested Python code to send a VisibilityNotify
event.
#! /usr/bin/env python
import re, sys, time
import Xlib.X, Xlib.XK, Xlib.display, Xlib.protocol
def parse_action(string):
state = {
'0': 0,
'1': 1,
'2': 2,
'unobscured': 0,
'partiallyobscured': 1,
'fullyobscured': 2,
'visibilityunobscured': 0,
'visibilitypartiallyobscured': 1,
'visibilityfullyobscured': 2,
}[string.lower()]
return state
def parse_window(display, arg):
wid = int(arg, 0)
return display.create_resource_object('window', wid)
def send_event(display, window, state):
window.send_event(Xlib.protocol.event.VisibilityNotify(window=window,
state=state))
display.sync()
if __name__ == "__main__":
display = Xlib.display.Display()
send_event(display, parse_window(display, sys.argv[1]), parse_action(sys.argv[2]))
Best Answer
To elaborate a bit on previous answers and comments, the ability to capture a screenshot of a non active window (as in fully or partially hidden) seems to depend on the window manager.
Using the following (already given) command :
or
(the
-
ofconvert
is for using standard input from the pipe,xwd:
tells the format of the input) one seems to be able under Enlightenment (e17, tested with Fedora 19) to capture a screenshot of :I checked with Openbox (same configuration) and KDE (with an old Scientific Linux 4.8 and latest version of
ImageMagick
(yes, incredibly it compiled…)) and in both cases screenshots show only what is on top of the display layers — that is, only what is already visible on screen.The point is that the
import
command checks for themap_state
field returned byXGetWindowAttributes
to beIsViewable
, and if not it returns an error. One can checkmap_state
e.g. using :It seems to be always
IsViewable
under e17, while it'sIsUnMapped
under openbox and KDE as soon as the window is minimized or whatever.Not sure though why the screenshot is always clean with e17 while it's mixed with other windows when the window is partially recovered with other WMs, but obviously it also has to do with the way the WM handles the display.
Anyway, clearly it's a matter of WM. It would be nice to have a list of WMs able vs unable to do screenshots of hidden windows — I'm not doing it.