keybindings: cycle window height <super><shift>r

This commit is contained in:
Ole Jørgen Brønner
2019-01-05 12:52:52 +01:00
parent 4eea221a39
commit d5a7c81895
7 changed files with 61 additions and 51 deletions
+1
View File
@@ -59,6 +59,7 @@ PaperWM doesn't handle attached modal dialogs very well, so it's best to turn it
| <kbd>Super</kbd><kbd>Shift</kbd><kbd>Tab</kbd> or <kbd>Alt</kbd><kbd>Shift</kbd><kbd>Tab</kbd> | Cycle backwards through the most recently used windows |
| <kbd>Super</kbd><kbd>C</kbd> | Center the active window horizontally |
| <kbd>Super</kbd><kbd>R</kbd> | Resize the window (cycles through useful widths) |
| <kbd>Super</kbd><kbd>Shift</kbd><kbd>R</kbd> | Resize the window (cycles through useful heights) |
| <kbd>Super</kbd><kbd>F</kbd> | Maximize the width of a window |
| <kbd>Super</kbd><kbd>Shift</kbd><kbd>F</kbd> | Toggle fullscreen |
| <kbd>Super</kbd><kbd>Return</kbd> or <kbd>Super</kbd><kbd>N</kbd> | Create a new window from the active application |
-50
View File
@@ -90,56 +90,6 @@ function showNavigator() {
}
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 = [];
+5
View File
@@ -118,6 +118,11 @@ function init() {
Tiling),
Meta.KeyBindingFlags.PER_WINDOW);
registerPaperAction("cycle-height",
dynamic_function_ref("cycleWindowHeight",
Tiling),
Meta.KeyBindingFlags.PER_WINDOW);
registerPaperAction("center-horizontally",
dynamic_function_ref("centerWindowHorizontally",
Tiling),
+2 -1
View File
@@ -164,7 +164,8 @@ class SettingsWidget {
'switch-first', 'switch-last', 'live-alt-tab', 'live-alt-tab-backward',
'move-left', 'move-right', 'move-up', 'move-down',
'slurp-in', 'barf-out', 'center-horizontally',
'paper-toggle-fullscreen', 'toggle-maximize-width', 'cycle-width']
'paper-toggle-fullscreen', 'toggle-maximize-width', 'cycle-width',
'cycle-height']
.forEach(k => {
addKeybinding(windows.model.child_model, settings, k);
});
Binary file not shown.
@@ -113,6 +113,11 @@
<summary>Cycle through useful window widths</summary>
</key>
<key type="as" name="cycle-height">
<default><![CDATA[['<Super><Shift>r']]]></default>
<summary>Cycle through useful window heights</summary>
</key>
<key type="as" name="center-horizontally">
<default><![CDATA[['<Super>c']]]></default>
<summary>Center window horizontally</summary>
+48
View File
@@ -2345,6 +2345,54 @@ function cycleWindowWidth(metaWindow) {
metaWindow.move_resize_frame(true, nextX, frame.y, nextW, frame.height);
}
function cycleWindowHeight(metaWindow) {
log("OMG")
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 = spaces.spaceOfWindow(metaWindow);
if (!space)
return;
let i = space.indexOf(metaWindow);
// Fix `frame` outside `allocate` so the allocation wont change during
// fixpoint calculation. (could move more out, but then we'd have to
// calculate available manually)
let frame = metaWindow.get_frame_rect();
function allocate(column, available) {
available -= (column.length - 1) * prefs.window_gap;
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}});
}
}
function activateNthWindow(n, space) {
space = space || spaces.spaceOf(workspaceManager.get_active_workspace());
let nth = space[n][0];