WindowRuleEnforcer.ts

This commit is contained in:
Peter Fajdiga
2023-02-25 23:59:47 +01:00
parent ae96af2d61
commit 20b2f8639e
5 changed files with 41 additions and 14 deletions

34
src/WindowRuleEnforcer.ts Normal file
View File

@@ -0,0 +1,34 @@
class WindowRuleEnforcer {
private preferFloating: ClientMatcher;
private preferTiling: ClientMatcher;
private workspaceSignalManager: SignalManager;
constructor(world: World, preferFloating: Map<string, RegExp>, preferTiling: Map<string, RegExp>) {
this.preferFloating = new ClientMatcher(preferFloating);
this.preferTiling = new ClientMatcher(preferTiling);
this.workspaceSignalManager = this.initWorkspaceSignalHandlers(world);
}
shouldTile(kwinClient: AbstractClient) {
return canTile(kwinClient) && (
this.preferTiling.matches(kwinClient) ||
kwinClient.normalWindow && kwinClient.managed && !this.preferFloating.matches(kwinClient)
);
}
initWorkspaceSignalHandlers(world: World) {
const manager = new SignalManager();
manager.connect(workspace.clientAdded, (kwinClient: AbstractClient) => {
if (this.shouldTile(kwinClient)) {
world.addClient(kwinClient);
}
});
return manager;
}
destroy() {
this.workspaceSignalManager.disconnect();
}
}

View File

@@ -4,6 +4,7 @@ class World {
public minimizedTiled: Set<AbstractClient>; // TODO: implement using `clientMap`
private lastFocusedClient: AbstractClient|null;
private workspaceSignalManager: SignalManager;
private windowRuleEnforcer: WindowRuleEnforcer;
private screenResizedDelayer: Delayer;
constructor() {
@@ -12,6 +13,7 @@ class World {
this.minimizedTiled = new Set();
this.lastFocusedClient = null;
this.workspaceSignalManager = initWorkspaceSignalHandlers(this);
this.windowRuleEnforcer = new WindowRuleEnforcer(this, PREFER_FLOATING, PREFER_TILING);
this.screenResizedDelayer = new Delayer(1000, () => {
// this delay ensures that docks get taken into account by `workspace.clientArea`
const grids = this.grids; // workaround for bug in Qt5's JS engine
@@ -141,6 +143,7 @@ class World {
destroy() {
this.workspaceSignalManager.disconnect();
this.windowRuleEnforcer.destroy();
this.removeAllClients();
for (const grid of this.grids) {
grid.destroy();

View File

@@ -326,10 +326,3 @@ function canTile(kwinClient: AbstractClient) {
// TODO: support windows on all desktops
return kwinClient.resizeable && !kwinClient.minimized && kwinClient.desktop > 0;
}
function shouldTile(kwinClient: AbstractClient) {
return canTile(kwinClient) && (
PREFER_TILING.matches(kwinClient) ||
kwinClient.normalWindow && kwinClient.managed && !PREFER_FLOATING.matches(kwinClient)
);
}

View File

@@ -3,14 +3,14 @@ const GAPS_INNER = { x: 12, y: 12 };
const AUTO_OVERSCROLL_X = 12;
const GRID_SCROLL_STEP = 200;
const STACKED_BY_DEFAULT = false;
const PREFER_FLOATING = new ClientMatcher(new Map(Object.entries({
const PREFER_FLOATING = new Map(Object.entries({
"ksmserver-logout-greeter": new RegExp(""),
"kcalc": new RegExp(""),
"kruler": new RegExp(""),
"zoom": new RegExp("^(Zoom Cloud Meetings|zoom)$"),
"jetbrains-idea": new RegExp("^splash$"),
})));
const PREFER_TILING = new ClientMatcher(new Map(Object.entries({
}));
const PREFER_TILING = new Map(Object.entries({
"kfind": new RegExp(""),
"jetbrains-idea": new RegExp("^(Unstash Changes|Paths Affected by stash@.*)$"),
})));
}));

View File

@@ -33,9 +33,6 @@ function initWorkspaceSignalHandlers(world: World) {
world.onScreenResized();
return;
}
if (shouldTile(kwinClient)) {
world.addClient(kwinClient);
}
});
manager.connect(workspace.clientRemoved, (kwinClient: AbstractClient) => {