1

I'm running Ubuntu Gnome, gnome shell version 3.24.2. I'm trying to create a gnome shell extension, and am using Javascript.

In my extension and in Javascript, how do I create a global key binding that is recognized from anywhere in Gnome? I want to bind a function to that key binding so that when the user presses the key combination then the said function is executed.

There's virtually no documentation on gnome-shell extension development. So asking here is my only option. Please don't refer me to the following stackoverflow question, since its answer is for Gnome 3.22 and I sincerely hope there's an easier way to create a key-binding: Gnome Shell Extension Key Binding

Arash B.
  • 11
  • 2

1 Answers1

1

There a pretty complete answer here: How to handle keyboard events in gnome shell extensions?

You may find the easiest way is to use Gnome Shell's DBus interface, but dealing with shortcut conflicts and handling the signal callbacks is unavoidable:

Bus Name: org.gnome.Shell -> Path: /org/gnome/Shell -> Interface: org.gnome.Shell

Relevant Methods:

GrabAccelerator(String accelerator, UInt32 flags) -> (UInt32 action) UngrabAccelerator(UInt32 action) -> (Boolean success)

Signal:

AcceleratorActivate(UInt32, Dict of {String, Variant})

andy.holmes
  • 3,383
  • 17
  • 28
  • thx for your reply. I'm now using the solution linked below, but I can only get it to work for "a" and not for for instance "" (note there's no last char such as "a". I get an error saying couldn't listen for this key binding. Do you know how I can create partial key bidning such as "" or "" using the solution I've linked below? https://superuser.com/questions/471606/gnome-shell-extension-key-binding/1182899#1182899 – Arash B. Sep 30 '17 at 09:30
  • As far as I know, that's not possible, since those are both modifier keys and don't trigger an `accelerator-activated` event. You'll have to bind to `key-press-event` and decode the keyname from the keyval as described in the answer I linked to above (also to solution you linked to above is a repost of the solution you asked not to be linked to...) – andy.holmes Sep 30 '17 at 20:57