aboutsummaryrefslogtreecommitdiffstats
path: root/home/quickshell/bar/utils/HyprlandUtils.qml
diff options
context:
space:
mode:
Diffstat (limited to 'home/quickshell/bar/utils/HyprlandUtils.qml')
-rw-r--r--home/quickshell/bar/utils/HyprlandUtils.qml54
1 files changed, 54 insertions, 0 deletions
diff --git a/home/quickshell/bar/utils/HyprlandUtils.qml b/home/quickshell/bar/utils/HyprlandUtils.qml
new file mode 100644
index 0000000..dde3b31
--- /dev/null
+++ b/home/quickshell/bar/utils/HyprlandUtils.qml
@@ -0,0 +1,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();
+ }
+ }
+ }
+ }
+}