Actions: implement cyclePresetWidths (resolves #57)

This commit is contained in:
Peter Fajdiga
2024-10-04 10:38:50 +02:00
parent 218ab65d61
commit 6e53bbad2f
3 changed files with 97 additions and 0 deletions

View File

@@ -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();
}

View File

@@ -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",

View File

@@ -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));
});