Search code examples
screendesktopcluttergnome-shellgnome-shell-extensions

fetch the whole desktop/screen using gnome-extension?


I'm working on gnome-extensions (javascript) and i would like to know if it's possible to fetch/capture a desktop/screen object to apply modifications on it.

For example getting a window i use this code:

let app= app_system.get_running();
for(i = 0; i < app.length; i++) {
    let window = app[i].get_windows();

There is something similar to grab the desktop ?

Such as system.get_desktop().


Solution

  • You cannot really use the Clutter API for this; the screenshot needs to be taken with the help of the compositor at the right time, and saving the data to a file has to be done complete asynchronously, to avoid blocking the compositor loop.

    GNOME Shell exposes a DBus API for taking screenshot and screencasts, which is useful for external services (for instance, gnome-screenshot uses that API, if present, instead of using X11 API). Since you're writing an extension, you can use the same internal API to take a screenshot by importing the Shell module and using its Shell.Screenshot class:

    const Shell = imports.gi.Shell;
    const Lang = imports.lang;
    
    let shooter = new Shell.Screenshot();
    shooter.screenshot (filename, includePointer, onScreenshotComplete);
    

    Where filename is the path to the file you wish to save; includePointer is a boolean that controls whether the pointer should be taken into the screenshot; and onScreenshotComplete is a function called when the screenshot has been saved.