Dynamic monitor toggle

Hyprland version
Hyprland 0.55.4 built from branch v0.55.4-b at commit a0136d8c04687bb36eb8a28eb9d1ff92aea99704 clean ([gha] Nix: update inputs).
Date: 2026-06-11
Tag: v0.55.4, commits: -1

Libraries:
Hyprgraphics: built against 0.5.1, system has unknown
Hyprutils: built against 0.13.1, system has unknown
Hyprcursor: built against 0.1.13, system has unknown
Hyprlang: built against 0.6.8, system has unknown
Aquamarine: built against 0.13.0, system has unknown

Version ABI string: a0136d8c04687bb36eb8a28eb9d1ff92aea99704_aq_0.13_hu_0.13_hg_0.5_hc_0.1_hlg_0.6
flags set:
nix

Describe your issue / feature…

I want my laptop monitor to be enabled only when no other monitor is connected, so i made this:

local function toggle_monitor()
hl.monitor({ output = "eDP-1", disabled = hl.get_monitor("HDMI-A-1") ~= nil })
end

hl.on("monitor.added", toggle_monitor)

hl.monitor({
output = "eDP-1",
mode = "1920x1080@60",
mirror = "HDMI-A-1",
position = "1920x0",
scale = 1.25,
disabled = false,
})

But each config reload after that resets workspace on main monitor and may crash some apps. can i avoid this?

I was about to open a thread asking how to implement this, thanks! I’d love to hear other’s inputs on it.

Ok, solution was pretty eassy, monitor just should be disabled by default, and then you enable it, instead of having it enabled and disabling on event