PaperWM/examples/keybindings.js
Ole Jørgen Brønner 71b6ee8f56 Unify regular keybinding api an schemaless keybinding api
Try to make it a bit more "action oriented":

  An action exists independently of its binding. It could conceivable be invoked
  by other means too.

Some weirdness from the marriage remain to weed out, but this is a working
stepping stone.
2018-07-06 12:16:37 +02:00

86 lines
2.5 KiB
JavaScript

var Extension = imports.misc.extensionUtils.extensions['paperwm@hedning:matrix.org'];
var Keybindings = Extension.imports.keybindings;
var Main = imports.ui.main;
var Tiling = Extension.imports.tiling;
function gotoByIndex() {
function goto(k) {
return () => {
let space = Tiling.spaces.get(global.screen.get_active_workspace());
let metaWindow = space.getWindow(k, 0)
if (!metaWindow)
return;
if (metaWindow.has_focus()) {
// Can happen when navigator is open
Tiling.ensureViewport(metaWindow);
} else {
Main.activateWindow(metaWindow);
}
}
}
for(let k = 1; k <= 9; k++) {
Keybindings.bindkey(`<Super>${k}`, `goto-coloumn-${i}`,
goto(k-1), {activeInNavigator: true})
}
}
function windowMarks() {
var marks = {}
function setMark(k) {
return (mw) => marks[k] = mw
}
function gotoMark(k) {
return () => {
let metaWindow = marks[k];
if (!metaWindow)
return;
if (metaWindow.has_focus()) {
// Can happen when navigator is open
Tiling.ensureViewport(metaWindow);
} else {
Main.activateWindow(metaWindow);
}
}
}
for(let k = 0; k <= 9; k++) {
Keybindings.bindkey(`<Super>${k}`, `goto-mark-${k}`,
gotoMark(k), {activeInNavigator: true})
Keybindings.bindkey(`<Super><Shift>${k}`, `set-mark-${k}`,
setMark(k), {activeInNavigator: true})
}
}
function swapNeighbours() {
var Tiling = Extension.imports.tiling;
var Meta = imports.gi.Meta;
Keybindings.bindkey("<Super>y", "swap-neighbours", (mw) => {
let space = Tiling.spaces.spaceOfWindow(mw)
let i = space.indexOf(mw);
if (space[i+1]) {
space.swap(Meta.MotionDirection.RIGHT, space[i+1][0])
}
}, {activeInNavigator: true})
}
function showNavigator() {
Keybindings.bindkey("<Super>j", "show-minimap", () => 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)
}