Extensions of GNOME

Hello GNOME Planet!

I was wondering if you could help me in finding documentation about making extensions in GNOME. Where I can find documentation of the API in Javascript?

I am asking because, after running this code, the lap freeze:

const St = imports.gi.St;
const Main = imports.ui.main;
const Tweener = imports.ui.tweener;
const WebKit = imports.gi.WebKit;
const Gtk = imports.gi.Gtk;

let text, button;

function _hideHello() {
    text = null;

function _showHello() {
    /*if (!text) {
        text = new St.Label({ style_class: 'helloworld-label', text: "Hello, world!" });

    text.opacity = 255;

    let monitor = Main.layoutManager.primaryMonitor;

    text.set_position(Math.floor(monitor.width / 2 - text.width / 2),
                      Math.floor(monitor.height / 2 - text.height / 2));

                     { opacity: 0,
                       time: 2,
                       transition: 'easeOutQuad',
                       onComplete: _hideHello });*/

    Gtk.init(null, null);    

    win = new Gtk.Window({title: 'Ola Ke ase'});
    webview = new WebKit.WebView();
    hbox = new Gtk.HBox();




function init() {
    button = new St.Bin({ style_class: 'panel-button',
                          reactive: true,
                          can_focus: true,
                          x_fill: true,
                          y_fill: false,
                          track_hover: true });
    let icon = new St.Icon({ icon_name: 'system-run-symbolic',
                             style_class: 'system-status-icon' });

    button.connect('button-press-event', _showHello);

function enable() {
    Main.panel._rightBox.insert_child_at_index(button, 0);

function disable() {

Thanks in advanced,


About Julita Inca

Ingeniero de Sistemas UNAC, Magíster en Ciencias de la Computación PUCP, Magíster en Computación de Alto Rendimiento de la Universidad de Edimburgo, OPW GNOME 2011, Miembro de la GNOME Foundation desde el 2012, Embajadora Fedora Perú desde el 2012, ganadora del scholarship of the Linux Foundation 2012, experiencia como Admin Linux en GMD y Especialista IT en IBM, con certificaciones RHCE, RHCSA, AIX 6.1, AIX 7 Administrator e ITILv3. Experiencia académica en universidades como PUCP, USIL y UNI. Leader of LinuXatUNI Community, HPC Software Specialist at UKAEA, and reviewer of the Technological Magazine of ESPOL-RTE, and volunteering Linux training for MINSA Peru... a simple mortal, just like you!
This entry was posted in GNOME and tagged , , . Bookmark the permalink.

8 Responses to Extensions of GNOME

  1. duncan says:

    Welcome to the confusing world of shell extensions!

    The Shell API (other than the ST toolkit) is not officially documented, and much to the annoyance of everybody outside of gnome keeps changing (hence extensions requiring re-writes with every new version of the shell) – you are left to look at the source code. For other libraries, you can generate documentatioin from the gir file. See http://www.piware.de/2013/03/automatically-generating-documentation-from-gir-files/

    WRT your particular example, init() is used for setting up persistent items, UI items should be allocated/connected in enable() and deallocated/disconnected in disable(), or from the extension class’s function called from those two places. I doubt whether connecting an object to a signal is at all safe inside init(). There some very useful guidelines on the following blog: http://blog.mecheye.net/2012/02/requirements-and-tips-for-getting-your-gnome-shell-extension-approved/

    Secondly, I don’t think that you can call gtk.init()/gtk.main() in thiis way from within an extension. Somewhere is the depths of the shell code there is a section which enables extension writers to add their own preferences dialog (as a javascript function) running the result as a separate gtk window/thread – but getting that to work is a lot more complicated than just calling gtk.main(). Normally you would simply connect to the signals that you were interested in and recieve callbacks in your javascript code, in which case you don’t need either function call, since your extension is running on the main shell gtk event loop.

    Hope this helps!

    • slaf says:

      Well, Julita just take the extension.js generated by ‘gnome-shell-extension-tool -c’ command , comment some parts and add the webkit and gtk stuff.
      So i think this tool is not up-to-date with new rules 🙂

      • duncan says:

        Thats exactly whats she has done, and you are right gnome-shell-extension-tool is generating code which was banned with the arrival of gnome 3.4. (see the guidelines blog posted above).

        There’s a bug report here, if anyone wants to file it.

  2. There is a bigger problem here: you cannot use toplevel Gtk windows in a shell extension, because you are running inside the window manager. Basically, any Gtk widget is out of question in a shell extension, because the way windows are created and events are delivered by Gdk are incompatible with mutter. (The fact that menus work on windows is a result of multiple hacks in mutter core, that cannot be replicated in JS)

    • duncan says:

      So now we have defined the problem, what is the solution?
      Write the window and its widgets as a separate application and merely use the extension to launch it as an independent task?

  3. casaxa says:

    /*if (!text) {
    Have you removed this /* ?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s