From 08297376a85a1719518507e54fca9de954d2376a Mon Sep 17 00:00:00 2001 From: Petri Hienonen Date: Thu, 23 May 2024 13:56:00 +0300 Subject: Agenix configuration --- home/quickshell/bar/utils/HyprlandUtils.qml | 54 +++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 home/quickshell/bar/utils/HyprlandUtils.qml (limited to 'home/quickshell/bar/utils') 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 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(); + } + } + } + } +} -- cgit v1.2.3-70-g09d2