From fd3be2cf25614e2ab0f75d636e8a8aaa9161298c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20J=C3=B8rgen=20Br=C3=B8nner?= Date: Mon, 25 Jun 2018 22:34:29 +0200 Subject: [PATCH] Notes: how to check if a key sequence is bound (outside clutter) --- notes.org | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) 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`.