omarchy icon indicating copy to clipboard operation
omarchy copied to clipboard

Display panel's scale presets silently no-op when `monitors.lua` has explicit per-output `hl.monitor` lines — per-monitor scaling and the bar panel are mutually exclusive

Open isaac30503 opened this issue 2 months ago • 3 comments

Environment

  • Omarchy 4.0.2-1 (packages, on CachyOS), Hyprland 0.56.2, quickshell 0.3.1
  • Lenovo Legion Go 2 (83N0), two outputs:
    • eDP-1 — 1920x1200@144, 8.8", 257 DPI (wants a fractional scale)
    • DP-1 — 1920x1080@60, 27", 81 DPI (wants scale 1)

What happens

Setting a different scale per output requires explicit lines in ~/.config/hypr/monitors.lua:

hl.monitor({ output = "DP-1",  mode = "preferred", position = "0x0",    scale = 1 })
hl.monitor({ output = "eDP-1", mode = "preferred", position = "1920x0", scale = 1.25 })

That works — but from then on the Display panel's scale presets in the bar do nothing. No error, no visual feedback: the buttons are simply inert. Restoring the stock monitors.lua (the single output = "" catch-all) makes the panel work again. Verified in both directions on this machine.

Why

omarchy-hyprland-monitor-scaling has no per-output persistence. It applies the change live and then persists it by rewriting a single global variable:

sed -i -E -e "s|^local omarchy_monitor_scale = .*|local omarchy_monitor_scale = ${new_scale}|" ...

That sed writes monitors.lua, which Hyprland auto-reloads — and on reload the file's explicit per-output lines take precedence over the catch-all the variable feeds. So the script's own persistence step immediately undoes its own live change.

Two consequences worth separating:

  1. The panel silently no-ops. The script's persistence branch is gated on grep -q '^local omarchy_monitor_scale = ', which still matches a customised file, so it reports nothing wrong while having no effect.
  2. The live apply also discards positions. It evaluates hl.monitor({ output = "<focused>", mode = "...", position = "auto", scale = N }), so a deliberate left/right arrangement is replaced by auto until the next reload.

Partial workaround, for the record: pointing only the internal output at the variable

hl.monitor({ output = "eDP-1", ..., scale = omarchy_monitor_scale })

does let the panel keep driving that one output, but the behaviour is confusing — using the panel while the other monitor is focused writes the same variable and moves the internal panel's scale instead. It is not a solution, just evidence of where the single-value assumption sits.

Steps to reproduce

  1. Attach a second monitor.
  2. Add an explicit hl.monitor({ output = "<name>", ..., scale = N }) line for either output to ~/.config/hypr/monitors.lua.
  3. Open the Display panel in the bar and press any scale preset.
  4. Nothing changes. Remove the explicit line and it works again.

Expected

Either the panel persists per-output scale (e.g. writing/updating an hl.monitor({ output = "<name>", ... }) line for the focused monitor), or it tells the user it cannot manage a customised monitors.lua instead of appearing functional.

Mixed-DPI setups make this concrete: an 8.8" 257 DPI panel and a 27" 81 DPI monitor cannot share one scale value, so today the choice is per-monitor scaling or the bar control, never both.


Investigated and written with Claude Code (Claude Opus 5). Every command output, file excerpt and measurement quoted above was taken from the affected machine.

isaac30503 avatar Sep 03 '26 08:09 isaac30503

Follow-up: I've now fully root-caused this and have a per-monitor implementation running locally. Sharing the findings in case the direction is useful upstream — happy to turn it into a PR if it is.

Findings beyond the original report

Digging into omarchy-hyprland-monitor-scaling and the Display panel showed the situation is better than "mutually exclusive" suggests — most of the pipeline is already per-monitor:

  1. State reading is per-monitor already. The panel's current-scale display comes from omarchy-monitor-state → omarchy-hyprland-monitor-scaling (no args) → hyprctl monitors -j filtered to the focused monitor. Nothing global here.
  2. The live apply is per-monitor already — set_scale() targets the focused output via hyprctl eval "hl.monitor({ output = <focused> ... })". But this eval has no effect for outputs that have an explicit hl.monitor line in the config (the config line wins), which is why the panel appears dead with explicit lines even though the script runs fine on every click (verifiable in ~/.local/state/omarchy/monitor-scaling.log).
  3. Persistence is the only fundamentally global piece: the sed rewrites the single local omarchy_monitor_scale variable (or the catch-all line), so scale can only ever be stored globally.
  4. Side note: the live eval uses position = "auto", which also discards manually positioned multi-monitor layouts on every scale change, even in the stock single-variable setup.

What works (running here for a day now)

Rewriting only set_scale() so that persistence is per-output makes the whole panel per-monitor with no QML changes at all, since state reading was already per-focused-monitor:

  • sed only the scale = <n> value inside the hl.monitor({ output = "<focused>" ... }) line of monitors.lua; append a new line (position = "auto") if the output has none.
  • Drop the hyprctl eval entirely — the config write triggers Hyprland's auto-reload, which applies the change. This also fixes finding 2 (eval ineffective with explicit lines) and finding 4 (position = "auto" clobbering layouts) for free.
  • GDK_SCALE (per-session, integer) = rounded max of the persisted scales.

monitors.lua then looks like:

hl.env("GDK_SCALE", "1")
hl.monitor({ output = "", mode = "preferred", position = "auto", scale = 1 })
hl.monitor({ output = "DP-1", mode = "preferred", position = "0x0", scale = 1 })
hl.monitor({ output = "eDP-1", mode = "preferred", position = "auto-right", scale = 1.25 })

UX result: focus the monitor you want to change, use the bar's scale presets — they apply and persist for that output only, and the panel shows the focused monitor's scale. Exactly the behavior a mixed-DPI setup (257 dpi internal + 81 dpi external, in my case) needs.

For local testing I had to ship this as a wrapper in /usr/local/bin plus a cloned Display plugin invoking it by absolute path (since $OMARCHY_PATH/bin leads the session PATH, shadowing doesn't work for omarchy-* commands) — upstream, none of that would be needed: it's a change to set_scale() in the stock script only.

If this direction sounds acceptable I'm glad to send a PR.


Investigated and written with assistance from Claude (Anthropic).

isaac30503 avatar Sep 04 '26 05:09 isaac30503

Follow-up #2: generalized the per-output persistence from my last comment to work for any number of monitors (not just this laptop's two), and found three more real bugs while doing it — one of them explains why the "ship a wrapper in /usr/local/bin" approach can silently do nothing even when it works perfectly by itself.

Generalizing to N monitors

The previous version keyed persistence to hardcoded connector names (DP-1/eDP-1). That breaks the same way omarchy#10199's monitor.id * 10 approach does: connector names move between ports/docks, and a replugged monitor can land on a different name. Fixed by keying the scale state to the monitor's stable identity — same EDID description+serial key already used for per-monitor workspace ranges (omarchy#7973) — in its own state file (~/.local/state/omarchy/hypr-monitor-scales), independent of monitors.lua's physical-layout lines. Any newly-connected monitor with no prior record gets a sane default; any monitor seen before (even on a different port) gets its own remembered scale back.

function SyncMonitorScales()
  if not REAL_COMPOSITOR then return end
  local mons = hl.get_monitors()
  if #mons == 0 then return end

  -- Always re-read from disk, never cached across reloads (see Bug 1 below).
  scales = load_scales()
  -- ... refresh/create a { identity, scale, seen, name } record per connected monitor ...

  by_connector_scale = {}
  local max_scale = 0
  for i = 1, #mons do
    -- ... look up each connected monitor's record by identity, populate by_connector_scale[mon.name] ...
  end
  if dirty then save_scales(scales) end
  if max_scale > 0 then hl.env("GDK_SCALE", tostring(round(max_scale))) end -- GDK_SCALE = rounded max across connected monitors, recomputed here, not a manual constant
end

function ApplyMonitorLayout()
  SyncMonitorScales()
  hl.monitor({ output = "", mode = "preferred", position = "auto", scale = DEFAULT_MONITOR_SCALE })
  -- any monitor without a fixed physical-position rule gets "auto" position + its own persisted scale:
  for _, mon in ipairs_safe(hl.get_monitors()) do
    if not KNOWN_POSITIONED_OUTPUTS[mon.name] then
      hl.monitor({ output = mon.name, mode = "preferred", position = "auto", scale = ScaleFor(mon.name) })
    end
  end
  -- ... this laptop's two known outputs, positioned last so they always win (see Bug 2) ...
end

The wrapper script's set_scale() now only ever computes the focused monitor's identity (same description+serial logic, mirrored in bash) and writes/updates that one row in the state file, then triggers hyprctl reload — same principle as before, just keyed by identity instead of connector name.

Bug 1: Lua caches the scale file across reloads, and can clobber the wrapper's write

First version copied the caching pattern already used for workspace ranges: if #scales == 0 then scales = load_scales() end. That's safe for the workspace-ranges file (only ever written by monitors.lua itself), but hypr-monitor-scales has a second writer — the wrapper script — and Lua's module state persists across hyprctl reload (confirmed empirically: the "never replace an existing workspace rule" protection in the previous comment's code depends on exactly this). Result: the wrapper's fresh write got ignored on the very next reload, and as soon as anything else marked the in-memory table dirty, Lua re-saved its stale copy over the wrapper's change — a scale set from the panel would silently revert to whatever it was at the first reload of the session. Fix: scales = load_scales() unconditionally, every call.

Bug 2: position = "auto-right" raced with the scale change and swapped the monitors

With eDP-1's position declared as "auto-right" (resolved by Hyprland relative to whatever is at "0x0"), changing DP-1's scale via the wrapper would, on some but not all reloads, result in Hyprland placing DP-1 itself at an auto/wrong position instead of respecting its own "0x0" rule — swapping which monitor was visually on the left. A follow-up manual hyprctl reload always fixed it, which pointed at a timing race (the modeset from the scale change not fully settled at the moment "auto-right" got resolved against it) rather than a config ordering mistake. Fix: stopped relying on Hyprland to resolve any relative position at all — the second monitor's absolute X is computed by hand in Lua (first monitor's physical width / its current scale) and passed as a literal coordinate. As a mitigation for any remaining settle-time race, the wrapper also retries its hyprctl reload (up to 8x, 150ms apart) until hyprctl monitors -j confirms the live scale matches what was requested, instead of assuming one reload is enough.

Bug 3 (the one that produced false negatives in my own testing): /usr/local/bin isn't ahead of Omarchy's own script in every PATH that matters

This is the one I'd flag loudest for anyone hitting "I shipped the wrapper and it still does nothing." /usr/local/bin precedes /usr/bin in a normal interactive shell's PATH — but the actual quickshell process (the one that runs the Display panel and calls omarchy-hyprland-monitor-scaling by bare name) has /usr/share/omarchy/bin ahead of /usr/local/bin in its PATH (confirmed via /proc/<quickshell-pid>/environ), and that's the script's real on-disk location (/usr/bin/omarchy-hyprland-monitor-scaling is a symlink into it). So the panel kept invoking the stock script regardless of what sat in /usr/local/bin, while every one of my own CLI tests (invoking the wrapper by absolute path) worked perfectly — false positives that cost real debugging time before I checked the actual process environment instead of my own shell's. My previous comment already mentioned "a cloned Display plugin invoking it by absolute path" was needed for local testing; I'd initially assumed that was incidental to my dev setup and skipped it here too — it isn't incidental, it's required. Fix: omarchy plugin clone omarchy.monitor, then in the clone's Panel.qml:

function setScale(scale) {
  actionProc.command = ["bash", "-c", "/usr/local/bin/omarchy-hyprland-monitor-scaling " + scale]
  if (!actionProc.running) actionProc.running = true
}

omarchy-monitor-state (read-only state query) didn't need the same treatment — its no-args branch does the same thing in both the stock and wrapper scripts.

Related, not fixed: cursor can't cross the full height of a mixed-resolution boundary

Once two monitors of different native resolution (not just scale) sit side by side, their logical heights never match exactly, so top-aligning them leaves a dead zone at one edge where the cursor has nowhere to land when crossing — this is independent of the bugs above, and happens even at matching scale=1 on both. Went looking for a fix and found #12297 already covers exactly this; noting it here since it's the same root cause as this issue's mixed-DPI setup. No native option, no plugin/script found upstream, and — worth recording since it affects anyone considering the same route — a script-side fix isn't buildable on top of Omarchy's Lua config either: hl.on()'s HL.EventName list has no mouse/cursor entries (checked against hl.meta.lua), only Hyprland's internal C++ plugin API gets a mouseMove callback with live coordinates, and even that couldn't distinguish "cursor resting at the clamped edge" from "user pushing to cross" without reading raw device deltas below the compositor's own clamping. We settled for centering the two monitors vertically (recomputed live, since which one is logically taller flips with the scale combination chosen) instead of top-aligning — splits the dead zone top/bottom instead of leaving it all on one edge, at zero cost to keeping both monitors' scale and resolution fully independent.


Investigated and written with assistance from Claude (Anthropic).

isaac30503 avatar Sep 05 '26 20:09 isaac30503

Automated duplication check: this issue looks similar to #6673, which covers the same Scale persists globally not per-monitor. I keep that one open and close this one to keep the discussion in one place.

If you feel this is the wrong decision, please open the issue again with a note on the difference.

bjarneo avatar Sep 21 '26 05:09 bjarneo