Files
hypr/workspaces.lua
T

45 lines
1.5 KiB
Lua

-- ~/.config/hypr/workspaces.lua
-- Dynamic workspace assignment: replaces kanshi + scripts
-- Detects monitor configuration and assigns workspaces accordingly.
local function get_monitor_names()
local names = {}
for _, m in ipairs(hl.get_monitors()) do
names[m.name] = m.name
if m.description then
local clean_desc = m.description:gsub(" %([^%)]+%)$", "")
names["desc:" .. clean_desc] = m.name
end
end
return names
end
local function assign_workspaces()
local monitors = get_monitor_names()
local has_dock = monitors["desc:Ancor Communications Inc ASUS VS228 E3LMTF071438"] and monitors["desc:Ancor Communications Inc ASUS VS228 E3LMTF071391"]
-- Read workspace configurations
package.loaded["workspace_config"] = nil -- force reload in case it changed
local ws_config = require("workspace_config")
-- Iterate in REVERSE to assign the most negative IDs to the first items, counteracting Waybar's low-to-high sorting!
for i = #ws_config, 1, -1 do
local ws = ws_config[i]
local target_mon = has_dock and monitors[ws.monitor] or "eDP-1"
if not target_mon then target_mon = "eDP-1" end
hl.workspace_rule({ workspace = "name:" .. ws.name, monitor = target_mon, persistent = true, default = true })
end
end
-- Apply on initial load
assign_workspaces()
-- Re-apply when monitors change
hl.on("monitor.added", function(monitor)
assign_workspaces()
end)
hl.on("monitor.removed", function(monitor)
assign_workspaces()
end)