Skip to content

Commit

Permalink
[skip ci] literally finished
Browse files Browse the repository at this point in the history
  • Loading branch information
zeroxoneafour committed Feb 24, 2024
1 parent 999e7aa commit e5f8f86
Show file tree
Hide file tree
Showing 17 changed files with 428 additions and 498 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"esbuild": "^0.19.4",
"eslint": "^8.51.0",
"fast-copy": "^3.0.1",
"kwin-api": "^6.0.5",
"kwin-api": "^6.0.7",
"mnemonist": "^0.39.5",
"prettier": "3.2.5",
"typescript": "^5.2.2"
Expand Down
164 changes: 92 additions & 72 deletions src/controller/actions/basic.ts
Original file line number Diff line number Diff line change
@@ -1,91 +1,111 @@
// actions/basic.ts - Basic actions performed by the window manager, such as adding or deleting clients

import * as Kwin from "kwin-api";
import { Window } from "kwin-api";
import { Controller } from "../";
import Log from "../../util/log";
import Config, { Borders } from "../../util/config";
import { attachClientHooks } from "./clienthooks";
import { Log } from "../../util/log";
import { Config, Borders } from "../../util/config";
import { WindowExtensions } from "../extensions";

function doTileWindow(c: Kwin.Window): boolean {
if (
c.normalWindow &&
!((c.popupWindow || c.transient) && !Config.tilePopups)
) {
// check for things like max/min/fullscreen
if (c.fullScreen || c.minimized) {
return false;
}
// check if caption/resourceclass is substring as well
for (const s of Config.filterProcess) {
if (s.length > 0 && c.resourceClass.includes(s)) {
export class WorkspaceActions {
private logger: Log;
private config: Config;
private ctrl: Controller;
constructor(ctrl: Controller) {
this.logger = ctrl.logger;
this.config = ctrl.config;
this.ctrl = ctrl;

const workspace = this.ctrl.workspace;
workspace.windowAdded.connect(this.windowAdded);
workspace.windowRemoved.connect(this.windowRemoved);
workspace.currentActivityChanged.connect(this.currentDesktopChange);
workspace.currentDesktopChanged.connect(this.currentDesktopChange);
workspace.windowActivated.connect(this.windowActivated);
}

doTileWindow(c: Window): boolean {
if (
c.normalWindow &&
!((c.popupWindow || c.transient) && !this.config.tilePopups)
) {
// check for things like max/min/fullscreen
if (c.fullScreen || c.minimized) {
return false;
}
}
for (const s of Config.filterCaption) {
if (s.length > 0 && c.caption.includes(s)) {
return false;
// check if caption/resourceclass is substring as well
for (const s of this.config.filterProcess) {
if (s.length > 0 && c.resourceClass.includes(s)) {
return false;
}
}
for (const s of this.config.filterCaption) {
if (s.length > 0 && c.caption.includes(s)) {
return false;
}
}
return true;
} else {
return false;
}
return true;
} else {
return false;
}
}

export function clientAdded(
this: Controller,
client: Kwin.Window,
) {
if (!doTileClient(client)) {
Log.debug("Not tiling client", client.resourceClass);
return;
}
if (Config.borders == Borders.NoAll) {
client.noBorder = true;
windowAdded(window: Window): void {
this.ctrl.windowExtensions.set(window, new WindowExtensions(window));
this.ctrl.windowHookManager.attachWindowHooks(window);
if (!this.doTileWindow(window)) {
this.logger.debug("Not tiling window", window.resourceClass);
return;
}
if (this.config.borders == Borders.NoAll) {
window.noBorder = true;
}
this.ctrl.driverManager.addWindow(window);
this.ctrl.driverManager.rebuildLayout();
}
attachClientHooks.bind(this)(client);
this.driverManager.addClient(client);
this.driverManager.rebuildLayout();
}

export function windowRemoved(this: Controller, window: Kwin.Window) {
this.driverManager.removeClient(window);
this.driverManager.rebuildLayout();
}
windowRemoved(window: Window): void {
this.ctrl.windowExtensions.delete(window);
this.ctrl.driverManager.removeWindow(window);
this.ctrl.driverManager.rebuildLayout();
}

export function currentDesktopChange(this: Controller) {
// have to set this because this function temp untiles all windows
this.driverManager.buildingLayout = true;
// set geometry for all clients manually to avoid resizing when tiles are deleted
for (const client of Array.from(this.workspace.clientList())) {
if (
client.tile != null &&
client.activities.includes(this.workspace.lastActivity!) &&
client.desktop == this.workspace.lastDesktop
) {
const tile = client.tile;
client.tile = null;
client.frameGeometry = tile.absoluteGeometry;
client.frameGeometry.width -= 2 * tile.padding;
client.frameGeometry.height -= 2 * tile.padding;
client.frameGeometry.x += tile.padding;
client.frameGeometry.y += tile.padding;
currentDesktopChange(): void {
// have to set this because this function temp untiles all windows
this.ctrl.driverManager.buildingLayout = true;
// set geometry for all clients manually to avoid resizing when tiles are deleted
for (const window of this.ctrl.workspace.windows) {
if (
window.tile != null &&
window.activities.includes(
this.ctrl.workspaceExtensions.lastActivity!,
) &&
window.desktops.includes(
this.ctrl.workspaceExtensions.lastDesktop,
)
) {
const tile = window.tile;
window.tile = null;
window.frameGeometry = tile.absoluteGeometry;
window.frameGeometry.width -= 2 * tile.padding;
window.frameGeometry.height -= 2 * tile.padding;
window.frameGeometry.x += tile.padding;
window.frameGeometry.y += tile.padding;
}
}
this.ctrl.driverManager.rebuildLayout();
}
this.workspace.lastActivity = this.workspace.currentActivity;
this.workspace.lastDesktop = this.workspace.currentDesktop;
this.driverManager.rebuildLayout();
}

export function clientActivated(this: Controller, client: Kwin.Client) {
if (Config.borders == Borders.Selected) {
client.noBorder = false;
if (
this.glob.lastActiveClient != null &&
this.glob.lastActiveClient.isTiled
) {
this.glob.lastActiveClient.noBorder = true;
windowActivated(window: Window) {
if (this.config.borders == Borders.Selected) {
window.noBorder = false;
if (
this.ctrl.workspaceExtensions.lastActiveWindow != null &&
this.ctrl.windowExtensions.get(
this.ctrl.workspaceExtensions.lastActiveWindow,
)!.isTiled
) {
this.ctrl.workspaceExtensions.lastActiveWindow.noBorder = true;
}
}
}
this.glob.lastActiveClient = client;
}
Loading

0 comments on commit e5f8f86

Please sign in to comment.