examples/keybindings.js: cycle-height

This commit is contained in:
Ole Jørgen Brønner
2019-01-05 11:14:39 +01:00
parent a586b230b3
commit e4916a434b
+52
View File
@@ -26,6 +26,7 @@ function gotoByIndex() {
}
}
function windowMarks() {
const Meta = imports.gi.Meta;
var marks = {}
@@ -88,6 +89,57 @@ function showNavigator() {
Keybindings.bindkey("<Super>j", "show-minimap", () => null, { opensMinimap: true })
}
function cycleWindowHeight() {
Keybindings.bindkey("<Super>q", "cycle-height", cycleHeight, { activeInNavigator: true });
var Tiling = Extension.imports.tiling;
function cycleHeight(metaWindow) {
const ratios = [1/3, 1/2, 2/3];
function findNext(tr) {
// Find the first ratio that is significantly bigger than 'tr'
for (let i = 0; i < ratios.length; i++) {
let r = ratios[i]
if (tr <= r) {
if (tr/r > 0.9) {
return (i+1) % ratios.length;
} else {
return i;
}
}
}
return 0; // cycle
}
let space = Tiling.spaces.spaceOfWindow(metaWindow);
if (!space)
return;
let i = space.indexOf(metaWindow);
function allocate(column, available) {
available -= (column.length - 1) * Tiling.prefs.window_gap;
let frame = metaWindow.get_frame_rect();
let r = frame.height / available;
let nextR = ratios[findNext(r)];
return column.map(mw => {
if (mw === metaWindow) {
return Math.floor(available * nextR);
} else {
return Math.floor(available * (1-nextR)/(column.length-1));
}
});
}
if (space[i].length > 1) {
space.layout(false, {customAllocators: {[i]: allocate}});
}
}
}
// listFreeBindings("<super>").join("\n")
function listFreeBindings(modifierString) {
let free = [];