omarchy icon indicating copy to clipboard operation
omarchy copied to clipboard

Per-monitor workspaces: after a KVM switch a monitor comes back on an empty workspace instead of the one it was showing

Open nyakojiru opened this issue 1 week ago • 4 comments

System details

AMD Ryzen 7 5800X3D, AMD Radeon RX 6600 (Navi 23). Omarchy 4.5.0-3, Hyprland 0.56.2-4, kernel 7.2.15-1-omarchy. Desktop with two identical monitors (Samsung LS27CG51x): HDMI-A-1 at 0x0 and DP-3 at 2560x0, both connected through a KVM switch.

What's wrong?

After a KVM switch (both monitors disconnect, then reconnect), a monitor comes back showing an empty workspace instead of the workspace it was showing before the switch. The windows aren't lost, but it looks as if every window was minimized until you press Super + .

monitor-workspaces.lua brings the workspaces back to the right monitor correctly. The problem is which workspace the monitor ends up showing:

  1. DP-3 is showing workspace 2 (with a window). HDMI-A-1 shows 11.
  2. KVM switches away. DP-3 is removed first, so merge() renumbers workspace 2 into HDMI-A-1's block as 12. Then HDMI-A-1 is removed and only FALLBACK remains.
  3. KVM switches back. restore() correctly moves 12 back to DP-3 and renumbers it to 2.
  4. But DP-3 now shows workspace 1 (empty), the number Hyprland gives a monitor when it is added. own_views() treats it as one of the monitor's own workspaces, and home() would pick the lowest-numbered one anyway, so the monitor stays there.

State captured right after switching back (hyprctl monitors / hyprctl workspaces):

DP-3      active workspace 1
HDMI-A-1  active workspace 11
workspace 2  on DP-3     windows: 1
workspace 1  on DP-3     windows: 0
workspace 11 on HDMI-A-1 windows: 1

The same result reproduces without a KVM by disabling both outputs and re-enabling them:

hyprctl eval 'hl.monitor({ output = "DP-3", disabled = true })'; sleep 1
hyprctl eval 'hl.monitor({ output = "HDMI-A-1", disabled = true })'; sleep 6
hyprctl reload

Before: DP-3 active 2 (1 window). After: DP-3 active 1 (0 windows), workspace 2 (1 window) on DP-3 but not shown.

Side note: FALLBACK also gets permanently assigned a block in ~/.local/state/omarchy/monitor-workspaces (2 FALLBACK FALLBACK), since connected() doesn't exclude it.

Expected

Windows should stick to their workspace across a KVM switch: same workspace number, same monitor, and the monitor showing the same workspace it showed before it was unplugged. At minimum, a monitor shouldn't come back on an empty workspace while one with windows is waiting on it.

Today the windows' workspaces are renumbered while the monitor is away (2 becomes 12 in the other monitor's block), and the returning monitor lands on an empty workspace. When all monitors go away at once (a KVM switch), there is nowhere useful to merge into, so perhaps the reconcile could leave workspaces untouched until real monitors return.

Workaround

A user Lua module that remembers each monitor's (by description) active workspace, stops recording on monitor.removed, and on monitor.added (debounced, after reconcile) calls monitor:set_workspace() back to it, falling back to the lowest workspace with windows when the monitor is showing an empty one.

nyakojiru avatar Nov 20 '26 10:11 nyakojiru

I read the report and compared it with default/hypr/monitor-workspaces.lua on current quattro. Disconnect/reconnect reproduction and tests have not run.

GPT-6 High in Codex classified this as a bug. The separate classification check using deepseek-v4p1-flash returned no usable answer, so classification remains unsettled and needs to be resolved before verification. No diagnostic second opinion has run.

omarchybot avatar Nov 20 '26 11:11 omarchybot

I checked quattro at fef807e08c on a disposable ISO-based worker running Hyprland 0.57.2, using its virtual display and a second headless output. In two disconnect-both/reconnect sequences, the displays returned to their previous workspaces (2/11 and 4/11); I did not reproduce the empty-workspace result reported on Hyprland 0.56.2 with physical KVM outputs. The existing workspace-model tests passed all 15 cases. FALLBACK did acquire a persistent workspace block during these checks.

In default/hypr/monitor-workspaces.lua, the saved state tracks monitor blocks and merged-workspace origins, without remembering each monitor's previously active workspace. own_views() accepts any workspace in the monitor's block, and home() chooses the lowest existing number. Those source observations fit the reported behavior, but the worker checks do not establish the original failure or verify a fix. #19641 already links this issue and proposes active-workspace restoration; #17488 also addresses restoring monitor views, so I have not opened another implementation.

GPT-6 in Codex (reasoning effort unspecified) performed these source and worker checks. No diagnostic second opinion completed: Opus 5.5 High reached its weekly usage limit, and the availability probe confirmed it could not answer. This remains open for maintainer review of the existing proposals; the reported-version KVM behavior is still unverified.

omarchybot avatar Nov 23 '26 14:11 omarchybot

A related case with a different cause: a mirrored output leaves its own empty workspace on the monitor it mirrors.

Setup. Omarchy 4.5.0-3, Hyprland 0.56.2, kernel 7.2.15-4-omarchy. One real monitor (ASUS PA32QCV on DP-4) and a GL.iNet KVM on HDMI-A-1 that mirrors it via monitors.lua:

hl.monitor({
  output = "desc:LTM Lontium semi 0x88888800",
  mode = "preferred", position = "auto", scale = 1,
  mirror = "desc:ASUSTek COMPUTER INC PA32QCV T7LMSV009162",
})

~/.local/state/omarchy/monitor-workspaces:

0	DP-4	ASUSTek COMPUTER INC PA32QCV T7LMSV009162
1		FALLBACK
2		ASUSTek COMPUTER INC ROG PG248Q L8LMQS075392
3	HDMI-A-1	LTM Lontium semi 0x88888800

Steps. Turn the ASUS off and on. Boot and wake from suspend do the same, since the ASUS drops out briefly while the KVM stays connected.

Result.

  1. With the ASUS off, the KVM has nothing to mirror and becomes a normal output. It gets block 3 and opens workspace 31.
  2. When the ASUS returns, the KVM mirrors again and workspace 1 (with windows) moves back to the ASUS.
  3. The ASUS is left showing empty workspace 31, which the bar labels "1". It goes away only after switching workspaces, when Hyprland removes it as empty.

State right after the ASUS comes back:

HDMI-A-1  mirrorOf: 1
DP-4      focused, active workspace 31
workspace 1  on DP-4  windows: 3
workspace 31 on DP-4  windows: 0

Cause (default/hypr/monitor-workspaces.lua). connected() skips mirrors (if not monitor.is_mirror ...), so once the KVM mirrors again, block 3 has no owner. settle() only moves a monitor off another block's workspace when owner(active.id, ...) finds a connected monitor for that block, so it leaves 31 alone. own_views() would send the ASUS to its home(), since an empty workspace with no owner doesn't count as a guest. But it only runs inside reconcile() (start, config reload, monitor.added, monitor.removed). Workspace 31 appears to land on the ASUS after the monitor.added reconcile, when the KVM switches back to mirroring, and nothing reconciles again.

Possible fix. Reconcile again once the mirror takes effect, for example on monitor.layout_changed or a short timer after monitor.added. Alternatively, have settle() treat an empty workspace from a block with no connected owner as stray and show home(). I haven't checked whether #19641's rule (a returning monitor prefers one of its own workspaces with windows over an empty one) covers this. Here the empty workspace is from another block, not the monitor's own.

Workaround (in ~/.config/hypr/monitors.lua; fixes this setup):

hl.on("monitor.added", function()
  hl.timer(function()
    for _, monitor in ipairs(hl.get_monitors()) do
      local active = monitor.active_workspace
      if not monitor.is_mirror
        and monitor.description:find("PA32QCV", 1, true)
        and active and active.id >= 31 and active.id <= 40
        and (active.windows or 0) == 0 then
        monitor:set_workspace({ workspace = "1" })
      end
    end
  end, { type = "oneshot", timeout = 1500 })
end)

phren0logy avatar Nov 23 '26 21:11 phren0logy

I tested the new mirror scenario on a fresh disposable worker running Hyprland 0.57.2, linked to quattro at 94a8c3c3321129fae87a329947711355897e69fd. With a window on workspace 1 and a second output mirroring it, disabling the source crashed Hyprland before I could test reconnect. The stack passes through a Lua timer and Config::Actions::focus(window) into CFocusState::rawWindowFocus, the path also described in #18448. This attempt did not reproduce the empty-workspace result.

In monitor-workspaces.lua, mirrors are excluded from connected(), settle() requires a connected owner before correcting a foreign workspace, and own_views() handles empty foreign workspaces during reconciliation. The module has no monitor.layout_changed handler. The proposed ordering of the mirror transition after reconciliation remains unverified, as does coverage of this case by #19641. That PR already links this issue; #17488 also proposes restoring monitor views.

GPT-6 in Codex (reasoning effort unspecified) performed these checks. No diagnostic second opinion completed: Opus 5.5 High reached its weekly limit, and the availability probe confirmed it could not answer. This remains waiting on maintainer review of the existing proposals, with the mirrored-output case still requiring a successful reproduction and fix verification.

omarchybot avatar Nov 23 '26 21:11 omarchybot