Skip to content

Leave the theme's Hyprland reload to Hyprland's own config watch - #15192

Closed
dhh wants to merge 1 commit into
quattrofrom
theme-set-single-hypr-reload
Closed

dhh wants to merge 1 commit into
quattrofrom
theme-set-single-hypr-reload

Conversation

@dhh

@dhh dhh commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #15189. Only the last commit ("Leave the theme's Hyprland reload to Hyprland's own config watch") is this PR. Merge #15189 first. This branch was squashed to that one commit while it absorbed review fixes.

What changed

Hyprland watches the config files it loaded, the theme's hyprland.lua among them. When omarchy-theme-set replaces current/theme, Hyprland reloads by itself. Counting configreloaded events on the event socket during live switches, quattro reloads two or three times per switch: Hyprland's own reload at the swap, then omarchy-restart-hyprctl from the retints, and sometimes one more. Each hyprctl reload stalls the compositor ~20ms, in the middle of the bar and wallpaper transition.

  • One rename for the swap. omarchy-theme-set now swaps the staged theme in with mv --exchange -T and only then removes the old one. The old rm -rf current; mv next current left a moment with no current theme. A reload landing in that gap would skip the theme (require_optional) and drop it from the watch. The fallback for a first theme, or an mv without --exchange, keeps the old two steps.
  • Reload only when Hyprland hasn't.
    • Before the templates render, timeout 10 socat appends Hyprland's event stream (.socket2.sock) to a temp file it opens once.
    • Just before the exchange, the switch counts the configreloaded lines so far.
    • reload_hyprland_unless_watched skips the explicit reload only if a new one appears after the exchange, waiting at most 500ms for it.
    • Otherwise it reloads as before. That covers the watch turned off or paused by omarchy-hyprland-reload-guard (checked first, so there is no wait), a missed or absent watch, and the non-atomic fallback swap, which is never trusted.
    • Once settled, the switch kills the listener and removes the file.
    • The intro path's reload after playback reads the same record. It kills the listener only if its pid still names a timeout.
  • Order. The terminals start retinting first. The reload is then settled while the switch still holds its selection lock, as the intro path already did after playback, so a reload one switch triggers can't reach the next switch's listener after that one's swap. Then the lock is released and the terminals are waited on. A failed explicit reload is reported with the other retints.
  • Locales. $EPOCHREALTIME uses the locale's decimal separator (1791832819,402790 under da_DK, de_DE or fr_FR), so the 500ms deadline reads only its digits (${EPOCHREALTIME//[!0-9]/}). Event order no longer depends on timestamps at all.

Earlier versions of this PR first guessed from the outgoing files whether the watch would fire, then compared read timestamps. Review found cases where each went wrong: symlinks, hard links, open files, delayed events from the previous switch, and comma locales. The current design counts events and settles them under the lock.

Measurements

These are live configreloaded events, in ms after the command started:

quattro this
Starship → Tokyo Night (intro) [351, 8227], [313, 8184], [312, 8184] see comment below
Tokyo Night → Starship [75, 102], [73, 98], [69, 93] see comment below

On every switch with this PR there is one reload, and the border changes with it. That includes the intro switch, where the reload after playback is skipped because the record shows Hyprland reloaded at the swap. Borders change ~44–53ms after a switch to Starship starts, against 51–59ms on quattro.

Tests

theme-set-retint-order-test.sh serves a stand-in for Hyprland's event socket and covers these behaviours:

  • A reload reported after the swap means no explicit reload.
  • None reported means the explicit reload runs, the terminals retint before it, and the listener and its file are gone afterwards.
  • A fallback two-step swap isn't trusted.
  • A 0.8s intro doesn't repeat the reload made at the swap.
  • The previous switch's slow 0.3s reload doesn't count for the next switch.
  • A failed reload is reported.
  • Under a da_DK locale built with localedef (skipped where it can't be built), the switch's microsecond clock reads digits only and a full switch completes.

New theme-swap-test.sh checks that a current hyprland.lua exists at every rename. The exchange-specific cases skip without mv --exchange. I mutation-checked each fix: a dot-only clock, terminals after the reload, a listener left running, counting after the exchange, never or always trusting the event, and settling outside the lock.

What a human should check

Switch themes with the picker and confirm the window borders follow every time. A missed watch now costs up to 500ms before the fallback reload, though the terminals no longer wait for it.

Not changed: after an intro, the reload still runs in the detached playback subshell, as on quattro. OMARCHY_THEME_WAIT=1 doesn't join it, and a failure there isn't reported. Joining it would hold the command for the whole clip.

🤖 Generated with Claude Code

@greptile-apps

greptile-apps Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with the existing non-blocking slow-switch reload issue still partly unresolved.

Findings

  1. P2 Listener stops before the swap ▶

Summary

This PR reduces repeated Hyprland reloads during theme switches.

  • Theme switches use Hyprland’s reload when it follows the theme swap.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Acquire selection lock] --> B[Start event listener]
  B --> C[Stage theme and render templates]
  C --> D{Exchange succeeds?}
  D -->|Yes| E[Save pre-swap event count]
  D -->|No| F[Use two-step swap]
  E --> G[Update shell and start terminal updates]
  F --> G
  G --> H{Intro playing?}
  H -->|No| I[Check watch event or reload explicitly]
  I --> J[Remove listener record]
  J --> K[Release selection lock]
  H -->|Yes| K
  K --> L[Wait for terminal updates]
  L --> M[Run other app updates]
  H -->|Yes| N[After playback, acquire lock]
  N --> O[If theme still current, settle reload]
  O --> P[Remove listener record]
Loading

Reviews (15) · Last reviewed commit: "Leave the theme's Hyprland reload to Hyp..." · Reviewed by Greptile

Comment thread bin/omarchy-theme-set Resolved
@dhh
dhh force-pushed the theme-set-single-hypr-reload branch from b25e19a to 039b4cf Compare October 12, 2026 15:57
Comment thread bin/omarchy-theme-set Resolved
@dhh
dhh force-pushed the theme-set-single-hypr-reload branch from 039b4cf to c509d0f Compare October 12, 2026 16:10
Comment thread bin/omarchy-theme-set Resolved
Comment thread bin/omarchy-theme-set Resolved
@dhh
dhh force-pushed the theme-set-single-hypr-reload branch 2 times, most recently from 8ac5007 to 8e62eb1 Compare October 12, 2026 17:04
Comment thread test/shell.d/theme-swap-test.sh Resolved
@dhh
dhh force-pushed the theme-set-single-hypr-reload branch from 8e62eb1 to 69e917f Compare October 12, 2026 17:27
Comment thread bin/omarchy-theme-set Resolved
Comment thread bin/omarchy-theme-set Outdated
[[ -n ${HYPRLAND_INSTANCE_SIGNATURE:-} && -S $socket ]] || return 0
HYPRLAND_RELOADS=$(mktemp "${XDG_RUNTIME_DIR:-/tmp}/omarchy-theme-set-reloads.XXXXXX") || return 0
{
timeout 3 socat -u "UNIX-CONNECT:$socket" - |

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.

P2 Listener stops before the swap

timeout 3 starts before template rendering and the intro-cover wait. That wait alone can take about three seconds, and user templates add more time. If these steps outlast the listener, Hyprland's reload after the swap is never recorded. The switch then reloads again despite a successful watch reload, adding the compositor pause this PR aims to remove.

Keep the listener alive through the swap and the following reload-check window.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in f405d0c: the listener now runs for 10s, past the intro cover wait (3s cap) and the templates.

Comment thread bin/omarchy-theme-set Resolved
@dhh
dhh force-pushed the theme-set-single-hypr-reload branch 2 times, most recently from d77fd25 to 2bd2d22 Compare October 12, 2026 19:40
@dhh

dhh commented Oct 12, 2026

Copy link
Copy Markdown
Contributor Author

Live results at head 2bd2d22, with #15190 and #15191 merged in. Each switch reloaded Hyprland once:

return border changes configreloaded (ms)
Starship → Tokyo Night (intro) 355ms, 354ms 293ms, 291ms [309], [308]
Tokyo Night → Starship 108ms, 109ms 48ms, 47ms [62], [61]

The background steps finished every time: icon theme, Chromium policy colour, Claude theme, and an empty theme-set.log. No listener or event file was left behind. A run of 6 traced switches before the last change also had one reload each. In one earlier untraced run (4 switches), one switch reloaded twice. The listener now starts right after the selection lock, well before the swap, which should make that fallback rare.

🤖 Generated with Claude Code

Hyprland already reloads when the swap replaces the hyprland.lua it
loaded, so the explicit reload repeated a ~20ms compositor stall
mid-transition.

- Swap the theme in with one rename (mv --exchange), so there is never a
  moment without a current theme for a reload to fall into.
- Record Hyprland's events from before the swap and reload explicitly
  only when no configreloaded follows it within 500ms, or when the swap
  could not be one rename.
- Settle that while holding the selection lock, so one switch's reload
  can't pass for the next one's, while the terminals already retint.
- Count microseconds from EPOCHREALTIME's digits alone, which comma
  locales write with a comma.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@dhh
dhh force-pushed the theme-set-single-hypr-reload branch from 2bd2d22 to 2fe66a1 Compare October 13, 2026 11:51
@dhh

dhh commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

Closing: saves at most one ~20ms compositor stall per switch, not worth the added listener/lock/timeout machinery in omarchy-theme-set. The main theme-switch win landed in #15189.

@dhh dhh closed this Oct 13, 2026
@dhh
dhh deleted the theme-set-single-hypr-reload branch October 13, 2026 12:35
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.

1 participant