diff --git a/src/tests/flows/userResize.ts b/src/tests/flows/userResize.ts new file mode 100644 index 0000000..8e1dd2e --- /dev/null +++ b/src/tests/flows/userResize.ts @@ -0,0 +1,72 @@ +tests.register("User resize", 1, () => { + const config = getDefaultConfig(); + config.resizeNeighborColumn = true; + + const h = getWindowHeight(2); + let clientLeft: MockKwinClient, clientRightTop: MockKwinClient, clientRightBottom: MockKwinClient; + function assertSizes(leftWidth: number, rightWidth: number, topHeight: number, bottomHeight: number) { + const { left, right } = getGridBounds(clientLeft, clientRightTop); + Assert.rect(clientLeft.frameGeometry, left, tilingArea.top, leftWidth, tilingArea.height); + Assert.rect(clientRightTop.frameGeometry, left+leftWidth+gapH, tilingArea.top, rightWidth, topHeight); + Assert.rect(clientRightBottom.frameGeometry, left+leftWidth+gapH, tilingArea.top+topHeight+gapV, rightWidth, bottomHeight); + } + + { + const { qtMock, workspaceMock, world } = init(config); + [clientLeft, clientRightTop, clientRightBottom] = workspaceMock.createClientsWithWidths(300, 300, 200); + qtMock.fireShortcut("karousel-window-move-left"); + assertSizes(300, 300, h, h); + + workspaceMock.resizeWindow(clientLeft, 10, 20, false, false, false); + assertSizes(310, 300, h, h); + + workspaceMock.resizeWindow(clientRightTop, -10, -20, false, false, false); + assertSizes(310, 290, h-20, h+20); + + workspaceMock.resizeWindow(clientRightBottom, -10, 20, false, false, false); + assertSizes(310, 280, h-20, h+20); + + workspaceMock.resizeWindow(clientRightBottom, 0, 20, false, true, false); + assertSizes(310, 280, h-40, h+40); + } + + { + const { qtMock, workspaceMock, world } = init(config); + [clientLeft, clientRightTop, clientRightBottom] = workspaceMock.createClientsWithWidths(300, 300, 200); + qtMock.fireShortcut("karousel-window-move-left"); + assertSizes(300, 300, h, h); + + workspaceMock.resizeWindow(clientLeft, 10, 20, false, false, true); + assertSizes(310, 290, h, h); + + workspaceMock.resizeWindow(clientRightTop, -10, -20, false, false, true); + assertSizes(310, 280, h-20, h+20); + + workspaceMock.resizeWindow(clientRightBottom, -10, 20, true, false, true); + assertSizes(320, 270, h-20, h+20); + + workspaceMock.resizeWindow(clientRightBottom, 0, 20, false, true, true); + assertSizes(320, 270, h-40, h+40); + } + + { + const { qtMock, workspaceMock, world } = init(config); + [clientLeft, clientRightTop, clientRightBottom] = workspaceMock.createClientsWithWidths(300, 300, 200); + clientRightBottom.minSize = new MockQmlSize(295, h-20); + qtMock.fireShortcut("karousel-window-move-left"); + assertSizes(300, 300, h, h); + + workspaceMock.resizeWindow(clientLeft, 10, 20, false, false, true); + assertSizes(310, 295, h, h); + + workspaceMock.resizeWindow(clientRightTop, -10, -20, false, false, true); + assertSizes(310, 295, h-20, h+20); + + workspaceMock.resizeWindow(clientRightBottom, -10, 20, true, false, true); + assertSizes(320, 295, h-20, h+20); + + // TODO + // workspaceMock.resizeWindow(clientRightBottom, 0, -80, false, true, true); + // assertSizes(320, 295, h+60, h-20); + } +}); diff --git a/src/tests/utils/global.ts b/src/tests/utils/global.ts index e0c9e24..f12efa7 100644 --- a/src/tests/utils/global.ts +++ b/src/tests/utils/global.ts @@ -32,3 +32,15 @@ function init(config: Config) { const world = new World(config); return { qtMock, workspaceMock, world }; } + +function getGridBounds(clientLeft: KwinClient, clientRight: KwinClient) { + const columnsWidth = clientRight.frameGeometry.right - clientLeft.frameGeometry.left; + const left = Math.floor((screen.width - columnsWidth) / 2); + const right = left + columnsWidth; + return { left, right }; +} + +function getWindowHeight(windowsInColumn: number) { + const totalGaps = (windowsInColumn-1) * gapV; + return Math.round((tilingArea.height - totalGaps) / windowsInColumn); +} diff --git a/src/tests/utils/mocks/MockKwinClient.ts b/src/tests/utils/mocks/MockKwinClient.ts index d6864e7..1545f0e 100644 --- a/src/tests/utils/mocks/MockKwinClient.ts +++ b/src/tests/utils/mocks/MockKwinClient.ts @@ -8,7 +8,7 @@ class MockKwinClient { public minSize: Readonly = new MockQmlSize(0, 0); public readonly transient: boolean; public readonly move: boolean = false; - public readonly resize: boolean = false; + public resize: boolean = false; public readonly moveable: boolean = true; public readonly resizeable: boolean = true; public readonly fullScreenable: boolean = true; @@ -185,4 +185,8 @@ class MockKwinClient { public unpin() { this.tile = null; } + + public getFrameGeometryCopy() { + return this._frameGeometry.clone(); + } } diff --git a/src/tests/utils/mocks/MockWorkspace.ts b/src/tests/utils/mocks/MockWorkspace.ts index db7322d..edd45ab 100644 --- a/src/tests/utils/mocks/MockWorkspace.ts +++ b/src/tests/utils/mocks/MockWorkspace.ts @@ -49,6 +49,40 @@ class MockWorkspace { return this.createClientsWithFrames(...widths.map(width => new MockQmlRect(randomInt(100), randomInt(100), width, 100+randomInt(400)))); } + public resizeWindow(window: MockKwinClient, widthDelta: number, heightDelta: number, leftEdge: boolean, topEdge: boolean, edgeResize: boolean) { + const frame = window.getFrameGeometryCopy(); + if (edgeResize) { + this.cursorPos = new MockQmlPoint( + leftEdge ? frame.left : frame.right, + topEdge ? frame.top : frame.bottom, + ); + } else { + this.cursorPos = new MockQmlPoint( + Math.round(frame.x + frame.width/2), + Math.round(frame.y + frame.height/2), + ); + } + window.resize = true; + window.interactiveMoveResizeStarted.fire(); + + if (widthDelta !== 0) { + frame.width += widthDelta; + if (leftEdge) { + frame.x -= widthDelta; + } + } + if (heightDelta !== 0) { + frame.height += heightDelta; + if (topEdge) { + frame.y -= heightDelta; + } + } + window.frameGeometry = frame; + + window.resize = false; + window.interactiveMoveResizeFinished.fire(); + } + public get activeWindow() { return this._activeWindow; }