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.