From 92144e8e83ee6b88d37b7d93366e2cbb426c872f Mon Sep 17 00:00:00 2001 From: Peter Fajdiga Date: Sun, 13 Oct 2024 19:36:39 +0200 Subject: [PATCH] prevent widening left neighbor on edge resize with min-width --- src/lib/layout/Window.ts | 10 +++++---- src/lib/world/clientState/Tiled.ts | 2 +- src/tests/flows/userResize.ts | 33 ++++++++++++++++++++++++++++-- 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/src/lib/layout/Window.ts b/src/lib/layout/Window.ts index 9679d61..b7f359b 100644 --- a/src/lib/layout/Window.ts +++ b/src/lib/layout/Window.ts @@ -116,11 +116,13 @@ class Window { const widthDelta = newGeometry.width - oldGeometry.width; const heightDelta = newGeometry.height - oldGeometry.height; if (widthDelta !== 0) { - this.column.adjustWidth(widthDelta, true); - let leftEdgeDelta = newGeometry.left - oldGeometry.left; - const resizingLeftSide = leftEdgeDelta !== 0; + const resizingLeftSide = newGeometry.left !== oldGeometry.left; + let widthDeltaTotal = newGeometry.width - startWidth; + const oldColumnWidth = this.column.getWidth(); + this.column.setWidth(startWidth + widthDeltaTotal, true); + widthDeltaTotal = this.column.getWidth() - startWidth; + let leftEdgeDelta = resizingLeftSide ? oldColumnWidth - this.column.getWidth() : 0; if (neighbor !== undefined) { - const widthDeltaTotal = newGeometry.width - startWidth; const oldNeighborWidth = neighbor.column.getWidth(); neighbor.column.setWidth(neighbor.startWidth - widthDeltaTotal, true); if (resizingLeftSide) { diff --git a/src/lib/world/clientState/Tiled.ts b/src/lib/world/clientState/Tiled.ts index e691542..a0b13fb 100644 --- a/src/lib/world/clientState/Tiled.ts +++ b/src/lib/world/clientState/Tiled.ts @@ -84,7 +84,7 @@ namespace ClientState { if (kwinClient.resize) { resizing = true; - resizeStartWidth = kwinClient.frameGeometry.width; + resizeStartWidth = window.column.getWidth(); if (config.resizeNeighborColumn) { const resizeNeighborColumn = Tiled.getResizeNeighborColumn(window); if (resizeNeighborColumn !== null) { diff --git a/src/tests/flows/userResize.ts b/src/tests/flows/userResize.ts index 730c099..7e29759 100644 --- a/src/tests/flows/userResize.ts +++ b/src/tests/flows/userResize.ts @@ -72,10 +72,39 @@ tests.register("User resize", 10, () => { assertSizes(310, 295, h-20, h+20); workspaceMock.resizeWindow(clientRightBottom, true, true, false, new MockQmlSize(-10, 20)); - assertSizes(320, 295, h-20, h+20); + assertSizes(310, 295, h-20, h+20); + + workspaceMock.resizeWindow(clientRightTop, true, true, false, new MockQmlSize(-10, 0)); + assertSizes(310, 295, h-20, h+20); // TODO // workspaceMock.resizeWindow(clientRightBottom, true, false, true, new MockQmlSize(0, -80)); - // assertSizes(320, 295, h+60, h-20); + // assertSizes(310, 295, h+60, h-20); + } + + { + const { qtMock, workspaceMock, world } = init(config); + const [clientLeftTop, clientLeftBottom, clientRight] = workspaceMock.createClientsWithWidths(300, 200, 300); + clientLeftBottom.minSize = new MockQmlSize(295, h-20); + + function assertSizes(leftWidth: number, rightWidth: number, topHeight: number, bottomHeight: number) { + const { left, right } = getGridBounds(clientLeftTop, clientRight); + Assert.rect(clientLeftTop.frameGeometry, left, tilingArea.top, leftWidth, topHeight); + Assert.rect(clientLeftBottom.frameGeometry, left, tilingArea.top+topHeight+gapV, leftWidth, bottomHeight); + Assert.rect(clientRight.frameGeometry, left+leftWidth+gapH, tilingArea.top, rightWidth, tilingArea.height); + } + + workspaceMock.activeWindow = clientLeftBottom; + qtMock.fireShortcut("karousel-window-move-left"); + assertSizes(300, 300, h, h); + + workspaceMock.resizeWindow(clientLeftTop, true, false, false, new MockQmlSize(-10, 0)); + assertSizes(295, 305, h, h); + + workspaceMock.resizeWindow(clientLeftTop, true, false, false, new MockQmlSize(10, 0)); + assertSizes(305, 295, h, h); + + workspaceMock.resizeWindow(clientLeftTop, true, false, false, new MockQmlSize(-20, 0), new MockQmlSize(20, 0)); + assertSizes(305, 295, h, h); } });