GNOME Extension keyboard shortcut

I have made a simple GNOME extension for changing display configurations from the quick settings menu, and was wondering if it is possible to register for shortcuts in a GNOME extension (so create a keyboard shortcut that my extension is able to react to). I know how to do this in GTK, but since extensions don’t use GTK I was unsure what the solution was.

I looked through the documentation on Extensions | GNOME JavaScript but was unable to find any information on this topic.

https://gjs-docs.gnome.org/meta15~15/meta.display#method-add_keybinding

1 Like

I will add to this, that the given method was not enough for me to get keybindings working for my GNOME extension. What I actually ended up using was the following function from WindowManager.js:

    addKeybinding(name, settings, flags, modes, handler) {
        let action = global.display.add_keybinding(name, settings, flags, handler);
        if (action !== Meta.KeyBindingAction.NONE)
            this.allowKeybinding(name, modes);
        return action;
    }

It can be seen that it actually uses the function that was mentioned in the other answer, but with an extra step of calling allowKeybinding.

To use this in extension.js, you can do:

Main.wm.addKeybinding(
    key,
    settings,
    Shell.ActionMode.NORMAL,
    handler
);

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.