Skip to content

Resolve omarchy_monitor_scale variable reference in clamshell recovery - #6688

Merged
dhh merged 2 commits into
omacom:quattrofrom
s-gato:fix/clamshell-scale-variable-reference
Aug 11, 2026
Merged

dhh merged 2 commits into
omacom:quattrofrom
s-gato:fix/clamshell-scale-variable-reference

Conversation

@s-gato

@s-gato s-gato commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Problem

When a user customizes monitors.lua with a specific internal output (e.g. output = "eDP-1") while keeping the default template's variable indirection for scale, disconnecting an external monitor resets the internal panel scale to the default (2) instead of the configured value.

Example config (matches the pattern the default template ships, just with a specific output):

local omarchy_gdk_scale = 1.5
local omarchy_monitor_scale = 1.5

hl.env("GDK_SCALE", tostring(omarchy_gdk_scale))
hl.monitor({ output = "eDP-1", mode = "preferred", position = "auto", scale = omarchy_monitor_scale })

On USB-C / external monitor unplug, omarchy-hyprland-monitor-watch fires omarchy-hyprland-monitor-clamshell, which calls configured_monitor_scale() to read the desired scale.

Root cause

configured_internal_monitor_value scale greps the hl.monitor line and captures whatever follows scale =. When the rule references the variable, the regex captures the literal string omarchy_monitor_scale — non-empty but not a number.

configured_monitor_scale() only falls through to the local omarchy_monitor_scale = ... lookup when the capture is empty ([[ -z $scale ]]), so the variable name leaks through, valid_scale rejects it downstream, and read_monitor_scale() returns the hardcoded default 2.

With the default template (output = "") the regex never matches, so the fallback fires correctly — which is why this only bites users who pin the output name (a pattern hyprland.md itself recommends).

Fix

Fall through on any non-numeric capture, not just an empty one:

-  if [[ -z $scale ]]; then
+  if ! valid_scale "$scale"; then

Reproduction

INTERNAL=eDP-1
monitor_lua=./monitors.lua  # the config above
scale=$(sed -nE "/^hl\.monitor\(\{.*output = \"$INTERNAL\".*\}\)/s/.*scale = \"?([^\", }]+)\"?.*/\1/p" "$monitor_lua" | head -1)
echo "captured: $scale"   # → omarchy_monitor_scale (invalid)

Test coverage

Adds a regression case to test/shell.d/monitor-clamshell-scale-test.sh covering the specific-output + variable-reference combination. Verified it fails on the previous code and passes with the fix. Full existing suite still passes (the only failing suites on my machine are environment-dependent: config-test needs an omarchy-pkgs checkout, runtime-smoke needs a live test shell — both fail identically on pristine quattro).

Copilot AI balanced review requested due to automatic review settings August 10, 2026 20:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes clamshell recovery to resolve variable-based monitor scales correctly.

Changes:

  • Falls back to omarchy_monitor_scale when the captured scale is non-numeric.
  • Adds regression coverage for a specific output using variable indirection.

Tip

If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.

Reviewed changes

Copilot reviewed 1 out of 2 changed files in this pull request and generated no comments.

File Description
bin/omarchy-hyprland-monitor-clamshell Resolves non-numeric scale references through the configured variable.
test/shell.d/monitor-clamshell-scale-test.sh Tests variable-based scale recovery for a specific internal output.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI review requested due to automatic review settings August 11, 2026 11:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 2 changed files in this pull request and generated no new comments.

Suppressed comments (1)

test/shell.d/monitor-clamshell-scale-test.sh:177

  • This sentence is grammatically incomplete; “Lua” needs a noun describing what the examples are.
# A nested table before the keys, and semicolons for separators. Both are Lua a
# user can reasonably write, and neither ends the rule.

The variable reference fix keyed on "the scale is not a number", which also
swallowed an explicit scale = "auto" and let an unrelated local stand in for it.
Read the config the way Hyprland writes it instead: a key's value is whatever
sits between the `=` and the next separator, and a bare word resolves against a
local only when one exists, so a quoted string stays a string. Comments are cut
before anything is matched.

An internal rule that names no scale still defers to the catch-all, as it always
has here. Against the released script only two configs change: a pinned rule
referencing omarchy_monitor_scale, which is the bug this fixes, and a quoted
number in that local, which now applies instead of falling back.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings August 11, 2026 11:48
@dhh
dhh force-pushed the fix/clamshell-scale-variable-reference branch from 9cb6122 to 0bf19bc Compare August 11, 2026 11:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 2 changed files in this pull request and generated no new comments.

@dhh

dhh commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Thanks for tracking this down — the diagnosis is exactly right. configured_internal_monitor_value captures the literal text omarchy_monitor_scale, the [[ -z $scale ]] guard lets it through, and the panel ends up on the hardcoded 2.

I've pushed a follow-up commit rather than asking for changes, since we're close to RC and I wanted the fix to land as one safe unit.

The reason for the rework: keying the fallthrough on "the scale is not a number" is wider than the bug. It also catches values that are deliberately non-numeric, so two configs regress against the released script:

Config Released This PR alone
pinned rule with scale = omarchy_monitor_scale 2 1.5 ✅
pinned rule with explicit scale = "auto", plus an unrelated local omarchy_monitor_scale = 2 1.75 2 ❌
pinned rule naming a variable that doesn't exist 1.75 1 ❌

Row two is the case the "ignores transient auto scale" test was written to prevent, just reached through a pinned output instead of the catch-all. Row three reaches the output = "" rule, which Hyprland never applies to a monitor that has its own rule, so the internal panel picks up the external monitors' scale.

The follow-up narrows the trigger: a bare word resolves against a local only when one actually exists, so a quoted "auto" stays a string and an unresolvable name stays unresolved. That also let the surrounding parse tighten up — values are read as the whole of what sits between the = and the next separator (so 3 / 2 no longer truncates to 3 and get applied), comments are cut before anything is matched, and position gets the same resolution since it had the identical bug.

Behavior against the released script is now down to two configs, both intentional: the bug you reported, and a quoted number in the local (= "1.5"), which previously fell back and now applies.

Your commit is untouched underneath.

— 🤖 Claude, posting on behalf of @dhh

@dhh
dhh merged commit 27d1b6b into omacom:quattro Aug 11, 2026
@s-gato
s-gato deleted the fix/clamshell-scale-variable-reference branch August 11, 2026 16:49
nick1udwig pushed a commit to nick1udwig/omarchy that referenced this pull request Sep 9, 2026
omacom#6688)

A pinned internal monitor rule that referenced the omarchy_monitor_scale local
had the variable name captured as the scale, so clamshell recovery fell all the
way to the hardcoded 2.

Read the config the way Hyprland writes it: a key's value is whatever sits
between the `=` and the next separator, and a bare word resolves against a local
only when one exists, so a quoted string stays a string. Comments are cut before
anything is matched, and position gets the same resolution since it had the
identical bug.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants