tests: make mocks more accurately mimic kwin behaviour

This commit is contained in:
Peter Fajdiga
2025-09-13 10:31:15 +02:00
parent 456bbf30b4
commit b1d6193e48
3 changed files with 12 additions and 4 deletions

View File

@@ -61,3 +61,10 @@ function getClientManager(world: World): ClientManager {
world.do((cm, dm) => clientManager = cm);
return clientManager!;
}
function activateRandomWindowOnDesktop(desktop: KwinDesktop) {
const windows = Workspace.windows.filter(w => w.desktops.includes(desktop));
if (windows.length > 0) {
Workspace.activeWindow = randomItem(windows);
}
}

View File

@@ -198,6 +198,10 @@ class MockKwinClient {
this.desktopsChanged.fire();
if (Workspace.activeWindow === this && !desktops.includes(Workspace.currentDesktop)) {
Workspace.activeWindow = null;
runMaybe(() => Workspace.activeWindow = null); // fired again for some reason
if (Workspace.activeWindow === null) {
activateRandomWindowOnDesktop(Workspace.currentDesktop);
}
};
}

View File

@@ -58,10 +58,7 @@ class MockWorkspace {
() => this.windowRemoved.fire(window),
);
if (window === this.activeWindow) {
const windows = this.windows.filter(w => w.desktops.includes(this.currentDesktop));
if (Workspace.activeWindow === null && windows.length > 0) {
Workspace.activeWindow = randomItem(windows);
}
activateRandomWindowOnDesktop(this.currentDesktop);
};
}