diff --git a/examples/keybindings.js b/examples/keybindings.js index 3b14881..678d759 100644 --- a/examples/keybindings.js +++ b/examples/keybindings.js @@ -26,6 +26,7 @@ function gotoByIndex() { } } + function windowMarks() { const Meta = imports.gi.Meta; var marks = {} @@ -88,6 +89,57 @@ function showNavigator() { Keybindings.bindkey("j", "show-minimap", () => null, { opensMinimap: true }) } + +function cycleWindowHeight() { + Keybindings.bindkey("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("").join("\n") function listFreeBindings(modifierString) { let free = [];