diff --git a/notes.org b/notes.org index 72a0aaa..48d053d 100644 --- a/notes.org +++ b/notes.org @@ -67,7 +67,28 @@ global.display.connect( display, action, deviceId, timestamp) }) #+END_SRC +** Lookup an keybinding action by a accelerator string +~global.display.get_keybinding_action(keycode, mask)~ is simple to use in clutter event handlers since the keycode and mask is readily available. Outside of clutter is harder: +#+BEGIN_SRC javascript +function devirtualizeMask(gdkVirtualMask) { + const keymap = Gdk.Keymap.get_default(); + let [success, rawMask] = keymap.map_virtual_modifiers(gdkVirtualMask); + if (!success) + throw new Error("Couldn't devirtualize mask " + gdkVirtualMask); + return rawMask; +} + +function getBoundActionId(keystr) { + let [dontcare, keycodes, mask] = + Gtk.accelerator_parse_with_keycode(keystr); + if(keycodes.length > 1) { + throw new Error("Multiple keycodes " + keycodes + " " + keystr); + } + const rawMask = devirtualizeMask(mask); + return global.display.get_keybinding_action(keycodes[0], rawMask); +} +#+END_SRC * GJS ** import system / module system `imports.NAME` reflects the directories and javascript files present in `imports.searchPath`.