10

How to take a screen shot of non active window? If I have 2 windows, I want to capture the screenshot of the one which is running in the background.

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
spendyala
  • 169
  • 2
  • 7
  • Interesting, I'm not sure if that's possible. – phunehehe May 21 '13 at 16:20
  • 1
    I think you should improve your question by making clear what is meant by "non active". Is this window, presumably not the one in focus, totally visible or partly visible or not visible at all because the active window covers part or all of it? –  May 21 '13 at 16:54

6 Answers6

12

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 :

import -window <windowid> image.png

or

xwd -id <windowid> | convert xwd:- image.png

(the - of convert 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 :

  • fully or partially hidden windows ;
  • minimized windows ;
  • windows on other workspaces.

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 the map_state field returned by XGetWindowAttributes to be IsViewable, and if not it returns an error. One can check map_state e.g. using :

xwininfo -id <windowid> | grep 'Map State'

It seems to be always IsViewable under e17, while it's IsUnMapped 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.

aksh1618
  • 326
  • 1
  • 15
2

What do you mean by "non active"? "Not having the focus" or "hidden by some other window"? In the first case, gimp will do it without any problems (File -> Create -> Screenshot). In the second case, it's more difficult (if it's possible at all).

Uwe
  • 3,257
  • 17
  • 19
  • Yes, non active means not having the focus. We can take screenshot of focused one. Can we make the window which is not having focus to be focused using command line. If so how can be do that. – spendyala May 21 '13 at 16:21
  • I want to do in commandline, to automate the process. – spendyala May 21 '13 at 16:23
  • 3
    I just checked that `import` (from the ImageMagick suite) has a `-window id` option. If you know the window identifier that should work, even on the command line. You can get the window identifier using `xwininfo`, but for that you'll have to use the mouse at least once. – Uwe May 21 '13 at 16:24
  • Can I extract for fixed height and width using import along with window id. I am also checking that. – spendyala May 21 '13 at 17:08
0

While this answer may not be desirable for some situations, this script will raise every window on the current desktop one at a time so that they may be screenshotted with your screenshot tool du jour.

#!/bin/bash
# raiseAll - Mark Belanger - raise all windows

# get the ID of the current desktop
thisDT=`wmctrl -d |grep ' \* ' | awk '{print $1}'`

echo Raising windows for desktop $thisDT
for window in `wmctrl -l |grep " $thisDT " | awk '{print $1}'`
do
  echo Raising $window - put your screenshot command here
  wmctrl -i -a $window
  sleep 1
done
0

Solution for kde

SystemSettings->Display And Monitors->Compositor->Keep window thumbnails set Always

thess
  • 1
  • Can you explain in more detail why this is a solution? – ajgringo619 Nov 16 '20 at 04:57
  • With it kwin dont call "hideinternal" and flag map_state always IsVieable for minimized windows etc https://github.com/KDE/kwin/blob/d36e326d66d0d24c342b6f15cb5ef0a602cc2328/x11client.cpp#L1520 – thess Nov 16 '20 at 22:10
0

Try this! [ Ubuntu 20.04.4 ]

# Screenshot a specific window, in this case a Firefox window:

import -window "$(wmctrl -l | cut -d ' ' -f 5- | grep -i firefox)" ~/Pictures/result.jpg

# Explaining the "wmctrl -l | cut -d ' ' -f 5- | grep -i firefox", list open windows and cut out the window name part by filtering on a keyword. Install the packages if necessary!

Cesar Devesa
  • 251
  • 2
  • 3
0
for i in `xprop -root|grep "_NET_CLIENT_LIST_STACKING(WINDOW): window id" |tr '#' ','|tr ',' '\n'| grep 0x`;do xwininfo -id $i|grep "Window id" ;done

Using the above I was able to get the windows id. and using

xwininfo
able to find the label or name or title of the window.
Rui F Ribeiro
  • 55,929
  • 26
  • 146
  • 227
spendyala
  • 169
  • 2
  • 7