diff --git a/src/lib/keyBindings/Actions.ts b/src/lib/keyBindings/Actions.ts index f5e7d4e..893ef2a 100644 --- a/src/lib/keyBindings/Actions.ts +++ b/src/lib/keyBindings/Actions.ts @@ -184,6 +184,17 @@ class Actions { this.config.columnResizer.decreaseWidth(column, this.config.manualResizeStep); } + public readonly cyclePresetWidths = (cm: ClientManager, dm: DesktopManager, window: Window, column: Column, grid: Grid) => { + if (this.config.presetWidths === null) { + return; + } + const widths = this.config.presetWidths.get(column.getMinWidth(), column.getMaxWidth()); + const currentWidth = column.getWidth(); + const nextIndex = widths.findIndex(width => width < currentWidth); + const nextWidth = nextIndex >= 0 ? widths[nextIndex] : widths[0]; + column.setWidth(nextWidth, true); + } + public readonly columnsWidthEqualize = (cm: ClientManager, dm: DesktopManager) => { dm.getCurrentDesktop().equalizeVisibleColumnsWidths(); } diff --git a/src/lib/keyBindings/definition.ts b/src/lib/keyBindings/definition.ts index a39542d..828b43b 100644 --- a/src/lib/keyBindings/definition.ts +++ b/src/lib/keyBindings/definition.ts @@ -146,6 +146,12 @@ function getKeyBindings(world: World, actions: Actions): KeyBinding[] { defaultKeySequence: "Meta+Ctrl+-", action: () => world.doIfTiledFocused(actions.columnWidthDecrease), }, + { + name: "cycle-preset-widths", + description: "Cycle through preset column widths", + defaultKeySequence: "Meta+R", + action: () => world.doIfTiledFocused(actions.cyclePresetWidths), + }, { name: "columns-width-equalize", description: "Equalize widths of visible columns", diff --git a/src/tests/flows/presetWidths.ts b/src/tests/flows/presetWidths.ts new file mode 100644 index 0000000..51545b9 --- /dev/null +++ b/src/tests/flows/presetWidths.ts @@ -0,0 +1,80 @@ +tests.register("Preset Widths default", 1, () => { + const { qtMock, workspaceMock } = initMocks(); + const config = getDefaultConfig(); + const world = new World(config); + + const maxWidth = screenWidth - config.gapsOuterLeft - config.gapsOuterRight; + const halfWidth = maxWidth/2 - config.gapsInnerHorizontal/2; + + const kwinClient = new MockKwinClient( + 1, + "app1", + "Application 1", + new MockQmlRect(10, 20, 300, 200), + ); + + function getRect(columnWidth: number) { + return new MockQmlRect( + (screenWidth - columnWidth) / 2, + config.gapsOuterTop, + columnWidth, + screenHeight - config.gapsOuterTop - config.gapsOuterBottom, + ); + } + + workspaceMock.createWindow(kwinClient); + assertRectEqual(kwinClient.frameGeometry, getRect(300)); + + qtMock.fireShortcut("karousel-cycle-preset-widths"); + assertRectEqual(kwinClient.frameGeometry, getRect(maxWidth)); + + qtMock.fireShortcut("karousel-cycle-preset-widths"); + assertRectEqual(kwinClient.frameGeometry, getRect(halfWidth)); + + qtMock.fireShortcut("karousel-cycle-preset-widths"); + assertRectEqual(kwinClient.frameGeometry, getRect(maxWidth)); +}); + +tests.register("Preset Widths custom", 1, () => { + const { qtMock, workspaceMock } = initMocks(); + const config = getDefaultConfig(); + config.presetWidths = "500px, 250px, 100px, 50%"; + const world = new World(config); + + const maxWidth = screenWidth - config.gapsOuterLeft - config.gapsOuterRight; + const halfWidth = maxWidth/2 - config.gapsInnerHorizontal/2; + + const kwinClient = new MockKwinClient( + 1, + "app1", + "Application 1", + new MockQmlRect(10, 20, 300, 200), + ); + + function getRect(columnWidth: number) { + return new MockQmlRect( + (screenWidth - columnWidth) / 2, + config.gapsOuterTop, + columnWidth, + screenHeight - config.gapsOuterTop - config.gapsOuterBottom, + ); + } + + workspaceMock.createWindow(kwinClient); + assertRectEqual(kwinClient.frameGeometry, getRect(300)); + + qtMock.fireShortcut("karousel-cycle-preset-widths"); + assertRectEqual(kwinClient.frameGeometry, getRect(250)); + + qtMock.fireShortcut("karousel-cycle-preset-widths"); + assertRectEqual(kwinClient.frameGeometry, getRect(100)); + + qtMock.fireShortcut("karousel-cycle-preset-widths"); + assertRectEqual(kwinClient.frameGeometry, getRect(500)); + + qtMock.fireShortcut("karousel-cycle-preset-widths"); + assertRectEqual(kwinClient.frameGeometry, getRect(halfWidth)); + + qtMock.fireShortcut("karousel-cycle-preset-widths"); + assertRectEqual(kwinClient.frameGeometry, getRect(250)); +});