Gnome shell Hello world

Gnome Shell, besides providing the main user interface for GNOME 3, is a Javascript shell with bindings to many native interfaces that allow e.g. Window manipulation, graphics rendering and animations, compositing, etc. It also allows developers to write extensions changing Gnome Shell's behavior.

Less known is that it is possible to replace the entire Javascript code base that Gnome Shell uses. It can be useful to hack on Gnome Shell itself (no need to fiddle with system files, or, since 3.12, no need to rebuild libgnome-shell.so), but it can also be used to implement a completely new User Interface in Javascript.

I'm starting to experiment with the latter, because I want to try building a window manager that fits my needs, while keeping away the boring details of EWMH, xinerama, and other X11 things. And because it's fun.

But baby steps, first: let's bootstrap a Hello world with Gnome shell.

  • Create a directory that will hold your code.
  • In that directory, create a ui subdirectory.
  • In that ui directory, create a environment.js file, with the following contents:
    const Shell = imports.gi.Shell;
    
    function init() {
      window.global = Shell.Global.get();
    }
    
  • In the same directory, create a main.js file, with the following contents:
    const St = imports.gi.St;
    
    function start() {
      let text = new St.Label({ text: "Hello, world!" });
      global.stage.add_actor(text);
      global.stage.show();
    }
    
  • Run Gnome Shell with your code:
    $ GNOME_SHELL_JS=/path/to/parent/of/ui gnome-shell
    

    You may want to run this in a separate X server (I use Xephyr)

I tested this with Gnome Shell 3.14. Trying various older versions, I got different results for reasons I don't know. 3.4 doesn't display anything unless, paradoxically, global.stage.show() is removed, and 3.8 doesn't display anything no matter what.

I guess the next step is to go through some Clutter tutorials and transpose them to Javascript.

Update: On the other hand, a lot of the window managing is still done by mutter under the hood, which doesn't leave a lot of space for something really different.

2015-05-04 04:10:17+0900

miscellaneous, p.d.o

Responses are currently closed, but you can trackback from your own site.

One Response to “Gnome shell Hello world”

  1. autra Says:

    I tried that like 1-2 years ago. I just wanted to add some keybinding (so a lot less ambitious than you). I gave up seeing the poorness of the documentation and because as you said, you can’t do something completely different…

    Maybe things have improved since though. I might give it another try one day.