Utility function for checking if a key-combo is bound

This commit is contained in:
Ole Jørgen Brønner
2018-07-06 12:16:37 +02:00
parent 5bce8922c1
commit f9fd005fa5
2 changed files with 19 additions and 0 deletions
+10
View File
@@ -39,3 +39,13 @@ function swapNeighbours() {
function showNavigator() {
Keybindings.bindkey("<Super>j", () => null, { opensNavigator: true })
}
// listFreeBindings("<super>").join("\n")
function listFreeBindings(modifierString) {
let free = [];
const chars = "abcdefghijklmnopqrstuvxyz1234567890".split("")
const symbols = ["minus", "comma", "period", "plus"]
return [].concat(chars, symbols).filter(
key => Keybindings.getBoundActionId(modifierString+key) === 0
).map(key => modifierString+key)
}
+9
View File
@@ -120,6 +120,15 @@ function openNavigatorHandler(actionName, keystr) {
}
}
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);
}
function handleAccelerator(display, actionId, deviceId, timestamp) {
const action = actionIdMap[actionId];