Ubuntu: Taking screenshots of all (or specific) virtual desktops/workspaces (or: windows beyond/larger than current desktop)?



Question:

I often need to take screenshots of windows that are larger than the currently shown desktop. I'm on Ubuntu 11.04, gnome-about says Version: 2.32.1; compiz --version says Compiz 0.9.4.0 -- and I have four virtual desktops/workspaces, which are arranged as such:


The above images were obtained by moving into each separate workspace, and taking a screenshot via PrintScreen key - that is to say, gnome-screenshot. (I am aware that there are better ways of obtaining firefox shots, like the "Page Saver" addon - the above is taken simply as an example of a generic oversized window).

EDIT: I'm apparently using the wrong nomenclature here (found via xorg - Get current Virtual Desktop - number/name/tag/id? - Unix and Linux) - it turns out, in the above example, I still have only one workspace; what is changed, instead, is the viewport - this is what wmctrl -d shows on each of the "virtual desktops":

$ wmctrl -d  0  * DG: 2048x1200  VP: 0,0  WA: 0,1 1024x598  Workspace 1  $ wmctrl -d  0  * DG: 2048x1200  VP: 0,600  WA: 0,1 1024x598  Workspace 1  $ wmctrl -d  0  * DG: 2048x1200  VP: 1024,0  WA: 0,1 1024x598  Workspace 1  $ wmctrl -d  0  * DG: 2048x1200  VP: 1024,600  WA: 0,1 1024x598  Workspace 1

so to switch between "virtual desktops" from the command line, I should in fact change the "viewport", as in: wmctrl -o 1024,0

Obviously, moving to each virtual desktop, taking a screenshot and stitching them together - and finally cutting the application window - is a bit tedious, so I was wandering if there was a tool (preferably command line) that would allow me to pick a window that is larger than the current desktop, and takes a screenshot of its entire contents, in one go. There could be two scenarios here as well:

  • A larger-than-desktop window is moved so it takes up space on several virtual desktops (like the images above show)
  • A larger-than-desktop window is moved outside of the total size of all virtual desktops (from the perspective of top-left desktop in composition above, imagine moving the application window towards the top-left, and outside of desktop area - as opposed to it being moved bottom right as shown above)

The first case is possible, if not in any other way, then manually (as I did it above) -- and for the second case, I guess it should be possible for an application to either "move" the window briefly to the total all-desktops area - or create a "virtual" graphics context not shown on screen, and render the window there (although, I don't know enough details to know for sure).

I have tried the following tools so far:

  • gnome-screenshot
  • xwd
  • scrot
  • import (ImageMagick)

and they will all capture just a "corner" of the entire application window, which is shown on the current desktop (in a situation as shown above). When trying to capture "root" or "full-screen", all of these capture just the currently rendered desktop (not the total area of all virtual desktops).

I also tried shutter (0.87.2 Rev.1071), and while I've found information that from version 0.86.4 onwards, "you can capture all virtual desktops now. Shutter will go through all of them, take a picture of every one and compose them into a one large screenshot" - I did give a try clicking on "Capture all Workspaces" - but it only takes a shot of the current workspace/desktop; window captures are likewise cut at the limits of current desktop (or fail with "Error while taking the screenshot: Maybe mouse pointer could not be grabbed or the selected area is invalid." if the window fully sits in a virtual desktop other than the current one).

Then I read that there is a screenshot plugin for compiz - and since here compiz manages the virtual desktops, I thought it could handle the total area - but there are no settings there (in CompizConfig settings manager), but: "Enable plugin", an output directory, and a button to enable and set hotkeys for "Initiate rectangle screenshot" -- and since apparently only thing you can do is drag with the mouse to specify a rectangular area, I doubt that plugin would help capturing the total area in one go.

Thus, I'd like to ask for some suggestions about tools, that can:

  • Capture the total area (all workspaces/virtual desktops) in one go; or
  • Capture the total area of the selected window, even if it is pushed outside of the currently rendered desktop (also in one go)

I would prefer something that deals with this stuff in memory - I myself could come up with something worse: such as a bash script that sends keystrokes to change desktops (or just via wmctrl), and takes individual screenshots there -- but that would be a pain to use, especially since I'd be visually exposed to the "desktop switching" while the screenshot is being captures... If not any complete programs, suggestions for C/Perl/Python APIs that can access bitmap data on all/any virtual desktops would be great too.


Solution:1

Ok, found this for X windows:

FVWM Forums • View topic - Thumbnailing a Window on another Viewport

As to why you can't access a window (that is, take a picture of it when it is not on the same desk/page as the current viewport) is because windows that are not on the current page are unmapped. This is true when one changes pages/desks -- the windows are unmapped, and the windows on the current viewport are remapped.

So, I guess that means what I want is impossible? Although there are two workarounds:

  • use xrandr to increase the virtual size of (each of the four) viewports

This is what works for me - first query to see which output you want, then execute:

$ xrandr -q  Screen 0: minimum 320 x 200, current 1024 x 600, maximum 4096 x 4096  LVDS1 connected 1024x600+0+0 (normal left inverted right x axis y axis) 0mm x 0mm     1024x600       60.0*+     800x600        60.3     56.2       640x480        59.9    VGA1 disconnected (normal left inverted right x axis y axis)    $ xrandr --output LVDS1 --panning 1600x768  

... see also X/Config/Resolution - Ubuntu Wiki

  • Use xvfb for virtual render

Got this via x11 - Remote offscreen rendering - Server Fault, also see Xvfb - Wikipedia, the free encyclopedia for examples. This is what worked for me - each command goes in own terminal (as some of them are meant to be services)

# start xvfb as display 1 - note the "screen 0" there refers to "its own" screen 0; should set it to 24-bit color    Xvfb :1 -screen 0 1600x1200x24 -pixdepths 3 -fp /usr/share/fonts/X11/Type1    # start metacity on display 1 (would start gdm, but [Bug #598848: gdm no longer works with xvfb](https://bugs.launchpad.net/bugs/598848)  # needed to we have title bars, and possibility to move windows around     DISPLAY=:1 metacity    # start application (here web-browser arora) again on display 1    DISPLAY=:1 arora    # start vnc server, which will bridge display 1 to port 5900  # note - this command exists, however starts a server in background     x11vnc -display :1 -bg -nopw -listen localhost -xkb    # start vnc viewer on port 5900 - so we can see display 1:  # note also - when vncviewer exits, it also will kill the x11vnc server    vncviewer -FullColor=1 localhost:5900  

The problem here is that not all parts of the OS are initialized - so there are no window decoration, and only basic X fonts; although, apps may find their own fonts, as seen below:

vnc-xvfb.png

xvfb looks almost ideal to me - since I could basically set up an "invisible" environment, as big as I want, and take screenshots directly from it (using xwd). The problem is that I cannot have a window on "my" DISPLAY=:0, then switch it to the 'virtual' DISPLAY=:1 for screenshotting, then bring it back to DISPLAY=:0. Then one must set up an application specifically for xvfb; and if so happens you need more size - then the whole chain above needs to be restarted.

On the other hand, I find working with 4 workspaces and large viewports (shwere the mouse moves you around within a viewport) a bit confusing - then again, can change the size there on the fly and nothing needs to be restarted; and plus I can use any of the usual screenshot tools (but I'd still have to switch viewports).

Needless to say, I'd still love to hear about a possible command line solution that could do this kind of screenshotting in one go :)


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »