Notes: how to check if a key sequence is bound (outside clutter)

This commit is contained in:
Ole Jørgen Brønner
2018-06-25 22:35:17 +02:00
parent 2dd9b86bb9
commit fd3be2cf25
+21
View File
@@ -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`.