Add isOccupied to hyprland workspaces

This commit is contained in:
Ly-sec 2025-08-21 13:07:43 +02:00
parent ae5fada790
commit 586a8add08

View file

@ -48,6 +48,8 @@ Singleton {
enabled: isHyprland enabled: isHyprland
function onValuesChanged() { function onValuesChanged() {
updateHyprlandWindows() updateHyprlandWindows()
// Keep workspace occupancy up to date when windows change
updateHyprlandWorkspaces()
windowListChanged() windowListChanged()
} }
} }
@ -118,6 +120,19 @@ Singleton {
workspaces.clear() workspaces.clear()
try { try {
const hlWorkspaces = Hyprland.workspaces.values const hlWorkspaces = Hyprland.workspaces.values
// Determine occupied workspace ids from current toplevels
const occupiedIds = {}
try {
const hlToplevels = Hyprland.toplevels.values
for (var t = 0; t < hlToplevels.length; t++) {
const tws = hlToplevels[t].workspace?.id
if (tws !== undefined && tws !== null) {
occupiedIds[tws] = true
}
}
} catch (e2) {
// ignore occupancy errors; fall back to false
}
for (var i = 0; i < hlWorkspaces.length; i++) { for (var i = 0; i < hlWorkspaces.length; i++) {
const ws = hlWorkspaces[i] const ws = hlWorkspaces[i]
// Only append workspaces with id >= 1 // Only append workspaces with id >= 1
@ -129,7 +144,8 @@ Singleton {
"output": ws.monitor?.name || "", "output": ws.monitor?.name || "",
"isActive": ws.active === true, "isActive": ws.active === true,
"isFocused": ws.focused === true, "isFocused": ws.focused === true,
"isUrgent": ws.urgent === true "isUrgent": ws.urgent === true,
"isOccupied": occupiedIds[ws.id] === true
}) })
} }
} }