aboutsummaryrefslogtreecommitdiffstats
path: root/home/quickshell/bar/utils
diff options
context:
space:
mode:
authorPetri Hienonen <petri.hienonen@gmail.com>2024-05-23 13:56:00 +0300
committerPetri Hienonen <petri.hienonen@gmail.com>2025-11-30 12:29:57 +0200
commit08297376a85a1719518507e54fca9de954d2376a (patch)
tree3b9c58304b40248533bbb2bb5b7bad2da9da1ff0 /home/quickshell/bar/utils
parent75c2af4aedd2ac5c2cfc74b346625fa4b265541d (diff)
downloadnixos-08297376a85a1719518507e54fca9de954d2376a.tar.zst
Agenix configuration
Diffstat (limited to 'home/quickshell/bar/utils')
-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();
+ }
+ }
+ }
+ }
+}