examples/keybindings: tile into left/right column

Takes the selected window and tile it into the left/right neighbour column.
This commit is contained in:
Ole Jørgen Brønner
2019-10-31 20:08:03 +01:00
parent 0bd9de889e
commit d2887263a2
+30
View File
@@ -205,3 +205,33 @@ function adjustWidth(incBinding="<Super>plus", decBinding="<Super>minus", increm
Keybindings.bindkey(incBinding, "inc-width", adjuster(increment));
Keybindings.bindkey(decBinding, "dec-width", adjuster(-increment));
}
function tileInto(leftBinding="<Super>less", rightBinding="<Super><Shift>less") {
// less: '<'
let Tiling = Extension.imports.tiling;
const tileIntoDirection = (dir=-1) => (metaWindow) => {
let space = Tiling.spaces.spaceOfWindow(metaWindow);
let jFrom = space.indexOf(metaWindow);
let jTo = jFrom + dir;
if (jTo < 0 || jTo >= space.length)
return;
space[jFrom].splice(space.rowOf(metaWindow), 1);
space[jTo].push(metaWindow);
if (space[jFrom].length === 0) {
space.splice(jFrom, 1);
}
space.layout(true, {
customAllocators: { [space.indexOf(metaWindow)]: Tiling.allocateEqualHeight }
});
space.emit("full-layout");
}
let options = { activeInNavigator: true };
if (leftBinding)
Keybindings.bindkey(leftBinding, "tile-into-left-column", tileIntoDirection(-1), options);
if (rightBinding)
Keybindings.bindkey(rightBinding, "tile-into-right-column", tileIntoDirection(1), options);
}