blob: dde3b3145fadd2c66d1567d06a85686638e6e43c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
pragma Singleton
import Quickshell
import Quickshell.Hyprland
import QtQuick
Singleton {
id: hyprland
property list<HyprlandWorkspace> workspaces: sortWorkspaces(Hyprland.workspaces.values)
property int maxWorkspace: findMaxId()
function sortWorkspaces(ws) {
return [...ws].sort((a, b) => a?.id - b?.id);
}
function switchWorkspace(w: int): void {
Hyprland.dispatch(`workspace ${w}`);
}
function findMaxId(): int {
if (hyprland.workspaces.length === 0) {
console.log("No workspaces found, defaulting to 1");
return 1; // Return 1 if no workspaces exist
}
let num = hyprland.workspaces.length;
let maxId = hyprland.workspaces[num - 1]?.id || 1;
console.log("Current max workspace ID:", maxId);
return maxId;
}
Connections {
target: Hyprland
function onRawEvent(event) {
let eventName = event.name;
console.log("Hyprland event received:", eventName);
switch (eventName) {
case "createworkspacev2":
{
console.log("Workspace created, updating workspace list");
hyprland.workspaces = hyprland.sortWorkspaces(Hyprland.workspaces.values);
hyprland.maxWorkspace = findMaxId();
}
case "destroyworkspacev2":
{
console.log("Workspace destroyed, updating workspace list");
hyprland.workspaces = hyprland.sortWorkspaces(Hyprland.workspaces.values);
hyprland.maxWorkspace = findMaxId();
}
}
}
}
}
|