Compare commits
89 Commits
v0.7.2
...
per-screen
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aec5750dc0 | ||
|
|
6784259c12 | ||
|
|
23186bbe91 | ||
|
|
d7df3901e2 | ||
|
|
b85c86e7db | ||
|
|
fdb4b88333 | ||
|
|
4e3d924366 | ||
|
|
3d3e8cff17 | ||
|
|
a79229da75 | ||
|
|
53d04c1d33 | ||
|
|
a18ff61d9e | ||
|
|
99ffad9223 | ||
|
|
e776df509b | ||
|
|
63de2d4cae | ||
|
|
85d361f16f | ||
|
|
f3b75807be | ||
|
|
88bce26456 | ||
|
|
3a75ddab0f | ||
|
|
ee0aa93308 | ||
|
|
33ca138420 | ||
|
|
79f4aaeef8 | ||
|
|
0aca6e1146 | ||
|
|
28e54434aa | ||
|
|
ee14509228 | ||
|
|
1596edc43f | ||
|
|
b897ab5b9f | ||
|
|
5e6dad8459 | ||
|
|
beeba74442 | ||
|
|
3e14440180 | ||
|
|
36836ad258 | ||
|
|
bebc009cc6 | ||
|
|
a4ba8516dc | ||
|
|
675a70d907 | ||
|
|
3ba66f1c89 | ||
|
|
4556198b2e | ||
|
|
7b8de5955d | ||
|
|
68a687b7d4 | ||
|
|
20a3ece4b5 | ||
|
|
3cad8102ee | ||
|
|
7fd45eed8f | ||
|
|
7299341608 | ||
|
|
842ec1ac63 | ||
|
|
0523465b84 | ||
|
|
c7cfa261b9 | ||
|
|
56955e4df3 | ||
|
|
bb308cfbfb | ||
|
|
6c00245943 | ||
|
|
2efdbe5a7b | ||
|
|
092cbf3ff1 | ||
|
|
f9ae299ce8 | ||
|
|
695f5edf6a | ||
|
|
9b80b535a1 | ||
|
|
752df86db5 | ||
|
|
f05eefe19b | ||
|
|
f550285778 | ||
|
|
5247a6a0d3 | ||
|
|
2b114a63dc | ||
|
|
63e4015f3a | ||
|
|
02db31266b | ||
|
|
67d4d89700 | ||
|
|
755cf90b1a | ||
|
|
e6a01217a5 | ||
|
|
21d7bbd6c4 | ||
|
|
605215acdc | ||
|
|
4b6808dba1 | ||
|
|
f9749c6f56 | ||
|
|
9b40b2f777 | ||
|
|
33470b4d7b | ||
|
|
8947719621 | ||
|
|
4bf4f8e8a1 | ||
|
|
080de7cf97 | ||
|
|
c29902dc15 | ||
|
|
1736b0a398 | ||
|
|
a1c44647ca | ||
|
|
0ea75d6348 | ||
|
|
12901e45ce | ||
|
|
29b4ccd1dd | ||
|
|
7b547bc5b8 | ||
|
|
78a127111b | ||
|
|
333b7601b2 | ||
|
|
1927ae445d | ||
|
|
1f563dae01 | ||
|
|
6b82eedbfe | ||
|
|
b479735130 | ||
|
|
c8f022d66f | ||
|
|
7f71750a8e | ||
|
|
13ebf24732 | ||
|
|
ec6b3247b7 | ||
|
|
50681d3a07 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,4 +1,5 @@
|
||||
/package/contents/code/main.js
|
||||
/package/contents/config/main.xml
|
||||
/karousel*.tar.gz
|
||||
run-ts-tmp.js
|
||||
/.idea
|
||||
|
||||
27
Makefile
27
Makefile
@@ -1,32 +1,29 @@
|
||||
.PHONY: *
|
||||
|
||||
TSC_SCRIPT_FLAGS = --lib es2020 ./src/extern/qt.d.ts
|
||||
VERSION = $(shell grep '"Version":' ./package/metadata.json | grep -o '[0-9\.]*')
|
||||
|
||||
config:
|
||||
build: tests
|
||||
tsc -p ./src/main --outFile ./package/contents/code/main.js
|
||||
mkdir -p ./package/contents/config
|
||||
tsc ${TSC_SCRIPT_FLAGS} ./src/config/definition.ts ./generators/config/kcfg.ts --outFile /dev/stdout | node - > ./package/contents/config/main.xml
|
||||
./run-ts.sh ./src/generators/config > ./package/contents/config/main.xml
|
||||
|
||||
build:
|
||||
tsc --outFile ./package/contents/code/main.js
|
||||
tests:
|
||||
./run-ts.sh ./src/tests
|
||||
|
||||
install: build config
|
||||
kpackagetool5 --type=KWin/Script -i ./package || kpackagetool5 --type=KWin/Script -u ./package
|
||||
install: build
|
||||
kpackagetool6 --type=KWin/Script -i ./package || kpackagetool6 --type=KWin/Script -u ./package
|
||||
|
||||
uninstall:
|
||||
kpackagetool5 --type=KWin/Script -r ./package
|
||||
kpackagetool6 --type=KWin/Script -r karousel
|
||||
|
||||
package: build config
|
||||
package: build
|
||||
tar -czf ./karousel_${subst .,_,${VERSION}}.tar.gz ./package
|
||||
|
||||
logs:
|
||||
journalctl -t kwin_x11 -g '^qml:|^file://.*karousel' -f
|
||||
|
||||
docs-key-bindings-bbcode:
|
||||
@tsc ${TSC_SCRIPT_FLAGS} ./src/keyBindings/definition.ts ./generators/docs/keyBindings.ts ./generators/docs/keyBindingsBbcode.ts --outFile /dev/stdout | node -
|
||||
@./run-ts.sh ./src/generators/docs/keyBindingsBbcode
|
||||
|
||||
docs-key-bindings-table:
|
||||
@tsc ${TSC_SCRIPT_FLAGS} ./src/keyBindings/definition.ts ./generators/docs/keyBindings.ts ./generators/docs/keyBindingsTable.ts --outFile /dev/stdout | node -
|
||||
@./run-ts.sh ./src/generators/docs/keyBindingsTable
|
||||
|
||||
docs-key-bindings-fmt:
|
||||
@tsc ${TSC_SCRIPT_FLAGS} ./src/keyBindings/definition.ts ./generators/docs/keyBindings.ts ./generators/docs/keyBindingsFmt.ts --outFile /dev/stdout | node -
|
||||
@./run-ts.sh ./src/generators/docs/keyBindingsFmt
|
||||
|
||||
@@ -19,7 +19,7 @@ Similar window managers include [PaperWM](https://github.com/paperwm/PaperWM),
|
||||
|
||||
## Dependencies
|
||||
Karousel requires the following QML modules:
|
||||
- QtQuick 2.15
|
||||
- QtQuick 6.0
|
||||
- org.kde.kwin 3.0
|
||||
- org.kde.notification 1.0
|
||||
|
||||
|
||||
@@ -121,6 +121,13 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="kcfg_noLayering">
|
||||
<property name="text">
|
||||
<string>No layering</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import QtQuick 2.15
|
||||
import QtQuick 6.0
|
||||
import org.kde.kwin 3.0
|
||||
import org.kde.notification 1.0
|
||||
import "./main.js" as Karousel
|
||||
import "../code/main.js" as Karousel
|
||||
|
||||
Item {
|
||||
id: qmlBase
|
||||
@@ -1,4 +1,5 @@
|
||||
{
|
||||
"KPackageStructure": "KWin/Script",
|
||||
"KPlugin": {
|
||||
"Name": "Karousel",
|
||||
"Description": "Scrollable tiling extension for KWin",
|
||||
@@ -8,13 +9,13 @@
|
||||
"Name": "Peter Fajdiga"
|
||||
}],
|
||||
"Id": "karousel",
|
||||
"ServiceTypes": ["KWin/Script"],
|
||||
"Version": "0.7.1",
|
||||
"Version": "0.9.3",
|
||||
"License": "GPLv3",
|
||||
"Website": "https://github.com/peterfajdiga/karousel",
|
||||
"BugReportUrl": "https://github.com/peterfajdiga/karousel/issues"
|
||||
},
|
||||
"X-Plasma-API": "declarativescript",
|
||||
"X-Plasma-MainScript": "code/main.qml",
|
||||
"X-Plasma-API-Minimum-Version": "6.0",
|
||||
"X-Plasma-MainScript": "ui/main.qml",
|
||||
"X-KDE-ConfigModule": "kwin/effects/configs/kcm_kwin4_genericscripted"
|
||||
}
|
||||
|
||||
2
run-ts.sh
Executable file
2
run-ts.sh
Executable file
@@ -0,0 +1,2 @@
|
||||
#!/bin/bash
|
||||
tsc -p "$1" --outFile ./run-ts-tmp.js && node ./run-ts-tmp.js && rm ./run-ts-tmp.js
|
||||
6
src/extern/global.d.ts
vendored
6
src/extern/global.d.ts
vendored
@@ -1,6 +0,0 @@
|
||||
declare const qmlBase: QmlObject;
|
||||
declare const notificationInvalidWindowRules: Notification;
|
||||
|
||||
type Notification = {
|
||||
sendEvent(): void;
|
||||
};
|
||||
79
src/extern/kwin.d.ts
vendored
79
src/extern/kwin.d.ts
vendored
@@ -1,79 +0,0 @@
|
||||
declare const KWin: {
|
||||
readConfig(key: string, defaultValue: any): any;
|
||||
registerShortcut(name: string, description: string, keySequence: string, callback: () => void): void;
|
||||
};
|
||||
|
||||
declare const workspace: {
|
||||
readonly desktops: number;
|
||||
readonly currentDesktop: number;
|
||||
readonly currentActivity: string;
|
||||
|
||||
activeClient: KwinClient;
|
||||
|
||||
readonly currentDesktopChanged: QSignal<[]>
|
||||
readonly clientAdded: QSignal<[KwinClient]>;
|
||||
readonly clientRemoved: QSignal<[KwinClient]>;
|
||||
readonly clientMinimized: QSignal<[KwinClient]>;
|
||||
readonly clientUnminimized: QSignal<[KwinClient]>;
|
||||
readonly clientMaximizeSet: QSignal<[KwinClient, horizontally: boolean, vertically: boolean]>;
|
||||
readonly clientActivated: QSignal<[KwinClient]>;
|
||||
readonly numberDesktopsChanged: QSignal<[]>;
|
||||
readonly currentActivityChanged: QSignal<[]>;
|
||||
readonly virtualScreenSizeChanged: QSignal<[]>;
|
||||
|
||||
clientArea(option: ClientAreaOption, screenNumber: number, desktopNumber: number);
|
||||
clientList(): KwinClient[];
|
||||
};
|
||||
|
||||
const enum ClientAreaOption {
|
||||
PlacementArea,
|
||||
MovementArea,
|
||||
MaximizeArea,
|
||||
MaximizeFullArea,
|
||||
FullScreenArea,
|
||||
WorkArea,
|
||||
FullArea,
|
||||
ScreenArea,
|
||||
}
|
||||
|
||||
type Tile = unknown;
|
||||
|
||||
interface KwinClient {
|
||||
readonly shadeable: boolean;
|
||||
readonly caption: string;
|
||||
readonly minSize: QmlSize;
|
||||
readonly transient: boolean;
|
||||
readonly transientFor: KwinClient;
|
||||
readonly move: boolean;
|
||||
readonly resize: boolean;
|
||||
readonly resizeable: boolean;
|
||||
readonly screen: number;
|
||||
readonly resourceClass: QByteArray;
|
||||
readonly dock: boolean;
|
||||
readonly normalWindow: boolean;
|
||||
readonly managed: boolean;
|
||||
|
||||
opacity: number;
|
||||
fullScreen: boolean;
|
||||
activities: string[]; // empty array means all activities
|
||||
skipSwitcher: boolean;
|
||||
keepAbove: boolean;
|
||||
keepBelow: boolean;
|
||||
shade: boolean;
|
||||
minimized: boolean;
|
||||
frameGeometry: QmlRect;
|
||||
desktop: number; // -1 means all desktops
|
||||
tile: Tile;
|
||||
|
||||
readonly fullScreenChanged: QSignal<[]>;
|
||||
readonly desktopChanged: QSignal<[]>;
|
||||
readonly activitiesChanged: QSignal<[]>;
|
||||
readonly captionChanged: QSignal<[]>;
|
||||
readonly tileChanged: QSignal<[]>;
|
||||
readonly moveResizedChanged: QSignal<[]>;
|
||||
readonly moveResizeCursorChanged: QSignal<[]>;
|
||||
readonly clientStartUserMovedResized: QSignal<[]>;
|
||||
readonly frameGeometryChanged: QSignal<[KwinClient, oldGeometry: QmlRect]>;
|
||||
|
||||
setMaximize(vertically: boolean, horizontally: boolean): void;
|
||||
}
|
||||
4
src/generators/config/tsconfig.json
Normal file
4
src/generators/config/tsconfig.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"include": ["../../lib/**/*", "./**/*"]
|
||||
}
|
||||
@@ -1,20 +1,3 @@
|
||||
type KeyBinding = {
|
||||
name: string;
|
||||
description: string;
|
||||
comment?: string;
|
||||
defaultKeySequence: string;
|
||||
action: string;
|
||||
}
|
||||
|
||||
type NumKeyBinding = {
|
||||
name: string;
|
||||
description: string;
|
||||
comment?: string;
|
||||
defaultModifiers: string;
|
||||
fKeys: boolean;
|
||||
action: string;
|
||||
}
|
||||
|
||||
function formatComment(comment: string | undefined) {
|
||||
return comment === undefined ? "" : ` (${comment})`;
|
||||
}
|
||||
8
src/generators/docs/keyBindingsBbcode/tsconfig.json
Normal file
8
src/generators/docs/keyBindingsBbcode/tsconfig.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": "../../../tsconfig.json",
|
||||
"include": [
|
||||
"../../../lib/**/*",
|
||||
"../keyBindings.ts",
|
||||
"./**/*"
|
||||
]
|
||||
}
|
||||
8
src/generators/docs/keyBindingsFmt/tsconfig.json
Normal file
8
src/generators/docs/keyBindingsFmt/tsconfig.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": "../../../tsconfig.json",
|
||||
"include": [
|
||||
"../../../lib/**/*",
|
||||
"../keyBindings.ts",
|
||||
"./**/*"
|
||||
]
|
||||
}
|
||||
8
src/generators/docs/keyBindingsTable/tsconfig.json
Normal file
8
src/generators/docs/keyBindingsTable/tsconfig.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": "../../../tsconfig.json",
|
||||
"include": [
|
||||
"../../../lib/**/*",
|
||||
"../keyBindings.ts",
|
||||
"./**/*"
|
||||
]
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
type KeyBinding = {
|
||||
name: string;
|
||||
description: string;
|
||||
comment?: string;
|
||||
defaultKeySequence: string;
|
||||
action: keyof ReturnType<typeof Actions.init>;
|
||||
};
|
||||
|
||||
type NumKeyBinding = {
|
||||
name: string;
|
||||
description: string;
|
||||
comment?: string;
|
||||
defaultModifiers: string;
|
||||
fKeys: boolean;
|
||||
action: keyof ReturnType<typeof Actions.initNum>;
|
||||
};
|
||||
|
||||
function catchWrap(f: () => void) {
|
||||
return () => {
|
||||
try {
|
||||
f();
|
||||
} catch (error: any) {
|
||||
log(error);
|
||||
log(error.stack);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function registerKeyBinding(name: string, description: string, keySequence: string, callback: () => void) {
|
||||
KWin.registerShortcut(
|
||||
"karousel-" + name,
|
||||
"Karousel: " + description,
|
||||
keySequence,
|
||||
catchWrap(callback),
|
||||
);
|
||||
}
|
||||
|
||||
function registerNumKeyBindings(name: string, description: string, modifiers: string, fKeys: boolean, callback: (i: number) => void) {
|
||||
const numPrefix = fKeys ? "F" : "";
|
||||
const n = fKeys ? 12 : 9;
|
||||
for (let i = 0; i < 12; i++) {
|
||||
const numKey = String(i + 1);
|
||||
const keySequence = i < n ?
|
||||
modifiers + "+" + numPrefix + numKey :
|
||||
"";
|
||||
registerKeyBinding(
|
||||
name + numKey,
|
||||
description + numKey,
|
||||
keySequence,
|
||||
() => callback(i),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function registerKeyBindings(world: World, config: Config) {
|
||||
const actions = Actions.init(world, {
|
||||
manualScrollStep: config.manualScrollStep,
|
||||
manualResizeStep: config.manualResizeStep,
|
||||
columnResizer: config.scrollingCentered ? new RawResizer() : new ContextualResizer(),
|
||||
});
|
||||
|
||||
for (const binding of keyBindings) {
|
||||
registerKeyBinding(binding.name, binding.description, binding.defaultKeySequence, actions[binding.action]);
|
||||
}
|
||||
|
||||
const numActions = Actions.initNum(world);
|
||||
for (const binding of numKeyBindings) {
|
||||
registerNumKeyBindings(binding.name, binding.description, binding.defaultModifiers, binding.fKeys, numActions[binding.action]);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
namespace Actions {
|
||||
export function init(world: World, config: Config) {
|
||||
return {
|
||||
focusLeft: () => {
|
||||
export function getAction(world: World, config: Config, name: string) {
|
||||
switch (name) {
|
||||
case "focus-left": return () => {
|
||||
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => {
|
||||
const prevColumn = grid.getPrevColumn(column);
|
||||
if (prevColumn === null) {
|
||||
@@ -9,9 +9,9 @@ namespace Actions {
|
||||
}
|
||||
prevColumn.focus();
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
focusRight: () => {
|
||||
case "focus-right": return () => {
|
||||
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => {
|
||||
const nextColumn = grid.getNextColumn(column);
|
||||
if (nextColumn === null) {
|
||||
@@ -19,9 +19,9 @@ namespace Actions {
|
||||
}
|
||||
nextColumn.focus();
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
focusUp: () => {
|
||||
case "focus-up": return () => {
|
||||
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => {
|
||||
const prevWindow = column.getPrevWindow(window);
|
||||
if (prevWindow === null) {
|
||||
@@ -29,9 +29,9 @@ namespace Actions {
|
||||
}
|
||||
prevWindow.focus();
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
focusDown: () => {
|
||||
case "focus-down": return () => {
|
||||
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => {
|
||||
const nextWindow = column.getNextWindow(window);
|
||||
if (nextWindow === null) {
|
||||
@@ -39,9 +39,9 @@ namespace Actions {
|
||||
}
|
||||
nextWindow.focus();
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
focusStart: () => {
|
||||
case "focus-start": return () => {
|
||||
world.do((clientManager, desktopManager) => {
|
||||
const grid = desktopManager.getCurrentDesktop().grid;
|
||||
const firstColumn = grid.getFirstColumn();
|
||||
@@ -50,9 +50,9 @@ namespace Actions {
|
||||
}
|
||||
firstColumn.focus();
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
focusEnd: () => {
|
||||
case "focus-end": return () => {
|
||||
world.do((clientManager, desktopManager) => {
|
||||
const grid = desktopManager.getCurrentDesktop().grid;
|
||||
const lastColumn = grid.getLastColumn();
|
||||
@@ -61,9 +61,9 @@ namespace Actions {
|
||||
}
|
||||
lastColumn.focus();
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
windowMoveLeft: () => {
|
||||
case "window-move-left": return () => {
|
||||
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => {
|
||||
if (column.getWindowCount() === 1) {
|
||||
// move from own column into existing column
|
||||
@@ -79,9 +79,9 @@ namespace Actions {
|
||||
window.moveToColumn(newColumn);
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
windowMoveRight: () => {
|
||||
case "window-move-right": return () => {
|
||||
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => {
|
||||
if (column.getWindowCount() === 1) {
|
||||
// move from own column into existing column
|
||||
@@ -97,100 +97,100 @@ namespace Actions {
|
||||
window.moveToColumn(newColumn);
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
windowMoveUp: () => {
|
||||
case "window-move-up": return () => {
|
||||
// TODO (optimization): only arrange moved windows
|
||||
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => {
|
||||
column.moveWindowUp(window);
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
windowMoveDown: () => {
|
||||
case "window-move-down": return () => {
|
||||
// TODO (optimization): only arrange moved windows
|
||||
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => {
|
||||
column.moveWindowDown(window);
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
windowMoveStart: () => {
|
||||
case "window-move-start": return () => {
|
||||
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => {
|
||||
const newColumn = new Column(grid, null);
|
||||
window.moveToColumn(newColumn);
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
windowMoveEnd: () => {
|
||||
case "window-move-end": return () => {
|
||||
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => {
|
||||
const newColumn = new Column(grid, grid.getLastColumn());
|
||||
window.moveToColumn(newColumn);
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
windowToggleFloating: () => {
|
||||
const kwinClient = workspace.activeClient;
|
||||
case "window-toggle-floating": return () => {
|
||||
const kwinClient = Workspace.activeWindow;
|
||||
world.do((clientManager, desktopManager) => {
|
||||
clientManager.toggleFloatingClient(kwinClient);
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
columnMoveLeft: () => {
|
||||
case "column-move-left": return () => {
|
||||
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => {
|
||||
grid.moveColumnLeft(column);
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
columnMoveRight: () => {
|
||||
case "column-move-right": return () => {
|
||||
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => {
|
||||
grid.moveColumnRight(column);
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
columnMoveStart: () => {
|
||||
case "column-move-start": return () => {
|
||||
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => {
|
||||
column.moveAfter(null);
|
||||
grid.moveColumn(column, null);
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
columnMoveEnd: () => {
|
||||
case "column-move-end": return () => {
|
||||
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => {
|
||||
column.moveAfter(grid.getLastColumn());
|
||||
grid.moveColumn(column, grid.getLastColumn());
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
columnToggleStacked: () => {
|
||||
case "column-toggle-stacked": return () => {
|
||||
world.doIfTiledFocused(false, (clientManager, desktopManager, window, column, grid) => {
|
||||
column.toggleStacked();
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
columnWidthIncrease: () => {
|
||||
case "column-width-increase": return () => {
|
||||
world.doIfTiledFocused(false, (clientManager, desktopManager, window, column, grid) => {
|
||||
config.columnResizer.increaseWidth(column, config.manualResizeStep);
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
columnWidthDecrease: () => {
|
||||
case "column-width-decrease": return () => {
|
||||
world.doIfTiledFocused(false, (clientManager, desktopManager, window, column, grid) => {
|
||||
config.columnResizer.decreaseWidth(column, config.manualResizeStep);
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
columnsWidthEqualize: () => {
|
||||
case "columns-width-equalize": return () => {
|
||||
world.do((clientManager, desktopManager) => {
|
||||
desktopManager.getCurrentDesktop().equalizeVisibleColumnsWidths();
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
gridScrollLeft: () => {
|
||||
case "grid-scroll-left": return () => {
|
||||
gridScroll(world, -config.manualScrollStep);
|
||||
},
|
||||
};
|
||||
|
||||
gridScrollRight: () => {
|
||||
case "grid-scroll-right": return () => {
|
||||
gridScroll(world, config.manualScrollStep);
|
||||
},
|
||||
};
|
||||
|
||||
gridScrollStart: () => {
|
||||
case "grid-scroll-start": return () => {
|
||||
world.do((clientManager, desktopManager) => {
|
||||
const grid = desktopManager.getCurrentDesktop().grid;
|
||||
const firstColumn = grid.getFirstColumn();
|
||||
@@ -199,9 +199,9 @@ namespace Actions {
|
||||
}
|
||||
grid.desktop.scrollToColumn(firstColumn);
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
gridScrollEnd: () => {
|
||||
case "grid-scroll-end": return () => {
|
||||
world.do((clientManager, desktopManager) => {
|
||||
const grid = desktopManager.getCurrentDesktop().grid;
|
||||
const lastColumn = grid.getLastColumn();
|
||||
@@ -210,15 +210,15 @@ namespace Actions {
|
||||
}
|
||||
grid.desktop.scrollToColumn(lastColumn);
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
gridScrollFocused: () => {
|
||||
case "grid-scroll-focused": return () => {
|
||||
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => {
|
||||
grid.desktop.scrollCenterRange(column);
|
||||
})
|
||||
},
|
||||
};
|
||||
|
||||
gridScrollLeftColumn: () => {
|
||||
case "grid-scroll-left-column": return () => {
|
||||
world.do((clientManager, desktopManager) => {
|
||||
const grid = desktopManager.getCurrentDesktop().grid;
|
||||
const column = grid.getLeftmostVisibleColumn(grid.desktop.getCurrentVisibleRange(), true);
|
||||
@@ -233,9 +233,9 @@ namespace Actions {
|
||||
|
||||
grid.desktop.scrollToColumn(prevColumn);
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
gridScrollRightColumn: () => {
|
||||
case "grid-scroll-right-column": return () => {
|
||||
world.do((clientManager, desktopManager) => {
|
||||
const grid = desktopManager.getCurrentDesktop().grid;
|
||||
const column = grid.getRightmostVisibleColumn(grid.desktop.getCurrentVisibleRange(), true);
|
||||
@@ -250,13 +250,15 @@ namespace Actions {
|
||||
|
||||
grid.desktop.scrollToColumn(nextColumn);
|
||||
});
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
default: throw new Error("unknown action: " + name);
|
||||
}
|
||||
}
|
||||
|
||||
export function initNum(world: World) {
|
||||
return {
|
||||
focusColumn: (columnIndex: number) => {
|
||||
export function getNumAction(world: World, name: string) {
|
||||
switch (name) {
|
||||
case "focus-": return (columnIndex: number) => {
|
||||
world.do((clientManager, desktopManager) => {
|
||||
const grid = desktopManager.getCurrentDesktop().grid;
|
||||
const targetColumn = grid.getColumnAtIndex(columnIndex);
|
||||
@@ -265,9 +267,9 @@ namespace Actions {
|
||||
}
|
||||
targetColumn.focus();
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
windowMoveToColumn: (columnIndex: number) => {
|
||||
case "window-move-to-column-": return (columnIndex: number) => {
|
||||
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => {
|
||||
const targetColumn = grid.getColumnAtIndex(columnIndex);
|
||||
if (targetColumn === null) {
|
||||
@@ -276,44 +278,52 @@ namespace Actions {
|
||||
window.moveToColumn(targetColumn);
|
||||
grid.desktop.autoAdjustScroll();
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
columnMoveToColumn: (columnIndex: number) => {
|
||||
case "column-move-to-column-": return (columnIndex: number) => {
|
||||
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => {
|
||||
const targetColumn = grid.getColumnAtIndex(columnIndex);
|
||||
if (targetColumn === null || targetColumn === column) {
|
||||
return;
|
||||
}
|
||||
if (targetColumn.isAfter(column)) {
|
||||
column.moveAfter(targetColumn);
|
||||
if (targetColumn.isToTheRightOf(column)) {
|
||||
grid.moveColumn(column, targetColumn);
|
||||
} else {
|
||||
column.moveAfter(grid.getPrevColumn(targetColumn));
|
||||
grid.moveColumn(column, grid.getPrevColumn(targetColumn));
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
columnMoveToDesktop: (desktopIndex: number) => {
|
||||
case "column-move-to-desktop-": return (desktopIndex: number) => {
|
||||
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, oldGrid) => {
|
||||
const desktopNumber = desktopIndex + 1;
|
||||
const newGrid = desktopManager.getDesktopInCurrentActivity(desktopNumber).grid;
|
||||
const kwinDesktop = Workspace.desktops[desktopIndex];
|
||||
if (kwinDesktop === undefined) {
|
||||
return;
|
||||
}
|
||||
const newGrid = desktopManager.getDesktopInCurrentActivity(kwinDesktop).grid;
|
||||
if (newGrid === null || newGrid === oldGrid) {
|
||||
return;
|
||||
}
|
||||
column.moveToGrid(newGrid, newGrid.getLastColumn());
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
tailMoveToDesktop: (desktopIndex: number) => {
|
||||
case "tail-move-to-desktop-": return (desktopIndex: number) => {
|
||||
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, oldGrid) => {
|
||||
const desktopNumber = desktopIndex + 1;
|
||||
const newGrid = desktopManager.getDesktopInCurrentActivity(desktopNumber).grid;
|
||||
const kwinDesktop = Workspace.desktops[desktopIndex];
|
||||
if (kwinDesktop === undefined) {
|
||||
return;
|
||||
}
|
||||
const newGrid = desktopManager.getDesktopInCurrentActivity(kwinDesktop).grid;
|
||||
if (newGrid === null || newGrid === oldGrid) {
|
||||
return;
|
||||
}
|
||||
oldGrid.evacuateTail(newGrid, column);
|
||||
});
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
default: throw new Error("unknown num action: " + name);
|
||||
}
|
||||
}
|
||||
|
||||
function gridScroll(world: World, amount: number) {
|
||||
@@ -4,43 +4,35 @@ const defaultWindowRules = `[
|
||||
"tile": false
|
||||
},
|
||||
{
|
||||
"class": "kcalc",
|
||||
"class": "xwaylandvideobridge",
|
||||
"tile": false
|
||||
},
|
||||
{
|
||||
"class": "org.kde.kcalc",
|
||||
"class": "(org\\\\.kde\\\\.)?plasmashell",
|
||||
"tile": false
|
||||
},
|
||||
{
|
||||
"class": "kfind",
|
||||
"class": "(org\\\\.kde\\\\.)?kded6",
|
||||
"tile": false
|
||||
},
|
||||
{
|
||||
"class": "(org\\\\.kde\\\\.)?kcalc",
|
||||
"tile": false
|
||||
},
|
||||
{
|
||||
"class": "(org\\\\.kde\\\\.)?kfind",
|
||||
"tile": true
|
||||
},
|
||||
{
|
||||
"class": "org.kde.kfind",
|
||||
"tile": true
|
||||
},
|
||||
{
|
||||
"class": "kruler",
|
||||
"class": "(org\\\\.kde\\\\.)?kruler",
|
||||
"tile": false
|
||||
},
|
||||
{
|
||||
"class": "org.kde.kruler",
|
||||
"class": "(org\\\\.kde\\\\.)?krunner",
|
||||
"tile": false
|
||||
},
|
||||
{
|
||||
"class": "krunner",
|
||||
"tile": false
|
||||
},
|
||||
{
|
||||
"class": "org.kde.krunner",
|
||||
"tile": false
|
||||
},
|
||||
{
|
||||
"class": "yakuake",
|
||||
"tile": false
|
||||
},
|
||||
{
|
||||
"class": "org.kde.yakuake",
|
||||
"class": "(org\\\\.kde\\\\.)?yakuake",
|
||||
"tile": false
|
||||
},
|
||||
{
|
||||
@@ -74,32 +66,32 @@ const configDef = [
|
||||
{
|
||||
name: "gapsOuterTop",
|
||||
type: "UInt",
|
||||
default: 18,
|
||||
default: 16,
|
||||
},
|
||||
{
|
||||
name: "gapsOuterBottom",
|
||||
type: "UInt",
|
||||
default: 18,
|
||||
default: 16,
|
||||
},
|
||||
{
|
||||
name: "gapsOuterLeft",
|
||||
type: "UInt",
|
||||
default: 18,
|
||||
default: 16,
|
||||
},
|
||||
{
|
||||
name: "gapsOuterRight",
|
||||
type: "UInt",
|
||||
default: 18,
|
||||
default: 16,
|
||||
},
|
||||
{
|
||||
name: "gapsInnerHorizontal",
|
||||
type: "UInt",
|
||||
default: 18,
|
||||
default: 8,
|
||||
},
|
||||
{
|
||||
name: "gapsInnerVertical",
|
||||
type: "UInt",
|
||||
default: 18,
|
||||
default: 8,
|
||||
},
|
||||
{
|
||||
name: "manualScrollStep",
|
||||
@@ -166,6 +158,11 @@ const configDef = [
|
||||
type: "Bool",
|
||||
default: false,
|
||||
},
|
||||
{
|
||||
name: "noLayering",
|
||||
type: "Bool",
|
||||
default: false,
|
||||
},
|
||||
{
|
||||
name: "windowRules",
|
||||
type: "String",
|
||||
6
src/lib/extern/global.d.ts
vendored
Normal file
6
src/lib/extern/global.d.ts
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
declare const console: Console;
|
||||
declare const Qt: Qt;
|
||||
declare const KWin: KWin;
|
||||
declare const Workspace: Workspace;
|
||||
declare const qmlBase: QmlObject;
|
||||
declare const notificationInvalidWindowRules: Notification;
|
||||
109
src/lib/extern/kwin.ts
vendored
Normal file
109
src/lib/extern/kwin.ts
vendored
Normal file
@@ -0,0 +1,109 @@
|
||||
type KWin = {
|
||||
readConfig(key: string, defaultValue: any): any;
|
||||
};
|
||||
|
||||
type Workspace = {
|
||||
readonly activities: string[];
|
||||
readonly desktops: KwinDesktop[];
|
||||
readonly currentDesktop: KwinDesktop;
|
||||
readonly currentActivity: string;
|
||||
readonly activeScreen: Output;
|
||||
readonly screens: Output[];
|
||||
readonly windows: KwinClient[];
|
||||
readonly cursorPos: Readonly<QmlPoint>;
|
||||
|
||||
activeWindow: KwinClient;
|
||||
|
||||
readonly currentDesktopChanged: QSignal<[]>
|
||||
readonly windowAdded: QSignal<[KwinClient]>;
|
||||
readonly windowRemoved: QSignal<[KwinClient]>;
|
||||
readonly windowActivated: QSignal<[KwinClient]>;
|
||||
readonly screensChanged: QSignal<[]>;
|
||||
readonly activitiesChanged: QSignal<[]>;
|
||||
readonly desktopsChanged: QSignal<[]>;
|
||||
readonly currentActivityChanged: QSignal<[]>;
|
||||
readonly virtualScreenSizeChanged: QSignal<[]>;
|
||||
|
||||
clientArea(option: ClientAreaOption, output: Output, kwinDesktop: KwinDesktop): QmlRect;
|
||||
};
|
||||
|
||||
const enum ClientAreaOption {
|
||||
PlacementArea,
|
||||
MovementArea,
|
||||
MaximizeArea,
|
||||
MaximizeFullArea,
|
||||
FullScreenArea,
|
||||
WorkArea,
|
||||
FullArea,
|
||||
ScreenArea,
|
||||
}
|
||||
|
||||
const enum MaximizedMode {
|
||||
Unmaximized,
|
||||
Vertically,
|
||||
Horizontally,
|
||||
Maximized,
|
||||
}
|
||||
|
||||
type Tile = unknown;
|
||||
|
||||
type Output = {
|
||||
name: string;
|
||||
};
|
||||
|
||||
interface KwinClient {
|
||||
readonly shadeable: boolean;
|
||||
readonly caption: string;
|
||||
readonly minSize: Readonly<QmlSize>;
|
||||
readonly transient: boolean;
|
||||
readonly transientFor: KwinClient;
|
||||
readonly clientGeometry: Readonly<QmlRect>;
|
||||
readonly move: boolean;
|
||||
readonly resize: boolean;
|
||||
readonly moveable: boolean;
|
||||
readonly resizeable: boolean;
|
||||
readonly fullScreenable: boolean;
|
||||
readonly maximizable: boolean;
|
||||
readonly output: Output;
|
||||
readonly resourceClass: string;
|
||||
readonly dock: boolean;
|
||||
readonly normalWindow: boolean;
|
||||
readonly managed: boolean;
|
||||
readonly popupWindow: boolean;
|
||||
readonly pid: number;
|
||||
|
||||
fullScreen: boolean;
|
||||
activities: string[]; // empty array means all activities
|
||||
skipSwitcher: boolean;
|
||||
keepAbove: boolean;
|
||||
keepBelow: boolean;
|
||||
shade: boolean;
|
||||
minimized: boolean;
|
||||
frameGeometry: QmlRect;
|
||||
desktops: KwinDesktop[]; // empty array means all desktops
|
||||
tile: Tile;
|
||||
opacity: number;
|
||||
|
||||
readonly fullScreenChanged: QSignal<[]>;
|
||||
readonly desktopsChanged: QSignal<[]>;
|
||||
readonly outputChanged: QSignal<[]>;
|
||||
readonly activitiesChanged: QSignal<[]>;
|
||||
readonly minimizedChanged: QSignal<[]>;
|
||||
readonly maximizedAboutToChange: QSignal<[MaximizedMode]>
|
||||
readonly captionChanged: QSignal<[]>;
|
||||
readonly tileChanged: QSignal<[]>;
|
||||
readonly interactiveMoveResizeStarted: QSignal<[]>;
|
||||
readonly interactiveMoveResizeFinished: QSignal<[]>;
|
||||
readonly frameGeometryChanged: QSignal<[oldGeometry: QmlRect]>;
|
||||
|
||||
setMaximize(vertically: boolean, horizontally: boolean): void;
|
||||
}
|
||||
|
||||
interface KwinDesktop {
|
||||
readonly id: string;
|
||||
}
|
||||
|
||||
type ShortcutHandler = {
|
||||
readonly activated: QSignal<[]>;
|
||||
destroy(): void;
|
||||
};
|
||||
3
src/lib/extern/notification.ts
vendored
Normal file
3
src/lib/extern/notification.ts
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
type Notification = {
|
||||
sendEvent(): void;
|
||||
};
|
||||
21
src/extern/qt.d.ts → src/lib/extern/qt.ts
vendored
21
src/extern/qt.d.ts → src/lib/extern/qt.ts
vendored
@@ -1,17 +1,20 @@
|
||||
declare const console: {
|
||||
log(...args: any[]);
|
||||
trace();
|
||||
assert(boolean);
|
||||
};
|
||||
type Console = {
|
||||
log(...args: any[]): void;
|
||||
trace(): void;
|
||||
assert(assertion: boolean, message?: string): void;
|
||||
}
|
||||
|
||||
declare const Qt: {
|
||||
type Qt = {
|
||||
rect(x: number, y: number, width: number, height: number): QmlRect;
|
||||
createQmlObject(qml: string, parent: QmlObject);
|
||||
};
|
||||
createQmlObject(qml: string, parent: QmlObject): QmlObject;
|
||||
}
|
||||
|
||||
type QmlObject = unknown;
|
||||
|
||||
type QByteArray = string;
|
||||
type QmlPoint = {
|
||||
x: number;
|
||||
y: number;
|
||||
}
|
||||
|
||||
type QmlRect = {
|
||||
x: number;
|
||||
@@ -3,176 +3,148 @@ const keyBindings: KeyBinding[] = [
|
||||
name: "window-toggle-floating",
|
||||
description: "Toggle floating",
|
||||
defaultKeySequence: "Meta+Space",
|
||||
action: "windowToggleFloating",
|
||||
},
|
||||
{
|
||||
name: "focus-left",
|
||||
description: "Move focus left",
|
||||
defaultKeySequence: "Meta+A",
|
||||
action: "focusLeft",
|
||||
},
|
||||
{
|
||||
name: "focus-right",
|
||||
description: "Move focus right",
|
||||
comment: "Clashes with default KDE shortcuts, may require manual remapping",
|
||||
defaultKeySequence: "Meta+D",
|
||||
action: "focusRight",
|
||||
},
|
||||
{
|
||||
name: "focus-up",
|
||||
description: "Move focus up",
|
||||
comment: "Clashes with default KDE shortcuts, may require manual remapping",
|
||||
defaultKeySequence: "Meta+W",
|
||||
action: "focusUp",
|
||||
},
|
||||
{
|
||||
name: "focus-down",
|
||||
description: "Move focus down",
|
||||
comment: "Clashes with default KDE shortcuts, may require manual remapping",
|
||||
defaultKeySequence: "Meta+S",
|
||||
action: "focusDown",
|
||||
},
|
||||
{
|
||||
name: "focus-start",
|
||||
description: "Move focus to start",
|
||||
defaultKeySequence: "Meta+Home",
|
||||
action: "focusStart",
|
||||
},
|
||||
{
|
||||
name: "focus-end",
|
||||
description: "Move focus to end",
|
||||
defaultKeySequence: "Meta+End",
|
||||
action: "focusEnd",
|
||||
},
|
||||
{
|
||||
name: "window-move-left",
|
||||
description: "Move window left",
|
||||
comment: "Moves window out of and into columns",
|
||||
defaultKeySequence: "Meta+Shift+A",
|
||||
action: "windowMoveLeft",
|
||||
},
|
||||
{
|
||||
name: "window-move-right",
|
||||
description: "Move window right",
|
||||
comment: "Moves window out of and into columns",
|
||||
defaultKeySequence: "Meta+Shift+D",
|
||||
action: "windowMoveRight",
|
||||
},
|
||||
{
|
||||
name: "window-move-up",
|
||||
description: "Move window up",
|
||||
defaultKeySequence: "Meta+Shift+W",
|
||||
action: "windowMoveUp",
|
||||
},
|
||||
{
|
||||
name: "window-move-down",
|
||||
description: "Move window down",
|
||||
defaultKeySequence: "Meta+Shift+S",
|
||||
action: "windowMoveDown",
|
||||
},
|
||||
{
|
||||
name: "window-move-start",
|
||||
description: "Move window to start",
|
||||
defaultKeySequence: "Meta+Shift+Home",
|
||||
action: "windowMoveStart",
|
||||
},
|
||||
{
|
||||
name: "window-move-end",
|
||||
description: "Move window to end",
|
||||
defaultKeySequence: "Meta+Shift+End",
|
||||
action: "windowMoveEnd",
|
||||
},
|
||||
{
|
||||
name: "column-toggle-stacked",
|
||||
description: "Toggle stacked layout for focused column",
|
||||
comment: "One window in the column visible, others shaded; not supported on Wayland",
|
||||
defaultKeySequence: "Meta+X",
|
||||
action: "columnToggleStacked",
|
||||
},
|
||||
{
|
||||
name: "column-move-left",
|
||||
description: "Move column left",
|
||||
defaultKeySequence: "Meta+Ctrl+Shift+A",
|
||||
action: "columnMoveLeft",
|
||||
},
|
||||
{
|
||||
name: "column-move-right",
|
||||
description: "Move column right",
|
||||
defaultKeySequence: "Meta+Ctrl+Shift+D",
|
||||
action: "columnMoveRight",
|
||||
},
|
||||
{
|
||||
name: "column-move-start",
|
||||
description: "Move column to start",
|
||||
defaultKeySequence: "Meta+Ctrl+Shift+Home",
|
||||
action: "columnMoveStart",
|
||||
},
|
||||
{
|
||||
name: "column-move-end",
|
||||
description: "Move column to end",
|
||||
defaultKeySequence: "Meta+Ctrl+Shift+End",
|
||||
action: "columnMoveEnd",
|
||||
},
|
||||
{
|
||||
name: "column-width-increase",
|
||||
description: "Increase column width",
|
||||
defaultKeySequence: "Meta+Ctrl++",
|
||||
action: "columnWidthIncrease",
|
||||
},
|
||||
{
|
||||
name: "column-width-decrease",
|
||||
description: "Decrease column width",
|
||||
defaultKeySequence: "Meta+Ctrl+-",
|
||||
action: "columnWidthDecrease",
|
||||
},
|
||||
{
|
||||
name: "columns-width-equalize",
|
||||
description: "Equalize widths of visible columns",
|
||||
defaultKeySequence: "Meta+Ctrl+X",
|
||||
action: "columnsWidthEqualize",
|
||||
},
|
||||
{
|
||||
name: "grid-scroll-focused",
|
||||
description: "Center focused window",
|
||||
comment: "Scrolls so that the focused window is centered in the screen",
|
||||
defaultKeySequence: "Meta+Alt+Return",
|
||||
action: "gridScrollFocused",
|
||||
},
|
||||
{
|
||||
name: "grid-scroll-left-column",
|
||||
description: "Scroll one column to the left",
|
||||
defaultKeySequence: "Meta+Alt+A",
|
||||
action: "gridScrollLeftColumn",
|
||||
},
|
||||
{
|
||||
name: "grid-scroll-right-column",
|
||||
description: "Scroll one column to the right",
|
||||
defaultKeySequence: "Meta+Alt+D",
|
||||
action: "gridScrollRightColumn",
|
||||
},
|
||||
{
|
||||
name: "grid-scroll-left",
|
||||
description: "Scroll left",
|
||||
defaultKeySequence: "Meta+Alt+PgUp",
|
||||
action: "gridScrollLeft",
|
||||
},
|
||||
{
|
||||
name: "grid-scroll-right",
|
||||
description: "Scroll right",
|
||||
defaultKeySequence: "Meta+Alt+PgDown",
|
||||
action: "gridScrollRight",
|
||||
},
|
||||
{
|
||||
name: "grid-scroll-start",
|
||||
description: "Scroll to start",
|
||||
defaultKeySequence: "Meta+Alt+Home",
|
||||
action: "gridScrollStart",
|
||||
},
|
||||
{
|
||||
name: "grid-scroll-end",
|
||||
description: "Scroll to end",
|
||||
defaultKeySequence: "Meta+Alt+End",
|
||||
action: "gridScrollEnd",
|
||||
},
|
||||
];
|
||||
|
||||
@@ -183,7 +155,6 @@ const numKeyBindings: NumKeyBinding[] = [
|
||||
comment: "Clashes with default KDE shortcuts, may require manual remapping",
|
||||
defaultModifiers: "Meta",
|
||||
fKeys: false,
|
||||
action: "focusColumn",
|
||||
},
|
||||
{
|
||||
name: "window-move-to-column-",
|
||||
@@ -191,7 +162,6 @@ const numKeyBindings: NumKeyBinding[] = [
|
||||
comment: "Requires manual remapping according to your keyboard layout, e.g. Meta+Shift+1 -> Meta+!",
|
||||
defaultModifiers: "Meta+Shift",
|
||||
fKeys: false,
|
||||
action: "windowMoveToColumn",
|
||||
},
|
||||
{
|
||||
name: "column-move-to-column-",
|
||||
@@ -199,20 +169,17 @@ const numKeyBindings: NumKeyBinding[] = [
|
||||
comment: "Requires manual remapping according to your keyboard layout, e.g. Meta+Ctrl+Shift+1 -> Meta+Ctrl+!",
|
||||
defaultModifiers: "Meta+Ctrl+Shift",
|
||||
fKeys: false,
|
||||
action: "columnMoveToColumn",
|
||||
},
|
||||
{
|
||||
name: "column-move-to-desktop-",
|
||||
description: "Move column to desktop ",
|
||||
defaultModifiers: "Meta+Ctrl+Shift",
|
||||
fKeys: true,
|
||||
action: "columnMoveToDesktop",
|
||||
},
|
||||
{
|
||||
name: "tail-move-to-desktop-",
|
||||
description: "Move this and all following columns to desktop ",
|
||||
defaultModifiers: "Meta+Ctrl+Shift+Alt",
|
||||
fKeys: true,
|
||||
action: "tailMoveToDesktop",
|
||||
},
|
||||
];
|
||||
67
src/lib/keyBindings/loader.ts
Normal file
67
src/lib/keyBindings/loader.ts
Normal file
@@ -0,0 +1,67 @@
|
||||
type KeyBinding = {
|
||||
name: string;
|
||||
description: string;
|
||||
comment?: string;
|
||||
defaultKeySequence: string;
|
||||
};
|
||||
|
||||
type NumKeyBinding = {
|
||||
name: string;
|
||||
description: string;
|
||||
comment?: string;
|
||||
defaultModifiers: string;
|
||||
fKeys: boolean;
|
||||
};
|
||||
|
||||
function catchWrap(f: () => void) {
|
||||
return () => {
|
||||
try {
|
||||
f();
|
||||
} catch (error: any) {
|
||||
log(error);
|
||||
log(error.stack);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function registerKeyBinding(world: World, config: Actions.Config, shortcutActions: ShortcutAction[], keyBinding: KeyBinding) {
|
||||
shortcutActions.push(new ShortcutAction(
|
||||
keyBinding,
|
||||
catchWrap(Actions.getAction(world, config, keyBinding.name)),
|
||||
));
|
||||
}
|
||||
|
||||
function registerNumKeyBindings(world: World, shortcutActions: ShortcutAction[], numKeyBinding: NumKeyBinding) {
|
||||
const numPrefix = numKeyBinding.fKeys ? "F" : "";
|
||||
const n = numKeyBinding.fKeys ? 12 : 9;
|
||||
for (let i = 0; i < 12; i++) {
|
||||
const numKey = String(i + 1);
|
||||
const keySequence = i < n ?
|
||||
numKeyBinding.defaultModifiers + "+" + numPrefix + numKey :
|
||||
"";
|
||||
const action = Actions.getNumAction(world, numKeyBinding.name);
|
||||
shortcutActions.push(new ShortcutAction(
|
||||
{
|
||||
name: numKeyBinding.name + numKey,
|
||||
description: numKeyBinding.description + numKey,
|
||||
defaultKeySequence: keySequence,
|
||||
},
|
||||
catchWrap(() => action(i)),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: refactor
|
||||
function registerKeyBindings(world: World, config: Actions.Config) {
|
||||
const shortcutActions: ShortcutAction[] = [];
|
||||
|
||||
for (const keyBinding of keyBindings) {
|
||||
registerKeyBinding(world, config, shortcutActions, keyBinding);
|
||||
}
|
||||
|
||||
for (const numKeyBinding of numKeyBindings) {
|
||||
registerNumKeyBindings(world, shortcutActions, numKeyBinding);
|
||||
}
|
||||
|
||||
return shortcutActions;
|
||||
}
|
||||
@@ -19,32 +19,25 @@ class Column {
|
||||
|
||||
public moveToGrid(targetGrid: Grid, prevColumn: Column|null) {
|
||||
if (targetGrid === this.grid) {
|
||||
this.grid.onColumnMoved(this, prevColumn);
|
||||
this.grid.moveColumn(this, prevColumn);
|
||||
} else {
|
||||
this.grid.onColumnRemoved(this, false);
|
||||
this.grid = targetGrid;
|
||||
targetGrid.onColumnAdded(this, prevColumn);
|
||||
for (const window of this.windows.iterator()) {
|
||||
window.client.kwinClient.desktop = targetGrid.desktop.desktopNumber;
|
||||
window.client.kwinClient.desktops = [targetGrid.desktop.kwinDesktop];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public moveAfter(prevColumn: Column|null) {
|
||||
if (prevColumn === this) {
|
||||
return;
|
||||
}
|
||||
this.grid.onColumnMoved(this, prevColumn);
|
||||
}
|
||||
|
||||
public isAfter(other: Column) {
|
||||
return this.gridX > other.gridX;
|
||||
}
|
||||
|
||||
public isBefore(other: Column) {
|
||||
public isToTheLeftOf(other: Column) {
|
||||
return this.gridX < other.gridX;
|
||||
}
|
||||
|
||||
public isToTheRightOf(other: Column) {
|
||||
return this.gridX > other.gridX;
|
||||
}
|
||||
|
||||
public moveWindowUp(window: Window) {
|
||||
this.windows.moveBack(window);
|
||||
this.grid.desktop.onLayoutChanged();
|
||||
@@ -1,6 +1,7 @@
|
||||
class Desktop {
|
||||
public readonly grid: Grid;
|
||||
public readonly desktopNumber: number;
|
||||
public readonly screen: Output;
|
||||
public readonly kwinDesktop: KwinDesktop;
|
||||
private readonly pinManager: PinManager;
|
||||
private readonly config: Desktop.Config;
|
||||
private scrollX: number;
|
||||
@@ -10,26 +11,27 @@ class Desktop {
|
||||
public clientArea: QmlRect;
|
||||
public tilingArea: QmlRect;
|
||||
|
||||
constructor(desktopNumber: number, pinManager: PinManager, config: Desktop.Config, layoutConfig: LayoutConfig) {
|
||||
constructor(screen: Output, kwinDesktop: KwinDesktop, pinManager: PinManager, config: Desktop.Config, layoutConfig: LayoutConfig) {
|
||||
this.pinManager = pinManager;
|
||||
this.config = config;
|
||||
this.scrollX = 0;
|
||||
this.dirty = true;
|
||||
this.dirtyScroll = true;
|
||||
this.dirtyPins = true;
|
||||
this.desktopNumber = desktopNumber;
|
||||
this.screen = screen;
|
||||
this.kwinDesktop = kwinDesktop;
|
||||
this.grid = new Grid(this, layoutConfig);
|
||||
this.clientArea = Desktop.getClientArea(desktopNumber);
|
||||
this.tilingArea = Desktop.getTilingArea(this.clientArea, desktopNumber, pinManager, config);
|
||||
this.clientArea = Desktop.getClientArea(screen, kwinDesktop);
|
||||
this.tilingArea = Desktop.getTilingArea(this.clientArea, kwinDesktop, pinManager, config);
|
||||
}
|
||||
|
||||
private updateArea() {
|
||||
const newClientArea = Desktop.getClientArea(this.desktopNumber);
|
||||
const newClientArea = Desktop.getClientArea(this.screen, this.kwinDesktop);
|
||||
if (newClientArea === this.clientArea && !this.dirtyPins) {
|
||||
return;
|
||||
}
|
||||
this.clientArea = newClientArea;
|
||||
this.tilingArea = Desktop.getTilingArea(newClientArea, this.desktopNumber, this.pinManager, this.config);
|
||||
this.tilingArea = Desktop.getTilingArea(newClientArea, this.kwinDesktop, this.pinManager, this.config);
|
||||
this.dirty = true;
|
||||
this.dirtyScroll = true;
|
||||
this.dirtyPins = false;
|
||||
@@ -37,12 +39,12 @@ class Desktop {
|
||||
this.autoAdjustScroll();
|
||||
}
|
||||
|
||||
private static getClientArea(desktopNumber: number) {
|
||||
return workspace.clientArea(ClientAreaOption.PlacementArea, 0, desktopNumber);
|
||||
private static getClientArea(screen: Output, kwinDesktop: KwinDesktop) {
|
||||
return Workspace.clientArea(ClientAreaOption.PlacementArea, screen, kwinDesktop);
|
||||
}
|
||||
|
||||
private static getTilingArea(clientArea: QmlRect, desktopNumber: number, pinManager: PinManager, config: Desktop.Config) {
|
||||
const availableSpace = pinManager.getAvailableSpace(desktopNumber, clientArea);
|
||||
private static getTilingArea(clientArea: QmlRect, kwinDesktop: KwinDesktop, pinManager: PinManager, config: Desktop.Config) {
|
||||
const availableSpace = pinManager.getAvailableSpace(kwinDesktop, clientArea);
|
||||
const top = availableSpace.top + config.marginTop;
|
||||
const bottom = availableSpace.bottom - config.marginBottom;
|
||||
const left = availableSpace.left + config.marginLeft;
|
||||
@@ -24,6 +24,18 @@ class Grid {
|
||||
});
|
||||
}
|
||||
|
||||
public moveColumn(column: Column, prevColumn: Column|null) {
|
||||
if (column === prevColumn) {
|
||||
return;
|
||||
}
|
||||
const movedLeft = prevColumn === null ? true : column.isToTheRightOf(prevColumn);
|
||||
const firstMovedColumn = movedLeft ? column : this.getNextColumn(column);
|
||||
this.columns.move(column, prevColumn);
|
||||
this.columnsSetX(firstMovedColumn);
|
||||
this.desktop.onLayoutChanged();
|
||||
this.desktop.autoAdjustScroll();
|
||||
}
|
||||
|
||||
public moveColumnLeft(column: Column) {
|
||||
this.columns.moveBack(column);
|
||||
this.columnsSetX(column);
|
||||
@@ -180,15 +192,6 @@ class Grid {
|
||||
}
|
||||
}
|
||||
|
||||
public onColumnMoved(column: Column, prevColumn: Column|null) {
|
||||
const movedLeft = prevColumn === null ? true : column.isAfter(prevColumn);
|
||||
const firstMovedColumn = movedLeft ? column : this.getNextColumn(column);
|
||||
this.columns.move(column, prevColumn);
|
||||
this.columnsSetX(firstMovedColumn);
|
||||
this.desktop.onLayoutChanged();
|
||||
this.desktop.autoAdjustScroll();
|
||||
}
|
||||
|
||||
public onColumnWidthChanged(column: Column) {
|
||||
const nextColumn = this.columns.getNext(column);
|
||||
this.columnsSetX(nextColumn);
|
||||
@@ -10,8 +10,7 @@ class Window {
|
||||
this.height = client.kwinClient.frameGeometry.height;
|
||||
this.focusedState = {
|
||||
fullScreen: false,
|
||||
maximizedHorizontally: false,
|
||||
maximizedVertically: false,
|
||||
maximizedMode: MaximizedMode.Unmaximized,
|
||||
};
|
||||
this.skipArrange = false;
|
||||
this.column = column;
|
||||
@@ -37,8 +36,11 @@ class Window {
|
||||
if (this.column.grid.config.reMaximize && this.isFocused()) {
|
||||
// do this here rather than in `onFocused` to ensure it happens after placement
|
||||
// (otherwise placement may not happen at all)
|
||||
if (this.focusedState.maximizedVertically || this.focusedState.maximizedHorizontally) {
|
||||
this.client.setMaximize(this.focusedState.maximizedVertically, this.focusedState.maximizedHorizontally);
|
||||
if (this.focusedState.maximizedMode !== MaximizedMode.Unmaximized) {
|
||||
this.client.setMaximize(
|
||||
this.focusedState.maximizedMode === MaximizedMode.Horizontally || this.focusedState.maximizedMode === MaximizedMode.Maximized,
|
||||
this.focusedState.maximizedMode === MaximizedMode.Vertically || this.focusedState.maximizedMode === MaximizedMode.Maximized,
|
||||
);
|
||||
maximized = true;
|
||||
}
|
||||
if (this.focusedState.fullScreen) {
|
||||
@@ -76,8 +78,8 @@ class Window {
|
||||
this.column.grid.desktop.onLayoutChanged();
|
||||
}
|
||||
|
||||
public onMaximizedChanged(horizontally: boolean, vertically: boolean) {
|
||||
const maximized = horizontally || vertically;
|
||||
public onMaximizedChanged(maximizedMode: MaximizedMode) {
|
||||
const maximized = maximizedMode !== MaximizedMode.Unmaximized;
|
||||
this.skipArrange = maximized;
|
||||
if (this.column.grid.config.tiledKeepBelow) {
|
||||
this.client.kwinClient.keepBelow = !maximized;
|
||||
@@ -86,8 +88,7 @@ class Window {
|
||||
this.client.kwinClient.keepAbove = maximized;
|
||||
}
|
||||
if (this.isFocused()) {
|
||||
this.focusedState.maximizedHorizontally = horizontally;
|
||||
this.focusedState.maximizedVertically = vertically;
|
||||
this.focusedState.maximizedMode = maximizedMode;
|
||||
}
|
||||
this.column.grid.desktop.onLayoutChanged();
|
||||
}
|
||||
@@ -145,7 +146,6 @@ class Window {
|
||||
namespace Window {
|
||||
export type State = {
|
||||
fullScreen: boolean,
|
||||
maximizedHorizontally: boolean,
|
||||
maximizedVertically: boolean,
|
||||
maximizedMode: MaximizedMode,
|
||||
}
|
||||
}
|
||||
19
src/lib/rules/ClientMatcher.ts
Normal file
19
src/lib/rules/ClientMatcher.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
class ClientMatcher {
|
||||
private readonly regex: RegExp;
|
||||
|
||||
constructor(regex: RegExp) {
|
||||
this.regex = regex;
|
||||
}
|
||||
|
||||
public matches(kwinClient: KwinClient) {
|
||||
return this.regex.test(ClientMatcher.getClientString(kwinClient));
|
||||
}
|
||||
|
||||
public static getClientString(kwinClient: KwinClient) {
|
||||
return ClientMatcher.getRuleString(kwinClient.resourceClass, kwinClient.caption);
|
||||
}
|
||||
|
||||
public static getRuleString(ruleClass: string, ruleCaption: string) {
|
||||
return ruleClass + "\0" + ruleCaption;
|
||||
}
|
||||
}
|
||||
5
src/lib/rules/WindowRule.ts
Normal file
5
src/lib/rules/WindowRule.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
type WindowRule = {
|
||||
class: string | undefined,
|
||||
caption: string | undefined,
|
||||
tile: boolean,
|
||||
};
|
||||
95
src/lib/rules/WindowRuleEnforcer.ts
Normal file
95
src/lib/rules/WindowRuleEnforcer.ts
Normal file
@@ -0,0 +1,95 @@
|
||||
class WindowRuleEnforcer {
|
||||
private readonly preferFloating: ClientMatcher;
|
||||
private readonly preferTiling: ClientMatcher;
|
||||
private readonly followCaption: RegExp;
|
||||
|
||||
constructor(windowRules: WindowRule[]) {
|
||||
const [floatRegex, tileRegex, followCaptionRegex] = WindowRuleEnforcer.createWindowRuleRegexes(windowRules);
|
||||
this.preferFloating = new ClientMatcher(floatRegex);
|
||||
this.preferTiling = new ClientMatcher(tileRegex);
|
||||
this.followCaption = followCaptionRegex;
|
||||
}
|
||||
|
||||
public shouldTile(kwinClient: KwinClient) {
|
||||
return Clients.canTileNow(kwinClient) && (
|
||||
this.preferTiling.matches(kwinClient) || (
|
||||
kwinClient.normalWindow &&
|
||||
!kwinClient.transient &&
|
||||
kwinClient.managed &&
|
||||
kwinClient.pid > -1 &&
|
||||
!this.preferFloating.matches(kwinClient)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public initClientSignalManager(world: World, kwinClient: KwinClient) {
|
||||
if (!this.followCaption.test(kwinClient.resourceClass)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const enforcer = this;
|
||||
const manager = new SignalManager();
|
||||
manager.connect(kwinClient.captionChanged, () => {
|
||||
const shouldTile = enforcer.shouldTile(kwinClient);
|
||||
world.do((clientManager, desktopManager) => {
|
||||
const desktop = desktopManager.getDesktopForClient(kwinClient);
|
||||
if (shouldTile && desktop !== undefined) {
|
||||
clientManager.tileKwinClient(kwinClient, desktop.grid);
|
||||
} else {
|
||||
clientManager.floatKwinClient(kwinClient);
|
||||
}
|
||||
});
|
||||
});
|
||||
return manager;
|
||||
}
|
||||
|
||||
private static createWindowRuleRegexes(windowRules: WindowRule[]) {
|
||||
const floatRegexes: string[] = [];
|
||||
const tileRegexes: string[] = [];
|
||||
const followCaptionRegexes: string[] = [];
|
||||
for (const windowRule of windowRules) {
|
||||
const ruleClass = WindowRuleEnforcer.parseRegex(windowRule.class);
|
||||
const ruleCaption = WindowRuleEnforcer.parseRegex(windowRule.caption);
|
||||
const ruleString = ClientMatcher.getRuleString(
|
||||
WindowRuleEnforcer.wrapParens(ruleClass),
|
||||
WindowRuleEnforcer.wrapParens(ruleCaption)
|
||||
);
|
||||
|
||||
(windowRule.tile ? tileRegexes : floatRegexes).push(ruleString);
|
||||
if (ruleCaption !== ".*") {
|
||||
followCaptionRegexes.push(ruleClass);
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
WindowRuleEnforcer.joinRegexes(floatRegexes),
|
||||
WindowRuleEnforcer.joinRegexes(tileRegexes),
|
||||
WindowRuleEnforcer.joinRegexes(followCaptionRegexes),
|
||||
];
|
||||
}
|
||||
|
||||
private static parseRegex(rawRule: string | undefined) {
|
||||
if (rawRule === undefined || rawRule === "" || rawRule === ".*") {
|
||||
return ".*";
|
||||
} else {
|
||||
return rawRule;
|
||||
}
|
||||
}
|
||||
|
||||
private static joinRegexes(regexes: string[]) {
|
||||
if (regexes.length === 0) {
|
||||
return new RegExp("a^"); // match nothing
|
||||
}
|
||||
|
||||
if (regexes.length === 1) {
|
||||
return new RegExp("^(" + regexes[0] + ")$");
|
||||
}
|
||||
|
||||
const joinedRegexes = regexes.map(WindowRuleEnforcer.wrapParens).join("|");
|
||||
return new RegExp("^(" + joinedRegexes + ")$");
|
||||
}
|
||||
|
||||
private static wrapParens(str: string) {
|
||||
return "(" + str + ")";
|
||||
}
|
||||
}
|
||||
@@ -17,8 +17,8 @@ class Delayer {
|
||||
}
|
||||
|
||||
function initQmlTimer() {
|
||||
return Qt.createQmlObject(
|
||||
`import QtQuick 2.15
|
||||
return <QmlTimer>Qt.createQmlObject(
|
||||
`import QtQuick 6.0
|
||||
Timer {}`,
|
||||
qmlBase
|
||||
);
|
||||
25
src/lib/utils/ShortcutAction.ts
Normal file
25
src/lib/utils/ShortcutAction.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
class ShortcutAction {
|
||||
private readonly shortcutHandler: ShortcutHandler;
|
||||
|
||||
constructor(keyBinding: KeyBinding, f: () => void) {
|
||||
this.shortcutHandler = ShortcutAction.initShortcutHandler(keyBinding);
|
||||
this.shortcutHandler.activated.connect(f);
|
||||
}
|
||||
|
||||
public destroy() {
|
||||
this.shortcutHandler.destroy();
|
||||
}
|
||||
|
||||
private static initShortcutHandler(keyBinding: KeyBinding) {
|
||||
return <ShortcutHandler>Qt.createQmlObject(
|
||||
`import QtQuick 6.0
|
||||
import org.kde.kwin 3.0
|
||||
ShortcutHandler {
|
||||
name: "karousel-${keyBinding.name}";
|
||||
text: "Karousel: ${keyBinding.description}";
|
||||
sequence: "${keyBinding.defaultKeySequence}";
|
||||
}`,
|
||||
qmlBase,
|
||||
);
|
||||
}
|
||||
}
|
||||
60
src/lib/workspace.ts
Normal file
60
src/lib/workspace.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
function initWorkspaceSignalHandlers(world: World) {
|
||||
const manager = new SignalManager();
|
||||
|
||||
manager.connect(Workspace.windowAdded, (kwinClient: KwinClient) => {
|
||||
if (Clients.canTileEver(kwinClient)) {
|
||||
// never open new tileable clients on all desktops or activities
|
||||
Clients.makeTileable(kwinClient);
|
||||
}
|
||||
world.do((clientManager, desktopManager) => {
|
||||
clientManager.addClient(kwinClient)
|
||||
});
|
||||
});
|
||||
|
||||
manager.connect(Workspace.windowRemoved, (kwinClient: KwinClient) => {
|
||||
world.do((clientManager, desktopManager) => {
|
||||
clientManager.removeClient(kwinClient, true);
|
||||
});
|
||||
});
|
||||
|
||||
manager.connect(Workspace.windowActivated, (kwinClient: KwinClient) => {
|
||||
if (kwinClient === null) {
|
||||
return;
|
||||
}
|
||||
world.do((clientManager, desktopManager) => {
|
||||
clientManager.onClientFocused(kwinClient);
|
||||
});
|
||||
});
|
||||
|
||||
manager.connect(Workspace.currentDesktopChanged, () => {
|
||||
world.do(() => {}); // re-arrange desktop
|
||||
});
|
||||
|
||||
manager.connect(Workspace.currentActivityChanged, () => {
|
||||
world.do(() => {}); // re-arrange desktop
|
||||
});
|
||||
|
||||
manager.connect(Workspace.screensChanged, () => {
|
||||
world.do((clientManager, desktopManager) => {
|
||||
desktopManager.updateScreens();
|
||||
})
|
||||
});
|
||||
|
||||
manager.connect(Workspace.activitiesChanged, () => {
|
||||
world.do((clientManager, desktopManager) => {
|
||||
desktopManager.updateActivities();
|
||||
})
|
||||
});
|
||||
|
||||
manager.connect(Workspace.desktopsChanged, () => {
|
||||
world.do((clientManager, desktopManager) => {
|
||||
desktopManager.updateDesktops();
|
||||
})
|
||||
});
|
||||
|
||||
manager.connect(Workspace.virtualScreenSizeChanged, () => {
|
||||
world.onScreenResized();
|
||||
});
|
||||
|
||||
return manager;
|
||||
}
|
||||
@@ -76,44 +76,41 @@ class ClientManager {
|
||||
return;
|
||||
}
|
||||
if (client.stateManager.getState() instanceof ClientState.Tiled) {
|
||||
client.stateManager.setState(() => new ClientState.TiledMinimized(), kwinClient === this.lastFocusedClient);
|
||||
client.stateManager.setState(
|
||||
() => new ClientState.TiledMinimized(this.world, client),
|
||||
kwinClient === this.lastFocusedClient,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public unminimizeClient(kwinClient: KwinClient) {
|
||||
const client = this.clientMap.get(kwinClient);
|
||||
if (client === undefined) {
|
||||
return;
|
||||
}
|
||||
if (client.stateManager.getState() instanceof ClientState.TiledMinimized) {
|
||||
const desktop = this.desktopManager.getDesktopForClient(kwinClient);
|
||||
if (desktop !== undefined) {
|
||||
client.stateManager.setState(() => new ClientState.Tiled(this.world, client, desktop.grid), false);
|
||||
} else {
|
||||
client.stateManager.setState(() => new ClientState.Floating(this.world, client, this.config, false), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public tileClient(kwinClient: KwinClient, grid: Grid) {
|
||||
const client = this.clientMap.get(kwinClient);
|
||||
if (client === undefined) {
|
||||
return;
|
||||
}
|
||||
public tileClient(client: ClientWrapper, grid: Grid) {
|
||||
if (client.stateManager.getState() instanceof ClientState.Tiled) {
|
||||
return;
|
||||
}
|
||||
client.stateManager.setState(() => new ClientState.Tiled(this.world, client, grid), false);
|
||||
}
|
||||
|
||||
public untileClient(kwinClient: KwinClient) {
|
||||
public floatClient(client: ClientWrapper) {
|
||||
if (client.stateManager.getState() instanceof ClientState.Floating) {
|
||||
return;
|
||||
}
|
||||
client.stateManager.setState(() => new ClientState.Floating(this.world, client, this.config, true), false);
|
||||
}
|
||||
|
||||
public tileKwinClient(kwinClient: KwinClient, grid: Grid) {
|
||||
const client = this.clientMap.get(kwinClient);
|
||||
if (client === undefined) {
|
||||
return;
|
||||
}
|
||||
if (client.stateManager.getState() instanceof ClientState.Tiled) {
|
||||
client.stateManager.setState(() => new ClientState.Floating(this.world, client, this.config, true), false);
|
||||
this.tileClient(client, grid);
|
||||
}
|
||||
|
||||
public floatKwinClient(kwinClient: KwinClient) {
|
||||
const client = this.clientMap.get(kwinClient);
|
||||
if (client === undefined) {
|
||||
return;
|
||||
}
|
||||
this.floatClient(client);
|
||||
}
|
||||
|
||||
public pinClient(kwinClient: KwinClient) {
|
||||
@@ -121,6 +118,11 @@ class ClientManager {
|
||||
if (client === undefined) {
|
||||
return;
|
||||
}
|
||||
if (client.getMaximizedMode() !== MaximizedMode.Unmaximized) {
|
||||
// the client is not really kwin-tiled, just maximized
|
||||
kwinClient.tile = null;
|
||||
return;
|
||||
}
|
||||
client.stateManager.setState(() => new ClientState.Pinned(this.world, this.pinManager, this.desktopManager, kwinClient, this.config), false);
|
||||
this.pinManager.addClient(kwinClient);
|
||||
for (const desktop of this.desktopManager.getDesktopsForClient(kwinClient)) {
|
||||
@@ -3,8 +3,10 @@ class ClientWrapper {
|
||||
public readonly stateManager: ClientState.Manager;
|
||||
public transientFor: ClientWrapper | null;
|
||||
private readonly transients: ClientWrapper[];
|
||||
private readonly signalManager: SignalManager;
|
||||
private readonly rulesSignalManager: SignalManager | null;
|
||||
public preferredWidth: number;
|
||||
private maximizedMode: MaximizedMode | undefined;
|
||||
private readonly manipulatingGeometry: Doer;
|
||||
private lastPlacement: QmlRect | null; // workaround for issue #19
|
||||
|
||||
@@ -20,6 +22,7 @@ class ClientWrapper {
|
||||
if (transientFor !== null) {
|
||||
transientFor.addTransient(this);
|
||||
}
|
||||
this.signalManager = ClientWrapper.initSignalManager(this);
|
||||
this.rulesSignalManager = rulesSignalManager;
|
||||
this.preferredWidth = kwinClient.frameGeometry.width;
|
||||
this.manipulatingGeometry = new Doer();
|
||||
@@ -44,9 +47,9 @@ class ClientWrapper {
|
||||
});
|
||||
}
|
||||
|
||||
private moveTransient(dx: number, dy: number, desktopNumber: number) {
|
||||
private moveTransient(dx: number, dy: number, kwinDesktops: KwinDesktop[]) {
|
||||
if (this.stateManager.getState() instanceof ClientState.Floating) {
|
||||
if (this.kwinClient.desktop === desktopNumber) {
|
||||
if (Clients.isOnOneOfVirtualDesktops(this.kwinClient, kwinDesktops)) {
|
||||
const frame = this.kwinClient.frameGeometry;
|
||||
this.kwinClient.frameGeometry = Qt.rect(
|
||||
frame.x + dx,
|
||||
@@ -57,32 +60,52 @@ class ClientWrapper {
|
||||
}
|
||||
|
||||
for (const transient of this.transients) {
|
||||
transient.moveTransient(dx, dy, desktopNumber);
|
||||
transient.moveTransient(dx, dy, kwinDesktops);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public moveTransients(dx: number, dy: number) {
|
||||
for (const transient of this.transients) {
|
||||
transient.moveTransient(dx, dy, this.kwinClient.desktop);
|
||||
transient.moveTransient(dx, dy, this.kwinClient.desktops);
|
||||
}
|
||||
}
|
||||
|
||||
public focus() {
|
||||
workspace.activeClient = this.kwinClient;
|
||||
Workspace.activeWindow = this.kwinClient;
|
||||
}
|
||||
|
||||
public isFocused() {
|
||||
return workspace.activeClient === this.kwinClient;
|
||||
return Workspace.activeWindow === this.kwinClient;
|
||||
}
|
||||
|
||||
public setMaximize(horizontally: boolean, vertically: boolean) {
|
||||
if (!this.kwinClient.maximizable) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.maximizedMode === undefined) {
|
||||
if (horizontally && vertically) {
|
||||
this.maximizedMode = MaximizedMode.Maximized;
|
||||
} else if (horizontally) {
|
||||
this.maximizedMode = MaximizedMode.Horizontally;
|
||||
} else if (vertically) {
|
||||
this.maximizedMode = MaximizedMode.Vertically;
|
||||
} else {
|
||||
this.maximizedMode = MaximizedMode.Unmaximized;
|
||||
}
|
||||
}
|
||||
|
||||
this.manipulatingGeometry.do(() => {
|
||||
this.kwinClient.setMaximize(vertically, horizontally);
|
||||
});
|
||||
}
|
||||
|
||||
public setFullScreen(fullScreen: boolean) {
|
||||
if (!this.kwinClient.fullScreenable) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.manipulatingGeometry.do(() => {
|
||||
this.kwinClient.fullScreen = fullScreen;
|
||||
});
|
||||
@@ -98,6 +121,10 @@ class ClientWrapper {
|
||||
return this.kwinClient.shade;
|
||||
}
|
||||
|
||||
public getMaximizedMode() {
|
||||
return this.maximizedMode;
|
||||
}
|
||||
|
||||
public isManipulatingGeometry(newGeometry: QmlRect | null) {
|
||||
if (newGeometry !== null && newGeometry === this.lastPlacement) {
|
||||
return true;
|
||||
@@ -124,7 +151,7 @@ class ClientWrapper {
|
||||
}
|
||||
|
||||
public ensureVisible(screenSize: QmlRect) {
|
||||
if (this.kwinClient.desktop !== workspace.currentDesktop) {
|
||||
if (!Clients.isOnVirtualDesktop(this.kwinClient, Workspace.currentDesktop)) {
|
||||
return;
|
||||
}
|
||||
const frame = this.kwinClient.frameGeometry;
|
||||
@@ -137,6 +164,7 @@ class ClientWrapper {
|
||||
|
||||
public destroy(passFocus: boolean) {
|
||||
this.stateManager.destroy(passFocus);
|
||||
this.signalManager.destroy();
|
||||
if (this.rulesSignalManager !== null) {
|
||||
this.rulesSignalManager.destroy();
|
||||
}
|
||||
@@ -147,4 +175,17 @@ class ClientWrapper {
|
||||
transient.transientFor = null;
|
||||
}
|
||||
}
|
||||
|
||||
private static initSignalManager(client: ClientWrapper) {
|
||||
const manager = new SignalManager();
|
||||
|
||||
manager.connect(client.kwinClient.maximizedAboutToChange, (maximizedMode: MaximizedMode) => {
|
||||
if (maximizedMode !== MaximizedMode.Unmaximized && client.kwinClient.tile !== null) {
|
||||
client.kwinClient.tile = null;
|
||||
}
|
||||
client.maximizedMode = maximizedMode;
|
||||
});
|
||||
|
||||
return manager;
|
||||
}
|
||||
}
|
||||
49
src/lib/world/Clients.ts
Normal file
49
src/lib/world/Clients.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
namespace Clients {
|
||||
export function canTileEver(kwinClient: KwinClient) {
|
||||
return kwinClient.moveable && kwinClient.resizeable && !kwinClient.popupWindow;
|
||||
}
|
||||
|
||||
export function canTileNow(kwinClient: KwinClient) {
|
||||
return canTileEver(kwinClient) && !kwinClient.minimized && kwinClient.desktops.length === 1 && kwinClient.activities.length === 1;
|
||||
}
|
||||
|
||||
export function makeTileable(kwinClient: KwinClient) {
|
||||
if (kwinClient.minimized) {
|
||||
kwinClient.minimized = false;
|
||||
}
|
||||
if (kwinClient.desktops.length !== 1) {
|
||||
kwinClient.desktops = [Workspace.currentDesktop];
|
||||
}
|
||||
if (kwinClient.activities.length !== 1) {
|
||||
kwinClient.activities = [Workspace.currentActivity];
|
||||
}
|
||||
}
|
||||
|
||||
export function getKwinDesktopApprox(kwinClient: KwinClient) {
|
||||
switch (kwinClient.desktops.length) {
|
||||
case 0:
|
||||
return Workspace.currentDesktop;
|
||||
case 1:
|
||||
return kwinClient.desktops[0];
|
||||
default:
|
||||
if (kwinClient.desktops.includes(Workspace.currentDesktop)) {
|
||||
return Workspace.currentDesktop;
|
||||
} else {
|
||||
return kwinClient.desktops[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function isFullScreenGeometry(kwinClient: KwinClient) {
|
||||
const fullScreenArea = Workspace.clientArea(ClientAreaOption.FullScreenArea, kwinClient.output, getKwinDesktopApprox(kwinClient));
|
||||
return kwinClient.frameGeometry === fullScreenArea;
|
||||
}
|
||||
|
||||
export function isOnVirtualDesktop(kwinClient: KwinClient, kwinDesktop: KwinDesktop) {
|
||||
return kwinClient.desktops.length === 0 || kwinClient.desktops.includes(kwinDesktop);
|
||||
}
|
||||
|
||||
export function isOnOneOfVirtualDesktops(kwinClient: KwinClient, kwinDesktops: KwinDesktop[]) {
|
||||
return kwinClient.desktops.length === 0 || kwinClient.desktops.some(d => kwinDesktops.includes(d));
|
||||
}
|
||||
}
|
||||
163
src/lib/world/DesktopManager.ts
Normal file
163
src/lib/world/DesktopManager.ts
Normal file
@@ -0,0 +1,163 @@
|
||||
class DesktopManager {
|
||||
// TODO: fix issue with removed and re-added screens
|
||||
|
||||
private readonly pinManager: PinManager;
|
||||
private readonly config: Desktop.Config;
|
||||
public readonly layoutConfig: LayoutConfig;
|
||||
private readonly desktops: Map<string, Desktop>; // key is activityId|desktopId
|
||||
private kwinScreens: Set<Output>;
|
||||
private kwinActivities: Set<string>;
|
||||
private kwinDesktops: Set<KwinDesktop>;
|
||||
|
||||
constructor(
|
||||
pinManager: PinManager,
|
||||
config: Desktop.Config,
|
||||
layoutConfig: LayoutConfig,
|
||||
currentScreen: Output,
|
||||
currentActivity: string,
|
||||
currentDesktop: KwinDesktop
|
||||
) {
|
||||
this.pinManager = pinManager;
|
||||
this.config = config;
|
||||
this.layoutConfig = layoutConfig;
|
||||
this.desktops = new Map();
|
||||
this.kwinScreens = new Set(Workspace.screens);
|
||||
this.kwinActivities = new Set(Workspace.activities);
|
||||
this.kwinDesktops = new Set(Workspace.desktops);
|
||||
this.addDesktop(currentScreen, currentActivity, currentDesktop);
|
||||
}
|
||||
|
||||
public getDesktop(screen: Output, activity: string, kwinDesktop: KwinDesktop) {
|
||||
const desktopKey = DesktopManager.getDesktopKey(screen, activity, kwinDesktop);
|
||||
const desktop = this.desktops.get(desktopKey);
|
||||
if (desktop !== undefined) {
|
||||
return desktop;
|
||||
} else {
|
||||
return this.addDesktop(screen, activity, kwinDesktop);
|
||||
}
|
||||
}
|
||||
|
||||
public getCurrentDesktop() {
|
||||
return this.getDesktop(Workspace.activeScreen, Workspace.currentActivity, Workspace.currentDesktop);
|
||||
}
|
||||
|
||||
public getDesktopInCurrentActivity(kwinDesktop: KwinDesktop) {
|
||||
return this.getDesktop(Workspace.activeScreen, Workspace.currentActivity, kwinDesktop);
|
||||
}
|
||||
|
||||
public getDesktopForClient(kwinClient: KwinClient) {
|
||||
if (kwinClient.activities.length !== 1 || kwinClient.desktops.length !== 1) {
|
||||
return undefined;
|
||||
}
|
||||
return this.getDesktop(kwinClient.output, kwinClient.activities[0], kwinClient.desktops[0]);
|
||||
}
|
||||
|
||||
private addDesktop(screen: Output, activity: string, kwinDesktop: KwinDesktop) {
|
||||
const desktopKey = DesktopManager.getDesktopKey(screen, activity, kwinDesktop);
|
||||
const desktop = new Desktop(screen, kwinDesktop, this.pinManager, this.config, this.layoutConfig);
|
||||
this.desktops.set(desktopKey, desktop);
|
||||
return desktop;
|
||||
}
|
||||
|
||||
private static getDesktopKey(screen: Output, activity: string, kwinDesktop: KwinDesktop) {
|
||||
return screen.name + "|" + activity + "|" + kwinDesktop.id;
|
||||
}
|
||||
|
||||
public updateScreens() {
|
||||
const newScreens = new Set(Workspace.screens);
|
||||
for (const screen of this.kwinScreens) {
|
||||
if (!newScreens.has(screen)) {
|
||||
this.removeScreen(screen);
|
||||
}
|
||||
}
|
||||
this.kwinScreens = newScreens;
|
||||
}
|
||||
|
||||
public updateActivities() {
|
||||
const newActivities = new Set(Workspace.activities);
|
||||
for (const activity of this.kwinActivities) {
|
||||
if (!newActivities.has(activity)) {
|
||||
this.removeActivity(activity);
|
||||
}
|
||||
}
|
||||
this.kwinActivities = newActivities;
|
||||
}
|
||||
|
||||
public updateDesktops() {
|
||||
const newDesktops = new Set(Workspace.desktops);
|
||||
for (const desktop of this.kwinDesktops) {
|
||||
if (!newDesktops.has(desktop)) {
|
||||
this.removeKwinDesktop(desktop);
|
||||
}
|
||||
}
|
||||
this.kwinDesktops = newDesktops;
|
||||
}
|
||||
|
||||
private removeScreen(kwinScreen: Output) {
|
||||
for (const activity of this.kwinActivities) {
|
||||
for (const kwinDesktop of this.kwinDesktops) {
|
||||
this.destroyDesktop(kwinScreen, activity, kwinDesktop);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private removeActivity(activity: string) {
|
||||
for (const kwinScreen of this.kwinScreens) {
|
||||
for (const kwinDesktop of this.kwinDesktops) {
|
||||
this.destroyDesktop(kwinScreen, activity, kwinDesktop);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private removeKwinDesktop(kwinDesktop: KwinDesktop) {
|
||||
for (const kwinScreen of this.kwinScreens) {
|
||||
for (const activity of this.kwinActivities) {
|
||||
this.destroyDesktop(kwinScreen, activity, kwinDesktop);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private destroyDesktop(screen: Output, activity: string, kwinDesktop: KwinDesktop) {
|
||||
const desktopKey = DesktopManager.getDesktopKey(screen, activity, kwinDesktop);
|
||||
const desktop = this.desktops.get(desktopKey);
|
||||
if (desktop !== undefined) {
|
||||
desktop.destroy();
|
||||
this.desktops.delete(desktopKey);
|
||||
}
|
||||
}
|
||||
|
||||
public destroy() {
|
||||
for (const desktop of this.desktops.values()) {
|
||||
desktop.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
public *getAllDesktops() {
|
||||
for (const desktop of this.desktops.values()) {
|
||||
yield desktop;
|
||||
}
|
||||
}
|
||||
|
||||
public getDesktopsForClient(kwinClient: KwinClient) {
|
||||
const desktops = this.getDesktops([kwinClient.output], kwinClient.activities, kwinClient.desktops); // workaround for QTBUG-109880
|
||||
return desktops;
|
||||
}
|
||||
|
||||
// empty array means all
|
||||
public *getDesktops(screens: Output[], activities: string[], kwinDesktops: KwinDesktop[]) {
|
||||
const matchedScreens = screens.length > 0 ? screens : this.kwinScreens.keys();
|
||||
const matchedActivities = activities.length > 0 ? activities : this.kwinActivities.keys();
|
||||
const matchedDesktops = kwinDesktops.length > 0 ? kwinDesktops : this.kwinDesktops.keys();
|
||||
for (const matchedScreen of matchedScreens) {
|
||||
for (const matchedActivity of matchedActivities) {
|
||||
for (const matchedDesktop of matchedDesktops) {
|
||||
const desktopKey = DesktopManager.getDesktopKey(matchedScreen, matchedActivity, matchedDesktop);
|
||||
const desktop = this.desktops.get(desktopKey);
|
||||
if (desktop !== undefined) {
|
||||
yield desktop;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
class PinManager {
|
||||
// TODO: per-screen
|
||||
|
||||
private readonly pinnedClients: Set<KwinClient>;
|
||||
|
||||
constructor() {
|
||||
@@ -13,11 +15,11 @@ class PinManager {
|
||||
this.pinnedClients.delete(kwinClient);
|
||||
}
|
||||
|
||||
public getAvailableSpace(desktopNumber: number, screen: QmlRect) {
|
||||
public getAvailableSpace(kwinDesktop: KwinDesktop, screen: QmlRect) {
|
||||
const baseLot = new PinManager.Lot(screen.top, screen.bottom, screen.left, screen.right);
|
||||
let lots = [baseLot];
|
||||
for (const client of this.pinnedClients) {
|
||||
if (!Clients.isOnVirtualDesktop(client, desktopNumber)) {
|
||||
if (!Clients.isOnVirtualDesktop(client, kwinDesktop)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -4,16 +4,21 @@ class World {
|
||||
public readonly clientManager: ClientManager;
|
||||
private readonly pinManager: PinManager;
|
||||
private readonly workspaceSignalManager: SignalManager;
|
||||
private readonly shortcutActions: ShortcutAction[];
|
||||
private readonly screenResizedDelayer: Delayer;
|
||||
|
||||
constructor(config: Config) {
|
||||
this.untileOnDrag = config.untileOnDrag;
|
||||
this.workspaceSignalManager = initWorkspaceSignalHandlers(this);
|
||||
this.shortcutActions = registerKeyBindings(this, {
|
||||
manualScrollStep: config.manualScrollStep,
|
||||
manualResizeStep: config.manualResizeStep,
|
||||
columnResizer: config.scrollingCentered ? new RawResizer() : new ContextualResizer(),
|
||||
});
|
||||
|
||||
this.screenResizedDelayer = new Delayer(1000, () => {
|
||||
// this delay ensures that docks are taken into account by `workspace.clientArea`
|
||||
const desktopManager = this.desktopManager; // workaround for bug in Qt5's JS engine
|
||||
for (const desktop of desktopManager.desktops()) {
|
||||
// this delay ensures that docks are taken into account by `Workspace.clientArea`
|
||||
for (const desktop of this.desktopManager.getAllDesktops()) {
|
||||
desktop.onLayoutChanged();
|
||||
}
|
||||
this.update();
|
||||
@@ -40,32 +45,40 @@ class World {
|
||||
marginBottom: config.gapsOuterBottom,
|
||||
marginLeft: config.gapsOuterLeft,
|
||||
marginRight: config.gapsOuterRight,
|
||||
scroller: config.scrollingLazy ? new LazyScroller() :
|
||||
config.scrollingCentered ? new CenteredScroller() :
|
||||
config.scrollingGrouped ? new GroupedScroller() :
|
||||
console.assert(false),
|
||||
scroller: World.createScroller(config),
|
||||
clamper: config.scrollingLazy ? new EdgeClamper() : new CenterClamper(),
|
||||
},
|
||||
layoutConfig,
|
||||
workspace.currentActivity,
|
||||
Workspace.activeScreen,
|
||||
Workspace.currentActivity,
|
||||
Workspace.currentDesktop,
|
||||
);
|
||||
this.clientManager = new ClientManager(config, this, this.desktopManager, this.pinManager);
|
||||
this.addExistingClients();
|
||||
this.update();
|
||||
}
|
||||
|
||||
private static createScroller(config: Config) {
|
||||
if (config.scrollingLazy) {
|
||||
return new LazyScroller();
|
||||
} else if (config.scrollingCentered) {
|
||||
return new CenteredScroller();
|
||||
} else if (config.scrollingGrouped) {
|
||||
return new GroupedScroller();
|
||||
} else {
|
||||
log("No scrolling mode selected, using default");
|
||||
return new LazyScroller();
|
||||
}
|
||||
}
|
||||
|
||||
private addExistingClients() {
|
||||
const kwinClients = workspace.clientList();
|
||||
const kwinClients = Workspace.windows;
|
||||
for (let i = 0; i < kwinClients.length; i++) {
|
||||
const kwinClient = kwinClients[i];
|
||||
this.clientManager.addClient(kwinClient);
|
||||
}
|
||||
}
|
||||
|
||||
public updateDesktops() {
|
||||
this.desktopManager.update();
|
||||
}
|
||||
|
||||
private update() {
|
||||
this.desktopManager.getCurrentDesktop().arrange();
|
||||
}
|
||||
@@ -94,11 +107,14 @@ class World {
|
||||
followTransient: boolean,
|
||||
f: (clientManager: ClientManager, desktopManager: DesktopManager, window: Window, column: Column, grid: Grid) => void,
|
||||
) {
|
||||
this.doIfTiled(workspace.activeClient, followTransient, f);
|
||||
this.doIfTiled(Workspace.activeWindow, followTransient, f);
|
||||
}
|
||||
|
||||
public destroy() {
|
||||
this.workspaceSignalManager.destroy();
|
||||
for (const shortcutAction of this.shortcutActions) {
|
||||
shortcutAction.destroy();
|
||||
}
|
||||
this.clientManager.destroy();
|
||||
this.desktopManager.destroy();
|
||||
}
|
||||
@@ -16,7 +16,7 @@ namespace ClientState {
|
||||
|
||||
private static initSignalManager(world: World, kwinClient: KwinClient) {
|
||||
const manager = new SignalManager();
|
||||
manager.connect(kwinClient.frameGeometryChanged, (kwinClient: KwinClient, oldGeometry: QmlRect) => {
|
||||
manager.connect(kwinClient.frameGeometryChanged, () => {
|
||||
world.onScreenResized();
|
||||
});
|
||||
return manager;
|
||||
@@ -24,7 +24,11 @@ namespace ClientState {
|
||||
}
|
||||
|
||||
private static limitHeight(client: ClientWrapper) {
|
||||
const placementArea = workspace.clientArea(ClientAreaOption.PlacementArea, client.kwinClient.screen, client.kwinClient.desktop);
|
||||
const placementArea = Workspace.clientArea(
|
||||
ClientAreaOption.PlacementArea,
|
||||
client.kwinClient.output,
|
||||
Clients.getKwinDesktopApprox(client.kwinClient),
|
||||
);
|
||||
const clientRect = client.kwinClient.frameGeometry;
|
||||
const width = client.preferredWidth;
|
||||
client.place(
|
||||
@@ -30,8 +30,8 @@ namespace ClientState {
|
||||
|
||||
private static initSignalManager(world: World, pinManager: PinManager, kwinClient: KwinClient) {
|
||||
const manager = new SignalManager();
|
||||
let oldDesktopNumber = kwinClient.desktop;
|
||||
let oldActivities = kwinClient.activities;
|
||||
let oldDesktops = kwinClient.desktops;
|
||||
|
||||
manager.connect(kwinClient.tileChanged, () => {
|
||||
if (kwinClient.tile === null) {
|
||||
@@ -41,7 +41,7 @@ namespace ClientState {
|
||||
}
|
||||
});
|
||||
|
||||
manager.connect(kwinClient.frameGeometryChanged, (kwinClient: KwinClient, oldGeometry: QmlRect) => {
|
||||
manager.connect(kwinClient.frameGeometryChanged, () => {
|
||||
if (kwinClient.tile === null) {
|
||||
world.do((clientManager, desktopManager) => {
|
||||
clientManager.unpinClient(kwinClient);
|
||||
@@ -56,31 +56,38 @@ namespace ClientState {
|
||||
})
|
||||
});
|
||||
|
||||
manager.connect(kwinClient.desktopChanged, () => {
|
||||
const changedDesktops = oldDesktopNumber === -1 || kwinClient.desktop === -1 ?
|
||||
manager.connect(kwinClient.desktopsChanged, () => {
|
||||
const changedDesktops = oldDesktops.length === 0 || kwinClient.desktops.length === 0 ?
|
||||
[] :
|
||||
[oldDesktopNumber, kwinClient.desktop];
|
||||
union(oldDesktops, kwinClient.desktops);
|
||||
world.do((clientManager, desktopManager) => {
|
||||
for (const desktop of desktopManager.getDesktops(changedDesktops, kwinClient.activities)) {
|
||||
for (const desktop of desktopManager.getDesktops([kwinClient.output], kwinClient.activities, changedDesktops)) {
|
||||
desktop.onPinsChanged();
|
||||
}
|
||||
});
|
||||
oldDesktopNumber = kwinClient.desktop;
|
||||
oldDesktops = kwinClient.desktops;
|
||||
});
|
||||
|
||||
manager.connect(kwinClient.activitiesChanged, () => {
|
||||
const desktops = kwinClient.desktop === -1 ? [] : [kwinClient.desktop];
|
||||
const changedActivities = oldActivities.length === 0 || kwinClient.activities.length === 0 ?
|
||||
[] :
|
||||
union(oldActivities, kwinClient.activities);
|
||||
world.do((clientManager, desktopManager) => {
|
||||
for (const desktop of desktopManager.getDesktops(desktops, changedActivities)) {
|
||||
for (const desktop of desktopManager.getDesktops([kwinClient.output], changedActivities, kwinClient.desktops)) {
|
||||
desktop.onPinsChanged();
|
||||
}
|
||||
});
|
||||
oldActivities = kwinClient.activities;
|
||||
});
|
||||
|
||||
manager.connect(kwinClient.outputChanged, () => {
|
||||
world.do((clientManager, desktopManager) => {
|
||||
for (const desktop of desktopManager.getDesktops([kwinClient.output], kwinClient.activities, kwinClient.desktops)) {
|
||||
desktop.onPinsChanged();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return manager;
|
||||
}
|
||||
}
|
||||
@@ -31,12 +31,12 @@ namespace ClientState {
|
||||
const kwinClient = client.kwinClient;
|
||||
const manager = new SignalManager();
|
||||
|
||||
manager.connect(kwinClient.desktopChanged, () => {
|
||||
manager.connect(kwinClient.desktopsChanged, () => {
|
||||
world.do((clientManager, desktopManager) => {
|
||||
const desktop = desktopManager.getDesktopForClient(kwinClient);
|
||||
if (desktop === undefined) {
|
||||
// windows on all desktops are not supported
|
||||
clientManager.untileClient(kwinClient);
|
||||
// windows on multiple desktops are not supported
|
||||
clientManager.floatKwinClient(kwinClient);
|
||||
return;
|
||||
}
|
||||
Tiled.moveWindowToGrid(window, desktop.grid);
|
||||
@@ -48,44 +48,54 @@ namespace ClientState {
|
||||
const desktop = desktopManager.getDesktopForClient(kwinClient);
|
||||
if (desktop === undefined) {
|
||||
// windows on multiple activities are not supported
|
||||
clientManager.untileClient(kwinClient);
|
||||
clientManager.floatKwinClient(kwinClient);
|
||||
return;
|
||||
}
|
||||
Tiled.moveWindowToGrid(window, desktop.grid);
|
||||
});
|
||||
})
|
||||
|
||||
let lastResize = false;
|
||||
manager.connect(kwinClient.moveResizedChanged, () => {
|
||||
manager.connect(kwinClient.minimizedChanged, () => {
|
||||
console.assert(kwinClient.minimized);
|
||||
world.do((clientManager, desktopManager) => {
|
||||
if (kwinClient.move) {
|
||||
if (world.untileOnDrag) {
|
||||
clientManager.untileClient(kwinClient);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const grid = window.column.grid;
|
||||
const resize = kwinClient.resize;
|
||||
if (!lastResize && resize) {
|
||||
grid.onUserResizeStarted();
|
||||
}
|
||||
if (lastResize && !resize) {
|
||||
grid.onUserResizeFinished();
|
||||
}
|
||||
lastResize = resize;
|
||||
clientManager.minimizeClient(kwinClient);
|
||||
});
|
||||
});
|
||||
|
||||
let cursorChangedAfterResizeStart = false;
|
||||
manager.connect(kwinClient.moveResizeCursorChanged, () => {
|
||||
cursorChangedAfterResizeStart = true;
|
||||
});
|
||||
manager.connect(kwinClient.clientStartUserMovedResized, () => {
|
||||
cursorChangedAfterResizeStart = false;
|
||||
manager.connect(kwinClient.maximizedAboutToChange, (maximizedMode: MaximizedMode) => {
|
||||
world.do(() => {
|
||||
window.onMaximizedChanged(maximizedMode);
|
||||
});
|
||||
});
|
||||
|
||||
manager.connect(kwinClient.frameGeometryChanged, (kwinClient: KwinClient, oldGeometry: QmlRect) => {
|
||||
let resizing = false;
|
||||
let resizingBorder = false;
|
||||
manager.connect(kwinClient.interactiveMoveResizeStarted, () => {
|
||||
if (kwinClient.move) {
|
||||
if (world.untileOnDrag) {
|
||||
world.do((clientManager, desktopManager) => {
|
||||
clientManager.floatKwinClient(kwinClient);
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (kwinClient.resize) {
|
||||
resizing = true;
|
||||
resizingBorder = Workspace.cursorPos.x > kwinClient.clientGeometry.right ||
|
||||
Workspace.cursorPos.x < kwinClient.clientGeometry.left;
|
||||
window.column.grid.onUserResizeStarted();
|
||||
}
|
||||
});
|
||||
|
||||
manager.connect(kwinClient.interactiveMoveResizeFinished, () => {
|
||||
if (resizing) {
|
||||
resizing = false;
|
||||
window.column.grid.onUserResizeFinished();
|
||||
}
|
||||
});
|
||||
|
||||
manager.connect(kwinClient.frameGeometryChanged, (oldGeometry: QmlRect) => {
|
||||
// on Wayland, this fires after `tileChanged`
|
||||
if (kwinClient.tile !== null) {
|
||||
world.do((clientManager, desktopManager) => {
|
||||
@@ -106,11 +116,11 @@ namespace ClientState {
|
||||
}
|
||||
|
||||
if (kwinClient.resize) {
|
||||
world.do(() => window.onUserResize(oldGeometry, !cursorChangedAfterResizeStart));
|
||||
world.do(() => window.onUserResize(oldGeometry, resizingBorder));
|
||||
} else if (
|
||||
!window.column.grid.isUserResizing() &&
|
||||
!client.isManipulatingGeometry(newGeometry) &&
|
||||
!Clients.isMaximizedGeometry(kwinClient) &&
|
||||
client.getMaximizedMode() === MaximizedMode.Unmaximized &&
|
||||
!Clients.isFullScreenGeometry(kwinClient) // not using `kwinClient.fullScreen` because it may not be set yet at this point
|
||||
) {
|
||||
world.do(() => window.onFrameGeometryChanged());
|
||||
@@ -164,6 +174,9 @@ namespace ClientState {
|
||||
if (config.tiledKeepBelow) {
|
||||
client.kwinClient.keepBelow = false;
|
||||
}
|
||||
if (config.offScreenOpacity < 1.0) {
|
||||
client.kwinClient.opacity = 1.0;
|
||||
}
|
||||
client.setShade(false);
|
||||
client.setFullScreen(false);
|
||||
if (client.kwinClient.tile === null) {
|
||||
31
src/lib/world/clientState/TiledMinimized.ts
Normal file
31
src/lib/world/clientState/TiledMinimized.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
namespace ClientState {
|
||||
export class TiledMinimized implements State {
|
||||
private readonly signalManager: SignalManager;
|
||||
|
||||
constructor(world: World, client: ClientWrapper) {
|
||||
this.signalManager = TiledMinimized.initSignalManager(world, client);
|
||||
}
|
||||
|
||||
public destroy(passFocus: boolean) {
|
||||
this.signalManager.destroy();
|
||||
}
|
||||
|
||||
private static initSignalManager(world: World, client: ClientWrapper) {
|
||||
const manager = new SignalManager();
|
||||
|
||||
manager.connect(client.kwinClient.minimizedChanged, () => {
|
||||
console.assert(!client.kwinClient.minimized);
|
||||
world.do((clientManager, desktopManager) => {
|
||||
const desktop = desktopManager.getDesktopForClient(client.kwinClient);
|
||||
if (desktop !== undefined) {
|
||||
clientManager.tileClient(client, desktop.grid);
|
||||
} else {
|
||||
clientManager.floatClient(client);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return manager;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
function init() {
|
||||
const config = loadConfig();
|
||||
const world = new World(config);
|
||||
registerKeyBindings(world, config);
|
||||
return world;
|
||||
}
|
||||
3
src/main/main.ts
Normal file
3
src/main/main.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
function init() {
|
||||
return new World(loadConfig());
|
||||
}
|
||||
4
src/main/tsconfig.json
Normal file
4
src/main/tsconfig.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"extends": "../tsconfig.json",
|
||||
"include": ["../lib/**/*", "./**/*"]
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
class ClientMatcher {
|
||||
private readonly rules: Map<string, RegExp>;
|
||||
|
||||
constructor(rules: Map<string, RegExp>) {
|
||||
this.rules = rules;
|
||||
}
|
||||
|
||||
public matches(kwinClient: KwinClient) {
|
||||
const rule = this.rules.get(kwinClient.resourceClass);
|
||||
if (rule === undefined) {
|
||||
return false;
|
||||
}
|
||||
return rule.test(kwinClient.caption);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
type WindowRule = {
|
||||
class: string,
|
||||
caption: string,
|
||||
tile: boolean,
|
||||
};
|
||||
@@ -1,90 +0,0 @@
|
||||
class WindowRuleEnforcer {
|
||||
private readonly preferFloating: ClientMatcher;
|
||||
private readonly preferTiling: ClientMatcher;
|
||||
private readonly followCaption: Set<string>;
|
||||
|
||||
constructor(windowRules: WindowRule[]) {
|
||||
const [mapFloat, mapTile] = WindowRuleEnforcer.createWindowRuleMaps(windowRules);
|
||||
this.preferFloating = new ClientMatcher(mapFloat);
|
||||
this.preferTiling = new ClientMatcher(mapTile);
|
||||
this.followCaption = new Set([...mapFloat.keys(), ...mapTile.keys()]);
|
||||
}
|
||||
|
||||
public shouldTile(kwinClient: KwinClient) {
|
||||
return Clients.canTileNow(kwinClient) && (
|
||||
this.preferTiling.matches(kwinClient) || (
|
||||
kwinClient.normalWindow &&
|
||||
!kwinClient.transient &&
|
||||
kwinClient.managed &&
|
||||
!this.preferFloating.matches(kwinClient)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public initClientSignalManager(world: World, kwinClient: KwinClient) {
|
||||
if (!this.followCaption.has(kwinClient.resourceClass)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const enforcer = this;
|
||||
const manager = new SignalManager();
|
||||
manager.connect(kwinClient.captionChanged, () => {
|
||||
const shouldTile = enforcer.shouldTile(kwinClient);
|
||||
world.do((clientManager, desktopManager) => {
|
||||
const desktop = desktopManager.getDesktopForClient(kwinClient);
|
||||
if (shouldTile && desktop !== undefined) {
|
||||
clientManager.tileClient(kwinClient, desktop.grid);
|
||||
} else {
|
||||
clientManager.untileClient(kwinClient);
|
||||
}
|
||||
});
|
||||
});
|
||||
return manager;
|
||||
}
|
||||
|
||||
private static createWindowRuleMaps(windowRules: WindowRule[]) {
|
||||
const mapFloat = new Map<string, string[]>();
|
||||
const mapTile = new Map<string, string[]>();
|
||||
for (const windowRule of windowRules) {
|
||||
const map = windowRule.tile ? mapTile : mapFloat;
|
||||
let captions = map.get(windowRule.class);
|
||||
if (captions === undefined) {
|
||||
captions = [];
|
||||
map.set(windowRule.class, captions);
|
||||
}
|
||||
if (windowRule.caption !== undefined) {
|
||||
captions.push(windowRule.caption);
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
WindowRuleEnforcer.createWindowRuleRegexMap(mapFloat),
|
||||
WindowRuleEnforcer.createWindowRuleRegexMap(mapTile),
|
||||
];
|
||||
}
|
||||
|
||||
private static createWindowRuleRegexMap(windowRuleMap: Map<string, string[]>) {
|
||||
const regexMap = new Map<string, RegExp>;
|
||||
for (const [k, v] of windowRuleMap) {
|
||||
regexMap.set(k, WindowRuleEnforcer.joinRegexes(v));
|
||||
}
|
||||
return regexMap;
|
||||
}
|
||||
|
||||
private static joinRegexes(regexes: string[]) {
|
||||
if (regexes.length === 0) {
|
||||
return new RegExp("");
|
||||
}
|
||||
|
||||
if (regexes.length === 1) {
|
||||
return new RegExp("^" + regexes[0] + "$");
|
||||
}
|
||||
|
||||
const joinedRegexes = regexes.map(WindowRuleEnforcer.wrapParens).join("|");
|
||||
return new RegExp("^" + joinedRegexes + "$");
|
||||
}
|
||||
|
||||
private static wrapParens(str: string) {
|
||||
return "(" + str + ")";
|
||||
}
|
||||
}
|
||||
36
src/tests/rules/WindowRuleEnforcer.ts
Normal file
36
src/tests/rules/WindowRuleEnforcer.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
{
|
||||
const testCases = [
|
||||
{tiledByDefault: true, resourceClass: "unknown", caption: "anything", shouldTile: true},
|
||||
{tiledByDefault: false, resourceClass: "unknown", caption: "anything", shouldTile: false},
|
||||
{tiledByDefault: true, resourceClass: "ksmserver-logout-greeter", caption: "anything", shouldTile: false},
|
||||
{tiledByDefault: true, resourceClass: "org.kde.plasmashell", caption: "something", shouldTile: false},
|
||||
{tiledByDefault: true, resourceClass: "plasmashell", caption: "something", shouldTile: false},
|
||||
{tiledByDefault: false, resourceClass: "org.kde.kfind", caption: "something", shouldTile: true},
|
||||
{tiledByDefault: false, resourceClass: "kfind", caption: "something", shouldTile: true},
|
||||
{tiledByDefault: true, resourceClass: "zoom", caption: "something", shouldTile: true},
|
||||
{tiledByDefault: true, resourceClass: "zoom", caption: "zoom", shouldTile: false},
|
||||
];
|
||||
|
||||
const enforcer = new WindowRuleEnforcer(JSON.parse(defaultWindowRules));
|
||||
for (const testCase of testCases) {
|
||||
const kwinClient: any = createKwinClient(testCase.tiledByDefault, testCase.resourceClass, testCase.caption);
|
||||
assert(enforcer.shouldTile(kwinClient) === testCase.shouldTile, "failed case: " + JSON.stringify(testCase));
|
||||
}
|
||||
|
||||
function createKwinClient(normalWindow: boolean, resoureClass: string, caption: string) {
|
||||
return {
|
||||
normalWindow: normalWindow,
|
||||
transient: false,
|
||||
managed: true,
|
||||
pid: 100,
|
||||
moveable: true,
|
||||
resizeable: true,
|
||||
popupWindow: false,
|
||||
minimized: false,
|
||||
desktops: [1],
|
||||
activities: [1],
|
||||
resourceClass: resoureClass,
|
||||
caption: caption,
|
||||
}
|
||||
}
|
||||
}
|
||||
17
src/tests/tests.ts
Normal file
17
src/tests/tests.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
declare const process: {
|
||||
exit(code?: number): void,
|
||||
};
|
||||
|
||||
function assert(assertion: boolean, message?: string) {
|
||||
if (assertion) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (message != undefined) {
|
||||
console.assert(assertion, message);
|
||||
} else {
|
||||
console.assert(assertion);
|
||||
}
|
||||
console.trace();
|
||||
process.exit(1);
|
||||
}
|
||||
4
src/tests/tsconfig.json
Normal file
4
src/tests/tsconfig.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"extends": "../tsconfig.json",
|
||||
"include": ["../lib/**/*", "./**/*"]
|
||||
}
|
||||
12
src/tsconfig.json
Normal file
12
src/tsconfig.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es2020",
|
||||
"lib": ["es2020"],
|
||||
"module": "none",
|
||||
"allowJs": false,
|
||||
"esModuleInterop": false,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"strict": true,
|
||||
"skipLibCheck": true
|
||||
}
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
function initWorkspaceSignalHandlers(world: World) {
|
||||
const manager = new SignalManager();
|
||||
|
||||
manager.connect(workspace.clientAdded, (kwinClient: KwinClient) => {
|
||||
if (Clients.canTileEver(kwinClient)) {
|
||||
// never open new tileable clients on all desktops or activities
|
||||
if (kwinClient.desktop <= 0) {
|
||||
kwinClient.desktop = workspace.currentDesktop;
|
||||
}
|
||||
if (kwinClient.activities.length !== 1) {
|
||||
kwinClient.activities = [workspace.currentActivity];
|
||||
}
|
||||
}
|
||||
world.do((clientManager, desktopManager) => {
|
||||
clientManager.addClient(kwinClient)
|
||||
});
|
||||
});
|
||||
|
||||
manager.connect(workspace.clientRemoved, (kwinClient: KwinClient) => {
|
||||
world.do((clientManager, desktopManager) => {
|
||||
clientManager.removeClient(kwinClient, true);
|
||||
});
|
||||
});
|
||||
|
||||
manager.connect(workspace.clientMinimized, (kwinClient: KwinClient) => {
|
||||
world.do((clientManager, desktopManager) => {
|
||||
clientManager.minimizeClient(kwinClient);
|
||||
});
|
||||
});
|
||||
|
||||
manager.connect(workspace.clientUnminimized, (kwinClient: KwinClient) => {
|
||||
world.do((clientManager, desktopManager) => {
|
||||
clientManager.unminimizeClient(kwinClient);
|
||||
});
|
||||
});
|
||||
|
||||
manager.connect(workspace.clientMaximizeSet, (kwinClient: KwinClient, horizontally: boolean, vertically: boolean) => {
|
||||
if ((horizontally || vertically) && kwinClient.tile !== null) {
|
||||
kwinClient.tile = null;
|
||||
}
|
||||
world.doIfTiled(kwinClient, false, (clientManager, desktopManager, window, column, grid) => {
|
||||
window.onMaximizedChanged(horizontally, vertically);
|
||||
});
|
||||
});
|
||||
|
||||
manager.connect(workspace.clientActivated, (kwinClient: KwinClient) => {
|
||||
if (kwinClient === null) {
|
||||
return;
|
||||
}
|
||||
world.do((clientManager, desktopManager) => {
|
||||
clientManager.onClientFocused(kwinClient);
|
||||
});
|
||||
});
|
||||
|
||||
manager.connect(workspace.currentDesktopChanged, () => {
|
||||
world.do(() => {}); // re-arrange desktop
|
||||
});
|
||||
|
||||
manager.connect(workspace.currentActivityChanged, () => {
|
||||
world.do(() => {}); // re-arrange desktop
|
||||
});
|
||||
|
||||
manager.connect(workspace.numberDesktopsChanged, () => {
|
||||
world.updateDesktops();
|
||||
});
|
||||
|
||||
manager.connect(workspace.virtualScreenSizeChanged, () => {
|
||||
world.onScreenResized();
|
||||
});
|
||||
|
||||
return manager;
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
namespace Clients {
|
||||
export function canTileEver(kwinClient: KwinClient) {
|
||||
return kwinClient.resizeable;
|
||||
}
|
||||
|
||||
export function canTileNow(kwinClient: KwinClient) {
|
||||
return canTileEver(kwinClient) && !kwinClient.minimized && kwinClient.desktop > 0 && kwinClient.activities.length === 1;
|
||||
}
|
||||
|
||||
export function makeTileable(kwinClient: KwinClient) {
|
||||
if (kwinClient.minimized) {
|
||||
kwinClient.minimized = false;
|
||||
}
|
||||
if (kwinClient.desktop <= 0) {
|
||||
kwinClient.desktop = workspace.currentDesktop;
|
||||
}
|
||||
if (kwinClient.activities.length !== 1) {
|
||||
kwinClient.activities = [workspace.currentActivity];
|
||||
}
|
||||
}
|
||||
|
||||
export function isMaximizedGeometry(kwinClient: KwinClient) {
|
||||
const maximizeArea = workspace.clientArea(ClientAreaOption.MaximizeArea, kwinClient.screen, kwinClient.desktop);
|
||||
return kwinClient.frameGeometry === maximizeArea;
|
||||
}
|
||||
|
||||
export function isFullScreenGeometry(kwinClient: KwinClient) {
|
||||
const fullScreenArea = workspace.clientArea(ClientAreaOption.FullScreenArea, kwinClient.screen, kwinClient.desktop);
|
||||
return kwinClient.frameGeometry === fullScreenArea;
|
||||
}
|
||||
|
||||
export function isOnVirtualDesktop(kwinClient: KwinClient, desktopNumber: number) {
|
||||
return kwinClient.desktop === desktopNumber || kwinClient.desktop === -1;
|
||||
}
|
||||
}
|
||||
@@ -1,149 +0,0 @@
|
||||
class DesktopManager {
|
||||
private readonly pinManager: PinManager;
|
||||
private readonly config: Desktop.Config;
|
||||
public readonly layoutConfig: LayoutConfig;
|
||||
private readonly desktopsPerActivity: Map<string, Desktop[]>;
|
||||
private nVirtualDesktops: number;
|
||||
|
||||
constructor(pinManager: PinManager, config: Desktop.Config, layoutConfig: LayoutConfig, currentActivity: string) {
|
||||
this.pinManager = pinManager;
|
||||
this.config = config;
|
||||
this.layoutConfig = layoutConfig;
|
||||
this.desktopsPerActivity = new Map();
|
||||
this.nVirtualDesktops = 0;
|
||||
this.update()
|
||||
this.addActivity(currentActivity);
|
||||
}
|
||||
|
||||
public update() {
|
||||
this.setNVirtualDesktops(workspace.desktops);
|
||||
}
|
||||
|
||||
public getDesktop(activity: string, desktopNumber: number) {
|
||||
const desktopIndex = desktopNumber - 1;
|
||||
if (desktopIndex >= this.nVirtualDesktops || desktopIndex < 0) {
|
||||
throw new Error("invalid desktop number: " + String(desktopNumber));
|
||||
}
|
||||
if (!this.desktopsPerActivity.has(activity)) {
|
||||
this.addActivity(activity);
|
||||
}
|
||||
return this.desktopsPerActivity.get(activity)![desktopIndex];
|
||||
}
|
||||
|
||||
public getCurrentDesktop() {
|
||||
return this.getDesktop(workspace.currentActivity, workspace.currentDesktop);
|
||||
}
|
||||
|
||||
public getDesktopInCurrentActivity(desktopNumber: number) {
|
||||
return this.getDesktop(workspace.currentActivity, desktopNumber);
|
||||
}
|
||||
|
||||
public getDesktopForClient(kwinClient: KwinClient) {
|
||||
if (kwinClient.activities.length !== 1 && kwinClient.desktop === 0) {
|
||||
return undefined;
|
||||
}
|
||||
return this.getDesktop(kwinClient.activities[0], kwinClient.desktop);
|
||||
}
|
||||
|
||||
private setNVirtualDesktops(nVirtualDesktops: number) {
|
||||
if (nVirtualDesktops > this.nVirtualDesktops) {
|
||||
this.addDesktopsToActivities(nVirtualDesktops - this.nVirtualDesktops);
|
||||
} else if (nVirtualDesktops < this.nVirtualDesktops) {
|
||||
this.removeDesktopsFromActivities(this.nVirtualDesktops - nVirtualDesktops);
|
||||
}
|
||||
this.nVirtualDesktops = nVirtualDesktops;
|
||||
}
|
||||
|
||||
private addDesktopsToActivities(n: number) {
|
||||
for (const desktops of this.desktopsPerActivity.values()) {
|
||||
this.addDesktops(desktops, n);
|
||||
}
|
||||
}
|
||||
|
||||
private addDesktops(desktops: Desktop[], n: number) {
|
||||
const nStart = desktops.length;
|
||||
for (let i = 0; i < n; i++) {
|
||||
const desktopNumber = nStart + i + 1;
|
||||
desktops.push(new Desktop(desktopNumber, this.pinManager, this.config, this.layoutConfig));
|
||||
}
|
||||
}
|
||||
|
||||
private removeDesktopsFromActivities(n: number) {
|
||||
const lastRemainingDesktopIndex = this.nVirtualDesktops - n - 1;
|
||||
for (const desktops of this.desktopsPerActivity.values()) {
|
||||
const targetDesktop = desktops[lastRemainingDesktopIndex];
|
||||
for (let i = 0; i < n; i++) {
|
||||
const removedDesktop = desktops.pop()!;
|
||||
removedDesktop.grid.evacuate(targetDesktop.grid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private addActivity(activity: string) {
|
||||
const desktops: Desktop[] = [];
|
||||
this.addDesktops(desktops, this.nVirtualDesktops);
|
||||
this.desktopsPerActivity.set(activity, desktops);
|
||||
}
|
||||
|
||||
private removeActivity(activity: string) {
|
||||
const removedDesktops = this.desktopsPerActivity.get(activity)!;
|
||||
this.desktopsPerActivity.delete(activity);
|
||||
const targetActivityDesktops = this.desktopsPerActivity.values().next().value;
|
||||
for (let i = 0; i < removedDesktops.length; i++) {
|
||||
removedDesktops[i].grid.evacuate(targetActivityDesktops[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public destroy() {
|
||||
for (const desktop of this.desktops()) {
|
||||
desktop.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
public *desktops() {
|
||||
for (const desktops of this.desktopsPerActivity.values()) {
|
||||
for (const desktop of desktops) {
|
||||
yield desktop;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public *getDesktopsForClient(kwinClient: KwinClient) {
|
||||
const activities = kwinClient.activities.length > 0 ? kwinClient.activities : this.desktopsPerActivity.keys();
|
||||
for (const activity of activities) {
|
||||
if (!this.desktopsPerActivity.has(activity)) {
|
||||
this.addActivity(activity);
|
||||
}
|
||||
const activityDesktops = this.desktopsPerActivity.get(activity)!;
|
||||
if (kwinClient.desktop === -1) {
|
||||
for (const desktop of activityDesktops) {
|
||||
yield desktop;
|
||||
}
|
||||
} else {
|
||||
const desktopIndex = kwinClient.desktop - 1;
|
||||
yield activityDesktops[desktopIndex];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// empty array means all
|
||||
public *getDesktops(desktopNumbers: number[], inputActivities: string[]) {
|
||||
const activities = inputActivities.length > 0 ? inputActivities : this.desktopsPerActivity.keys();
|
||||
for (const activity of activities) {
|
||||
if (!this.desktopsPerActivity.has(activity)) {
|
||||
this.addActivity(activity);
|
||||
}
|
||||
const activityDesktops = this.desktopsPerActivity.get(activity)!;
|
||||
if (desktopNumbers.length === 0) {
|
||||
for (const desktop of activityDesktops) {
|
||||
yield desktop;
|
||||
}
|
||||
} else {
|
||||
for (const desktopNumber of desktopNumbers) {
|
||||
const desktopIndex = desktopNumber - 1;
|
||||
yield activityDesktops[desktopIndex];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
namespace ClientState {
|
||||
export class TiledMinimized implements State {
|
||||
public destroy(passFocus: boolean) {}
|
||||
}
|
||||
}
|
||||
108
tsconfig.json
108
tsconfig.json
@@ -1,108 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
/* Visit https://aka.ms/tsconfig to read more about this file */
|
||||
|
||||
/* Projects */
|
||||
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
|
||||
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
|
||||
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
|
||||
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
|
||||
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
|
||||
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
||||
|
||||
/* Language and Environment */
|
||||
"target": "es2020", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
|
||||
"lib": [
|
||||
"es2020",
|
||||
], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
||||
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
||||
// "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
|
||||
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
|
||||
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
|
||||
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
|
||||
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
|
||||
// "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
|
||||
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
|
||||
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
|
||||
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
|
||||
|
||||
/* Modules */
|
||||
"module": "none", /* Specify what module code is generated. */
|
||||
"rootDir": "./src", /* Specify the root folder within your source files. */
|
||||
// "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
|
||||
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
||||
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
||||
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
||||
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
|
||||
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
|
||||
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
||||
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
|
||||
// "resolveJsonModule": true, /* Enable importing .json files. */
|
||||
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
|
||||
|
||||
/* JavaScript Support */
|
||||
"allowJs": false, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
|
||||
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
|
||||
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
|
||||
|
||||
/* Emit */
|
||||
// "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
|
||||
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
|
||||
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
|
||||
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
||||
// "outFile": "./ts_built.js", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
|
||||
// "outDir": "./", /* Specify an output folder for all emitted files. */
|
||||
// "removeComments": true, /* Disable emitting comments. */
|
||||
// "noEmit": true, /* Disable emitting files from a compilation. */
|
||||
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
||||
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
|
||||
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
|
||||
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
|
||||
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
||||
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
|
||||
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
|
||||
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
|
||||
// "newLine": "crlf", /* Set the newline character for emitting files. */
|
||||
// "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
|
||||
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
|
||||
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
|
||||
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
|
||||
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
|
||||
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
|
||||
|
||||
/* Interop Constraints */
|
||||
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
|
||||
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
|
||||
"esModuleInterop": false, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
|
||||
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
||||
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
|
||||
|
||||
/* Type Checking */
|
||||
"strict": true, /* Enable all strict type-checking options. */
|
||||
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
|
||||
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
|
||||
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
|
||||
// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
|
||||
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
|
||||
// "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
|
||||
// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
|
||||
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
|
||||
// "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
|
||||
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
|
||||
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
|
||||
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
|
||||
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
|
||||
// "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
|
||||
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
|
||||
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
|
||||
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
|
||||
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
|
||||
|
||||
/* Completeness */
|
||||
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
||||
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
||||
},
|
||||
"include": [
|
||||
"src/**/*"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user