local shared = assert(arg[1], "Pass the shared flake's homeConfigurations/modules/hyprland directory") package.path = (arg[0]:match("^(.*/)") or "") .. "?.lua;" .. package.path local context = dofile(shared .. "/test.lua") local D, events, one, two, advance = context.desktop, context.events, context.one, context.two, context.advance require("outputs") -- Model delayed modesets and their added/removed events, rather than immediate rule updates. local lg = { name = "HDMI-A-1", description = "LG Electronics LG HDR 4K 0x000404F0", width = 3840, height = 2160, refresh_rate = 60, dpms_status = true, active_workspace = two } local connected, stuck, apply_delay, commands = true, false, 1400, {} local lg_rule = { mode = "3840x2160@60", disabled = false } context.monitors = { lg } hl.monitor = function(rule) if not rule.output:find("LG HDR 4K", 1, true) then return end for k, v in pairs(rule) do lg_rule[k] = v end local mode, disabled = lg_rule.mode, lg_rule.disabled commands[#commands + 1] = { mode = disabled and "off" or mode, at = context.clock() } hl.timer(function() if not connected or stuck then return end if disabled then context.monitors = {} events["monitor.removed"](lg) else local was_off = #context.monitors == 0 lg.width, lg.height, lg.refresh_rate = mode:match("(%d+)x(%d+)@([%d.]+)") lg.width, lg.height, lg.refresh_rate = tonumber(lg.width), tonumber(lg.height), tonumber(lg.refresh_rate) context.monitors = { lg } if was_off then events["monitor.added"](lg) end end end, { timeout = apply_delay }) end local function count_off() local count = 0 for _, command in ipairs(commands) do if command.mode == "off" then count = count + 1 end end return count end events["hyprland.start"]() advance(100) assert(D.lg_recovery == "settling", "session startup must recover the LG") D.wake(); D.wake() advance(18000) assert(D.lg_recovery == "ready" and lg.refresh_rate == 60 and lg.width == 3840) local state = assert(io.open(os.getenv("XDG_RUNTIME_DIR") .. "/hypr-desktop-test.state")):read("*a") assert(state:find("panel HDMI-A-1 2 scrolling 2.40", 1, true), "panel state must report each output's own layout and ratio") assert(count_off() == 1, "wake and self-generated hotplug events must not restart recovery") local off_index for i, command in ipairs(commands) do if command.mode == "off" then off_index = i; break end end local off, low, mid, high = table.unpack(commands, off_index, off_index + 3) assert(low.mode == "1920x1080@60" and mid.mode == "3840x2160@30" and high.mode == "3840x2160@60") assert(low.at - off.at >= apply_delay + 1000, "off hold starts after disable takes effect") assert(mid.at - low.at >= apply_delay + 3000 and high.at - mid.at >= apply_delay + 3000, "each mode must be applied before starting its hold") events["config.reloaded"](); advance(100) assert(D.lg_recovery == "settling", "config restore must recover the LG") advance(18000) assert(D.lg_recovery == "ready" and count_off() == 2) D.wake(); advance(7500) assert(D.lg_recovery == "1920x1080@60") D.display_profile(false) local solo_commands = #commands advance(20000) assert(lg_rule.disabled and #context.monitors == 0, "solo must cancel an in-progress recovery immediately") for i = solo_commands + 1, #commands do assert(commands[i].mode == "off", "stale timer reenabled LG") end D.wake(); advance(20000) assert(lg_rule.disabled and #context.monitors == 0, "wake must respect intentional LG disable") D.display_profile(true); advance(20000) assert(D.lg_recovery == "ready" and lg.refresh_rate == 60, "dual must start low and retrain") D.wake(); advance(6500) connected = false; context.monitors = {}; events["monitor.removed"](lg) advance(20000) assert(D.lg_recovery == "pending" and lg_rule.mode == "1920x1080@60", "unplug must reset recovery to a safe mode") connected = true lg.width, lg.height, lg.refresh_rate = 1920, 1080, 60 context.monitors = { lg }; events["monitor.added"](lg) advance(20000) assert(D.lg_recovery == "ready" and lg.width == 3840 and lg.refresh_rate == 60, "replug must recover") stuck = true D.wake(); advance(10000) assert(D.lg_recovery == "failed" and lg_rule.mode == "1920x1080@60", "failed modeset must stop the ladder and leave a safe recovery rule") print("PASS: desktop HDMI recovery, startup, solo cancellation, replug, modeset timeout and per-output panel state")