1

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().

Erwan Douaille
  • 553
  • 1
  • 10
  • 31
  • Check this one: http://www.roojs.org/seed/gir-1.2-gtk-3.0/seed/Gdk.Screen.html#expand Looks hardware related !? I will have a look on it – Erwan Douaille Mar 11 '15 at 08:04
  • 1
    Don't use that website: it's completely out of date. It also refers to Seed, the JavaScriptCore-based introspection binding for JS. The GNOME Shell is written using GJS, the MozJs-based binding instead, which means that there are some differences. Plus, as I said, bot Seed and that website are not maintained any more, and woefully out of date. – ebassi Mar 12 '15 at 23:09
  • This is out of date. But some options are still usefull. Anyway, does Gdk.Screen is still in stable release ? And does it correspond to what i need ? – Erwan Douaille Mar 13 '15 at 23:34

1 Answers1

1

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.

ebassi
  • 8,648
  • 27
  • 29
  • Ok, so no way to make it live ? I mean,i cant use screenshot for apply shader on my desktop. – Erwan Douaille Mar 13 '15 at 23:32
  • You're literally asking a different thing, now; you should be more explicit in what you want to achieve when you ask a question. If you want to apply a shader to a window then you need to walk the scene graph and find the window actor you want, and use a ShaderEffect. If you want to apply a ShaderEffect to a region on the screen you'll need to apply the shader to the stage, and upload the region coordinates to the shader as a uniform. – ebassi Mar 16 '15 at 12:06
  • Thanks you answered to the post question plus my question in the comment above. – Erwan Douaille Aug 12 '15 at 13:04