From 08135a4ad4665f96c75ffcb6c99cb71dc578bcc6 Mon Sep 17 00:00:00 2001 From: Peter Fajdiga Date: Sat, 2 Sep 2023 10:54:47 +0200 Subject: [PATCH] prevent setting incorrect frameGeometry to windows that went from Karousel-tiled to Kwin-quick-tiled --- src/world/ClientManager.ts | 6 +++--- src/world/ClientWrapper.ts | 10 +++++++--- src/world/clientState/Floating.ts | 6 ++++++ src/world/clientState/Tiled.ts | 2 +- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/world/ClientManager.ts b/src/world/ClientManager.ts index 79cfc20..675f9d8 100644 --- a/src/world/ClientManager.ts +++ b/src/world/ClientManager.ts @@ -25,7 +25,7 @@ class ClientManager { console.assert(!this.hasClient(kwinClient)); const client = new ClientWrapper( kwinClient, - new ClientState.Floating(), + new ClientState.Floating(null), this.findTransientFor(kwinClient), this.windowRuleEnforcer.initClientSignalManager(this.world, kwinClient), ); @@ -101,7 +101,7 @@ class ClientManager { return; } if (client.stateManager.getState() instanceof ClientState.Tiled) { - client.stateManager.setState(() => new ClientState.Floating(), false); + client.stateManager.setState(() => new ClientState.Floating(client), false); } } @@ -117,7 +117,7 @@ class ClientManager { const grid = this.desktopManager.getDesktopForClient(client.kwinClient).grid; client.stateManager.setState(() => new ClientState.Tiled(this.world, client, grid), false); } else if (clientState instanceof ClientState.Tiled) { - client.stateManager.setState(() => new ClientState.Floating(), false); + client.stateManager.setState(() => new ClientState.Floating(client), false); } } diff --git a/src/world/ClientWrapper.ts b/src/world/ClientWrapper.ts index c7b896f..4925bf9 100644 --- a/src/world/ClientWrapper.ts +++ b/src/world/ClientWrapper.ts @@ -99,21 +99,25 @@ class ClientWrapper { this.setMaximize(false, false); } - public prepareForFloating(screenSize: QRect) { + public restoreAfterTiling(screenSize: QRect) { this.kwinClient.keepBelow = false; this.setShade(false); this.setFullScreen(false); if (this.kwinClient.tile === null) { this.setMaximize(false, false); } + this.ensureVisible(screenSize); + } + public prepareForFloating() { + const placementArea = workspace.clientArea(ClientAreaOption.PlacementArea, this.kwinClient.screen, this.kwinClient.desktop); const clientRect = this.kwinClient.frameGeometry; const width = this.preferredWidth; this.place( - clamp(clientRect.x, screenSize.left, screenSize.right - width), + clientRect.x, clientRect.y, width, - Math.min(clientRect.height, Math.round(screenSize.height / 2)), + Math.min(clientRect.height, Math.round(placementArea.height / 2)), ); } diff --git a/src/world/clientState/Floating.ts b/src/world/clientState/Floating.ts index b73a150..08132ef 100644 --- a/src/world/clientState/Floating.ts +++ b/src/world/clientState/Floating.ts @@ -1,5 +1,11 @@ namespace ClientState { export class Floating implements State { + constructor(client: ClientWrapper | null) { + if (client !== null && client.kwinClient.tile === null) { + client.prepareForFloating(); + } + } + public destroy(passFocus: boolean) {} } } diff --git a/src/world/clientState/Tiled.ts b/src/world/clientState/Tiled.ts index 9086021..81cad23 100644 --- a/src/world/clientState/Tiled.ts +++ b/src/world/clientState/Tiled.ts @@ -21,7 +21,7 @@ namespace ClientState { const client = window.client; window.destroy(passFocus); - client.prepareForFloating(grid.desktop.clientArea); + client.restoreAfterTiling(grid.desktop.clientArea); } private static initSignalManager(world: World, window: Window) {