diff --git a/src/rules/WindowRuleEnforcer.ts b/src/rules/WindowRuleEnforcer.ts index f228af7..561d2eb 100644 --- a/src/rules/WindowRuleEnforcer.ts +++ b/src/rules/WindowRuleEnforcer.ts @@ -31,8 +31,9 @@ class WindowRuleEnforcer { manager.connect(kwinClient.captionChanged, () => { const shouldTile = enforcer.shouldTile(kwinClient); world.do((clientManager, desktopManager) => { - if (shouldTile) { - clientManager.tileClient(kwinClient); + const desktop = desktopManager.getDesktopForClient(kwinClient); + if (shouldTile && desktop !== undefined) { + clientManager.tileClient(kwinClient, desktop.grid); } else { clientManager.untileClient(kwinClient); } diff --git a/src/world/ClientManager.ts b/src/world/ClientManager.ts index 4a3a707..fa349e9 100644 --- a/src/world/ClientManager.ts +++ b/src/world/ClientManager.ts @@ -27,13 +27,13 @@ class ClientManager { public addClient(kwinClient: KwinClient) { console.assert(!this.hasClient(kwinClient)); + const desktop = this.desktopManager.getDesktopForClient(kwinClient); let constructState: (client: ClientWrapper) => ClientState.State; if (kwinClient.dock) { constructState = () => new ClientState.Docked(this.world, kwinClient); - } else if (this.windowRuleEnforcer.shouldTile(kwinClient)) { - const grid = this.desktopManager.getDesktopForClient(kwinClient).grid; - constructState = (client: ClientWrapper) => new ClientState.Tiled(this.world, client, grid); + } else if (this.windowRuleEnforcer.shouldTile(kwinClient) && desktop !== undefined) { + constructState = (client: ClientWrapper) => new ClientState.Tiled(this.world, client, desktop.grid); } else { constructState = (client: ClientWrapper) => new ClientState.Floating(this.world, client, this.config, false); } @@ -86,12 +86,16 @@ class ClientManager { return; } if (client.stateManager.getState() instanceof ClientState.TiledMinimized) { - const grid = this.desktopManager.getDesktopForClient(kwinClient).grid; - client.stateManager.setState(() => new ClientState.Tiled(this.world, client, grid), false); + const desktop = this.desktopManager.getDesktopForClient(kwinClient); + if (desktop !== undefined) { + client.stateManager.setState(() => new ClientState.Tiled(this.world, client, desktop.grid), false); + } else { + client.stateManager.setState(() => new ClientState.Floating(this.world, client, this.config, false), false); + } } } - public tileClient(kwinClient: KwinClient) { + public tileClient(kwinClient: KwinClient, grid: Grid) { const client = this.clientMap.get(kwinClient); if (client === undefined) { return; @@ -99,7 +103,6 @@ class ClientManager { if (client.stateManager.getState() instanceof ClientState.Tiled) { return; } - const grid = this.desktopManager.getDesktopForClient(kwinClient).grid; client.stateManager.setState(() => new ClientState.Tiled(this.world, client, grid), false); } @@ -147,8 +150,11 @@ class ClientManager { const clientState = client.stateManager.getState(); if ((clientState instanceof ClientState.Floating || clientState instanceof ClientState.Pinned) && Clients.canTileEver(kwinClient)) { Clients.makeTileable(kwinClient); - const grid = this.desktopManager.getDesktopForClient(kwinClient).grid; - client.stateManager.setState(() => new ClientState.Tiled(this.world, client, grid), false); + const desktop = this.desktopManager.getDesktopForClient(kwinClient); + if (desktop === undefined) { + return; + } + client.stateManager.setState(() => new ClientState.Tiled(this.world, client, desktop.grid), false); } else if (clientState instanceof ClientState.Tiled) { client.stateManager.setState(() => new ClientState.Floating(this.world, client, this.config, true), false); } diff --git a/src/world/DesktopManager.ts b/src/world/DesktopManager.ts index f57d103..dd4f3c2 100644 --- a/src/world/DesktopManager.ts +++ b/src/world/DesktopManager.ts @@ -39,7 +39,9 @@ class DesktopManager { } public getDesktopForClient(kwinClient: KwinClient) { - console.assert(kwinClient.activities.length === 1 && kwinClient.desktop > 0); + if (kwinClient.activities.length !== 1 && kwinClient.desktop === 0) { + return undefined; + } return this.getDesktop(kwinClient.activities[0], kwinClient.desktop); } diff --git a/src/world/clientState/Tiled.ts b/src/world/clientState/Tiled.ts index ffd0b31..5a04067 100644 --- a/src/world/clientState/Tiled.ts +++ b/src/world/clientState/Tiled.ts @@ -33,23 +33,25 @@ namespace ClientState { manager.connect(kwinClient.desktopChanged, () => { world.do((clientManager, desktopManager) => { - if (kwinClient.desktop === -1) { + const desktop = desktopManager.getDesktopForClient(kwinClient); + if (desktop === undefined) { // windows on all desktops are not supported clientManager.untileClient(kwinClient); return; } - Tiled.moveWindowToCorrectGrid(desktopManager, window); + Tiled.moveWindowToGrid(window, desktop.grid); }); }); manager.connect(kwinClient.activitiesChanged, () => { world.do((clientManager, desktopManager) => { - if (kwinClient.activities.length !== 1) { + const desktop = desktopManager.getDesktopForClient(kwinClient); + if (desktop === undefined) { // windows on multiple activities are not supported clientManager.untileClient(kwinClient); return; } - Tiled.moveWindowToCorrectGrid(desktopManager, window); + Tiled.moveWindowToGrid(window, desktop.grid); }); }) @@ -130,17 +132,13 @@ namespace ClientState { return manager; } - private static moveWindowToCorrectGrid(desktopManager: DesktopManager, window: Window) { - const kwinClient = window.client.kwinClient; - - const oldGrid = window.column.grid; - const newGrid = desktopManager.getDesktopForClient(kwinClient).grid; - if (oldGrid === newGrid) { - // window already on the correct grid + private static moveWindowToGrid(window: Window, grid: Grid) { + if (grid === window.column.grid) { + // window already on the given grid return; } - const newColumn = new Column(newGrid, newGrid.getLastFocusedColumn() ?? newGrid.getLastColumn()); + const newColumn = new Column(grid, grid.getLastFocusedColumn() ?? grid.getLastColumn()); window.moveToColumn(newColumn); }