This repository has been archived by the owner on Jun 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
util.ts
138 lines (128 loc) · 4.59 KB
/
util.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// config options
let debug: boolean;
let useWhitelist: boolean;
let blacklist: Array<string>;
let tilePopups: boolean;
let borders: number;
let invertInsertion: boolean;
let insertMethod: number;
let keepTiledBelow: boolean;
let keepFullscreenAbove: boolean;
// caches of stuff to make operations faster
let blacklistCache: Set<string>;
// is x11
function checkIfX11() {
let re = new RegExp("Operation Mode: (\\w*)");
// assume that the operation mode is outputted correctly
let opMode = re.exec(workspace.supportInformation())![1];
print(opMode);
switch (opMode) {
case "XWayland": return false;
case "Wayland": return false;
case "X11": return true;
}
return false;
}
let isX11: boolean = checkIfX11();
let updateConfig = function() {
debug = readConfig("Debug", false);
useWhitelist = readConfig("UseWhitelist", false);
blacklist = readConfig("Blacklist", "krunner, yakuake, kded, polkit").split(',').map((x: string) => x.trim());
tilePopups = readConfig("TilePopups", false);
borders = readConfig("Borders", 1);
invertInsertion = readConfig("InvertInsertion", true);
insertMethod = readConfig("InsertMethod", 0);
keepTiledBelow = readConfig("KeepTiledBelow", true);
keepFullscreenAbove = readConfig("KeepFullscreenAbove", true);
blacklistCache = new Set();
printDebug("Config Updated", false)
printDebug("Running on " + (isX11 ? "X11" : "Wayland"), false);
printDebug("useWhitelist == " + useWhitelist, false);
printDebug("blacklist == " + blacklist, false);
printDebug("tilePopups == " + tilePopups, false);
printDebug("borders == " + borders, false);
printDebug("invertInsertion == " + invertInsertion, false);
printDebug("insertMethod == " + insertMethod, false);
printDebug("keepTiledBelow == " + keepTiledBelow, false);
printDebug("keepFullscreenAbove == " + keepFullscreenAbove, false);
}
updateConfig();
options.configChanged.connect(updateConfig);
function printDebug(str: string, isError: boolean) {
if (isError) {
print("Autotile ERR: " + str);
} else if (debug) {
print("Autotile DBG: " + str);
}
}
// whether to ignore a client or not
function doTileClient(client: KWin.AbstractClient): boolean {
// if the client is not movable, dont bother
if (client.fullScreen || !client.moveable || !client.resizeable) {
return false;
}
// check if client is a popup window or transient (placeholder window)
if ((client.popupWindow || client.transient) && !tilePopups) {
return false;
}
// check if client is a dock or something
if (client.specialWindow) {
return false;
}
let c = client.resourceClass.toString();
// check if client is in blacklist cache (to save time)
if (blacklistCache.has(c)) {
return useWhitelist;
}
// check if client is black/whitelisted
for (const i of blacklist) {
if (c.includes(i) || i.includes(c)) {
blacklistCache.add(c);
return useWhitelist;
}
}
return !useWhitelist;
}
// simple structured clone polyfill
function structuredClone<T>(value: T): T {
return JSON.parse(JSON.stringify(value));
}
// gets windows by key because tiles share windows across several desktops and activities
function windowsOnKey(tile: KWin.Tile, key: KWin.TileMapKey, exclude?: KWin.AbstractClient): Array<KWin.AbstractClient> {
let ret: Array<KWin.AbstractClient> = [];
// ik the if loop can go inside but this may be more performant
if (exclude == undefined) {
for (const w of tile.windows) {
if ((w.desktop == key.desktop || w.desktop == -1) && w.activities.includes(key.activity) && w.screen == key.screen) {
ret.push(w);
}
}
} else {
for (const w of tile.windows) {
if ((w.desktop == key.desktop || w.desktop == -1) && w.activities.includes(key.activity) && w.screen == key.screen && w != exclude) {
ret.push(w);
}
}
}
return ret;
}
function calculatePaddedGeometry(rect: Qt.QRect, padding: number): Qt.QRect {
let ret = structuredClone(rect);
print(ret);
ret.x += padding;
ret.y += padding;
ret.width -= (padding*2);
ret.height -= (padding*2);
return ret;
}
function clientToKeys(client: KWin.AbstractClient): Array<KWin.TileMapKey> {
let ret = new Array<KWin.TileMapKey>;
for (const a of client.activities) {
let key = new KWin.TileMapKey;
key.activity = a;
key.desktop = client.desktop;
key.screen = client.screen;
ret.push(key)
}
return ret;
}