workspace.windowAdded.connect((w: Window) => {
const root = workspace.tilingForScreen(workspace.activeScreen).rootTile;
if (["krunner", "yakuake", "kded", "polkit", "plasmashell"].includes(w.resourceName)) return;
if (!w.normalWindow || w.transient || w.resourceClass == "") return;
if (root.tiles.length == 0 && root.windows.length == 0) {
w.tile = root;
root.layoutDirection = LayoutDirection.Horizontal;
selectedWindow.it = w;
return;
}
let t = selectedWindow.it?.tile;
if (t == null) return;
t.split(t.layoutDirection);
t = selectedWindow.it?.tile!;
const p = t.parent!;
t = p.tiles[mod(get_tile_index(t) + 1, p.tiles.length)];
w.tile = t;
selectedWindow.it = w;
});