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