diff options
Diffstat (limited to 'config/quickshell/overview/services')
| -rw-r--r-- | config/quickshell/overview/services/HyprlandData.qml | 88 |
1 files changed, 80 insertions, 8 deletions
diff --git a/config/quickshell/overview/services/HyprlandData.qml b/config/quickshell/overview/services/HyprlandData.qml index e23472d0..6127e989 100644 --- a/config/quickshell/overview/services/HyprlandData.qml +++ b/config/quickshell/overview/services/HyprlandData.qml @@ -5,6 +5,7 @@ import QtQuick import Quickshell import Quickshell.Io import Quickshell.Hyprland +import "../common" /** * Provides access to some Hyprland data not available in Quickshell.Hyprland. @@ -15,11 +16,17 @@ Singleton { property var addresses: [] property var windowByAddress: ({}) property var workspaces: [] + property var allWorkspaces: [] property var workspaceIds: [] property var workspaceById: ({}) property var activeWorkspace: null property var monitors: [] property var layers: ({}) + property bool pendingWindowsUpdate: false + property bool pendingMonitorsUpdate: false + property bool pendingLayersUpdate: false + property bool pendingWorkspacesUpdate: false + property bool pendingActiveWorkspaceUpdate: false function updateWindowList() { getClients.running = true; @@ -39,10 +46,46 @@ Singleton { } function updateAll() { - updateWindowList(); - updateMonitors(); - updateLayers(); - updateWorkspaces(); + scheduleUpdates(true, true, true, true, true); + } + + function scheduleUpdates(windows, monitors, layers, workspaces, activeWorkspace) { + pendingWindowsUpdate = pendingWindowsUpdate || !!windows; + pendingMonitorsUpdate = pendingMonitorsUpdate || !!monitors; + pendingLayersUpdate = pendingLayersUpdate || !!layers; + pendingWorkspacesUpdate = pendingWorkspacesUpdate || !!workspaces; + pendingActiveWorkspaceUpdate = pendingActiveWorkspaceUpdate || !!activeWorkspace; + + const debounceMs = Math.max(0, Config.options.hacks.hyprlandEventDebounceMs); + if (debounceMs === 0) { + flushPendingUpdates(); + } else { + eventDebounceTimer.interval = debounceMs; + eventDebounceTimer.restart(); + } + } + + function flushPendingUpdates() { + if (pendingWindowsUpdate) { + pendingWindowsUpdate = false; + updateWindowList(); + } + if (pendingMonitorsUpdate) { + pendingMonitorsUpdate = false; + updateMonitors(); + } + if (pendingLayersUpdate) { + pendingLayersUpdate = false; + updateLayers(); + } + if (pendingWorkspacesUpdate) { + pendingWorkspacesUpdate = false; + getWorkspaces.running = true; + } + if (pendingActiveWorkspaceUpdate) { + pendingActiveWorkspaceUpdate = false; + getActiveWorkspace.running = true; + } } function biggestWindowForWorkspace(workspaceId) { @@ -55,24 +98,51 @@ Singleton { } Component.onCompleted: { - updateAll(); + scheduleUpdates(true, true, true, true, true); + flushPendingUpdates(); } Connections { target: Hyprland function onRawEvent(event) { - updateAll() + const eventName = `${event?.name ?? event?.event ?? event?.type ?? ""}`; + if (["openlayer", "closelayer", "screencast"].includes(eventName)) + return; + + if (eventName === "openwindow" || eventName === "closewindow" || eventName === "movewindow" || eventName === "movewindowv2" || eventName === "windowtitle") { + scheduleUpdates(true, false, false, true, false); + return; + } + + if (eventName === "workspace" || eventName === "workspacev2" || eventName === "focusedmon" || eventName === "focusedmonv2" || eventName === "activewindow" || eventName === "activewindowv2") { + scheduleUpdates(false, false, false, true, true); + return; + } + + if (eventName.startsWith("monitor") || eventName === "configreloaded") { + scheduleUpdates(true, true, false, true, true); + return; + } + + scheduleUpdates(true, true, true, true, true); } } + Timer { + id: eventDebounceTimer + interval: Math.max(0, Config.options.hacks.hyprlandEventDebounceMs) + repeat: false + onTriggered: root.flushPendingUpdates() + } + Process { id: getClients command: ["hyprctl", "clients", "-j"] stdout: StdioCollector { id: clientsCollector onStreamFinished: { - root.windowList = JSON.parse(clientsCollector.text) + root.windowList = JSON.parse(clientsCollector.text); let tempWinByAddress = {}; for (var i = 0; i < root.windowList.length; ++i) { var win = root.windowList[i]; @@ -112,7 +182,9 @@ Singleton { stdout: StdioCollector { id: workspacesCollector onStreamFinished: { - root.workspaces = JSON.parse(workspacesCollector.text); + const rawWorkspaces = JSON.parse(workspacesCollector.text); + root.allWorkspaces = rawWorkspaces; + root.workspaces = rawWorkspaces.filter(ws => ws.id >= 1 && ws.id <= 100); let tempWorkspaceById = {}; for (var i = 0; i < root.workspaces.length; ++i) { var ws = root.workspaces[i]; |
