From b68ea6129d22a0fba121d229a66736a61cd25893 Mon Sep 17 00:00:00 2001 From: Steve Derico <424734+stevederico@users.noreply.github.com> Date: Sat, 21 Nov 2026 08:12:33 -0800 Subject: [PATCH 1/7] Restart the bar clock and calendar on a resync request SystemClock waits out the rest of the minute on a timer that stops while the machine sleeps, so after a wake the label and the calendar's today kept the time from before it for up to a minute (#13504). Add an omarchy.clock resync IPC method that re-enables the label's SystemClock and the calendar's. A re-enabled SystemClock re-reads the time and schedules its next tick from now, and onDateChanged puts the result on screen. The calendar restarts its own clock rather than going through refresh(), so a month the user is browsing stays put. --- shell/plugins/panels/clock/BarWidget.qml | 12 ++++ shell/plugins/panels/clock/Panel.qml | 8 +++ .../fixtures/bar-widget-contract/shell.qml | 56 +++++++++++++++++++ 3 files changed, 76 insertions(+) diff --git a/shell/plugins/panels/clock/BarWidget.qml b/shell/plugins/panels/clock/BarWidget.qml index b69f2f157c50..37ab663b2c34 100644 --- a/shell/plugins/panels/clock/BarWidget.qml +++ b/shell/plugins/panels/clock/BarWidget.qml @@ -40,6 +40,17 @@ BarWidget { if (panelLoader.item && panelLoader.item.refresh) panelLoader.item.refresh() } + // SystemClock waits out the rest of the minute on a timer that stops during + // suspend, so after a wake the label kept the time from before it for up to a + // minute. Re-enabling the clock re-reads the time and arms its next tick from + // now, and onDateChanged below puts the result on the label. Unlike refresh() + // this leaves a month the user is browsing in the calendar where it is. + function resync() { + clock.enabled = false + clock.enabled = true + if (panelLoader.item && panelLoader.item.resync) panelLoader.item.resync() + } + function cycleFormat() { var current = String(configuredFormat) var next = Model.nextClockFormat(formatRing, current) @@ -142,6 +153,7 @@ BarWidget { target: "omarchy.clock" function refresh(): void { root.broadcast("refresh") } + function resync(): void { root.broadcast("resync") } function cycleFormat(): void { root.cycleFormat() } function toggleWeekStart(): void { root.toggleWeekStart() } function open(): void { root.open() } diff --git a/shell/plugins/panels/clock/Panel.qml b/shell/plugins/panels/clock/Panel.qml index 6b9fcd244207..25f18f2ce3ad 100644 --- a/shell/plugins/panels/clock/Panel.qml +++ b/shell/plugins/panels/clock/Panel.qml @@ -120,6 +120,14 @@ Panel { root.goToToday() } + // The same catch-up for the calendar's own clock, which is how today moves + // after a sleep that crossed midnight. Its onDateChanged keeps a browsed + // month, where refresh() would send it back to today. + function resync() { + clock.enabled = false + clock.enabled = true + } + function goToToday() { root.viewYear = today.getFullYear() root.viewMonth = today.getMonth() diff --git a/test/shell.d/fixtures/bar-widget-contract/shell.qml b/test/shell.d/fixtures/bar-widget-contract/shell.qml index a43e781cde40..6b5132abaab3 100644 --- a/test/shell.d/fixtures/bar-widget-contract/shell.qml +++ b/test/shell.d/fixtures/bar-widget-contract/shell.qml @@ -62,6 +62,61 @@ ShellRoot { return isFinite(n) && n >= 0 } + function calendarOf(item) { + for (var i = 0; i < item.children.length; i++) { + var child = item.children[i] + if (child && child.item && ("viewMonth" in child.item)) return child.item + } + return null + } + + // The SystemClock a QML object declares, found by the properties only it has. + function systemClockOf(item) { + for (var i = 0; i < item.data.length; i++) { + var child = item.data[i] + if (child && ("precision" in child) && ("enabled" in child)) return child + } + return null + } + + // How many times a clock was stopped and started while fn ran. + function restartsDuring(clock, fn) { + var restarts = 0 + var count = function() { if (clock.enabled) restarts++ } + clock.enabledChanged.connect(count) + fn() + clock.enabledChanged.disconnect(count) + return restarts + } + + // A wake leaves SystemClock counting down a minute it started before the + // sleep. Re-enabling it is what re-reads the time, so the resync the system + // clock timer asks for has to restart both the label's clock and the + // calendar's, and has to do it without sending a browsed month back to today. + function assertClockResyncs(item) { + var calendar = calendarOf(item) + root.assertTrue(calendar !== null, "omarchy.clock loads its calendar") + if (!calendar) return + + var labelClock = systemClockOf(item) + var calendarClock = systemClockOf(calendar) + root.assertTrue(labelClock !== null && calendarClock !== null, "omarchy.clock and its calendar each run a SystemClock") + if (!labelClock || !calendarClock) return + + calendar.viewMonth = (calendar.viewMonth + 3) % 12 + var browsed = calendar.viewMonth + + var labelRestarts = 0 + var calendarRestarts = restartsDuring(calendarClock, function() { + labelRestarts = restartsDuring(labelClock, function() { item.resync() }) + }) + + root.assertEqual(labelRestarts, 1, "omarchy.clock restarts its clock when the system clock jumps") + root.assertEqual(calendarRestarts, 1, "omarchy.clock restarts its calendar's clock when the system clock jumps") + root.assertTrue(labelClock.enabled && calendarClock.enabled, "omarchy.clock leaves both clocks running after a resync") + root.assertEqual(calendar.viewMonth, browsed, "omarchy.clock leaves a browsed month alone when the system clock jumps") + } + function loadWidget(entry) { var component = Qt.createComponent(entry.url, Component.PreferSynchronous) if (component.status !== Component.Ready) { @@ -162,6 +217,7 @@ ShellRoot { var id = root.createdIds[j] root.assertTrue(root.finiteDimension(item.implicitWidth), id + " has a finite implicitWidth") root.assertTrue(root.finiteDimension(item.implicitHeight), id + " has a finite implicitHeight") + if (id === "omarchy.clock") root.assertClockResyncs(item) } fakeBar.vertical = true From 929d76d91b5354727c251f67d20e2f1c02c025dd Mon Sep 17 00:00:00 2001 From: Steve Derico <424734+stevederico@users.noreply.github.com> Date: Sat, 21 Nov 2026 08:12:33 -0800 Subject: [PATCH 2/7] Resync the bar clock when the system clock jumps A user timer with OnClockChange=yes and OnTimezoneChange=yes starts a oneshot that runs omarchy-shell -q omarchy.clock resync. systemd waits on a TFD_TIMER_CANCEL_ON_SET timerfd for it, so nothing resident and nothing polling. The kernel cancels that timerfd when CLOCK_REALTIME jumps against CLOCK_MONOTONIC, which a resume from suspend does as well as an NTP step or timedatectl set-time, so one timer covers all of them. New installs enable the timer with the other user units, and a migration enables it for existing ones. Both link the units from default/ into ~/.config/systemd/user, so they follow the shipped files. Fixes #13504 --- .../systemd/user/omarchy-clock-resync.service | 11 +++ .../systemd/user/omarchy-clock-resync.timer | 16 ++++ docs/file-layout.md | 3 +- docs/omarchy-shell.md | 6 ++ install/user/first-run/enable-user-units.sh | 12 ++- migrations/1792360285.sh | 34 +++++++ test/shell.d/clock-resync-test.sh | 92 +++++++++++++++++++ test/shell.d/config-test.sh | 5 +- test/shell.d/first-run-test.sh | 12 ++- test/shell.d/owe-integration-test.sh | 4 +- 10 files changed, 188 insertions(+), 7 deletions(-) create mode 100644 default/systemd/user/omarchy-clock-resync.service create mode 100644 default/systemd/user/omarchy-clock-resync.timer create mode 100644 migrations/1792360285.sh create mode 100755 test/shell.d/clock-resync-test.sh diff --git a/default/systemd/user/omarchy-clock-resync.service b/default/systemd/user/omarchy-clock-resync.service new file mode 100644 index 000000000000..093c3c81d562 --- /dev/null +++ b/default/systemd/user/omarchy-clock-resync.service @@ -0,0 +1,11 @@ +[Unit] +Description=Restart the bar clock after the system clock jumped +# The same environment omarchy-sleep-lock waits for: the IPC call finds the +# running shell through OMARCHY_PATH and WAYLAND_DISPLAY. -q makes a shell that +# is not running, or still starting, a success rather than a failed unit. +ConditionEnvironment=OMARCHY_PATH +ConditionEnvironment=WAYLAND_DISPLAY + +[Service] +Type=oneshot +ExecStart=/usr/bin/omarchy-shell -q omarchy.clock resync diff --git a/default/systemd/user/omarchy-clock-resync.timer b/default/systemd/user/omarchy-clock-resync.timer new file mode 100644 index 000000000000..8bb0120ad9cb --- /dev/null +++ b/default/systemd/user/omarchy-clock-resync.timer @@ -0,0 +1,16 @@ +[Unit] +Description=Watch for the system clock jumping +# Nothing to count down: OnClockChange= waits on a timerfd the user manager +# already holds, so the timer costs no process and no wakeups. The kernel +# cancels that timerfd when CLOCK_REALTIME jumps against CLOCK_MONOTONIC, which +# is what a resume from suspend does as well as a clock being set. +PartOf=graphical-session.target + +[Timer] +OnClockChange=yes +# A zone change leaves the label on the old zone until the next tick, which is +# why omarchy-menu-timezone pushes a refresh; this covers any other way it is set. +OnTimezoneChange=yes + +[Install] +WantedBy=graphical-session.target diff --git a/docs/file-layout.md b/docs/file-layout.md index 1825c6c441bb..bcd496b62bab 100644 --- a/docs/file-layout.md +++ b/docs/file-layout.md @@ -337,7 +337,8 @@ and/or a working user systemd instance: `systemctl --user enable --now` the shipped user units (`bt-agent`, `omarchy-sleep-lock`, `omarchy-recover-internal-monitor`, `omarchy-migrate-notify.service`, `omarchy-fcitx5.service`, - `omarchy-crash-watch.service`) so they run in the first session too. + `omarchy-crash-watch.service`, `omarchy-clock-resync.timer`) so they run in the + first session too. Done here, not at finalize, because the user manager isn't reachable from the ISO chroot; `ConditionPath*` in the unit files keeps services inert when they don't apply. diff --git a/docs/omarchy-shell.md b/docs/omarchy-shell.md index 98559d019c7f..4e115cdf95aa 100644 --- a/docs/omarchy-shell.md +++ b/docs/omarchy-shell.md @@ -97,6 +97,12 @@ bar from the CLI — `use | reset | defaults | position | background | put | move | set | get`, with placement flags such as `--section` and `--index`. The lower-level IPC methods remain available through `omarchy-shell shell ...`. +## Waking from suspend + +`SystemClock` waits out the rest of the minute on a timer that stops while the machine is suspended, so it wakes still reporting the time it had before, for up to a minute. `omarchy-clock-resync.timer`, a user timer shipped in `default/systemd/user/`, fixes that for the bar clock without a process or a poll. It sets `OnClockChange=yes`, which makes systemd's user manager wait on a `timerfd` created with `TFD_TIMER_CANCEL_ON_SET`. The kernel cancels that timerfd when `CLOCK_REALTIME` jumps against `CLOCK_MONOTONIC`, and resuming from suspend does that as well as `settimeofday`, an NTP step and `timedatectl set-time`. `OnTimezoneChange=yes` covers a changed timezone. The timer starts `omarchy-clock-resync.service`, which runs `omarchy-shell -q omarchy.clock resync`. + +`resync` restarts the label's `SystemClock` and the calendar's: a re-enabled `SystemClock` re-reads the time and schedules its next tick from now. Unlike `refresh`, it leaves a month the user is browsing in the calendar where it is. A plugin with a `SystemClock` of its own can register an IPC method that does the same and have a user unit call it. + ## Elsewhen Elsewhen (`omarchy.elsewhen`), the world clock, is a first-party plugin in `shell/plugins/panels/elsewhen/`; [`elsewhen.md`](elsewhen.md) covers how it works. It shipped as the separate `elsewhen` package under the id `omacom.elsewhen` until it moved in. New installs place it immediately after the clock, before Weather; the placement migration uses `omarchy bar put omarchy.elsewhen --after omarchy.clock`, which preserves an existing placement and uses Elsewhen's normal right-side placement if the clock is absent. With no shell to ask, as in an update from a TTY, it skips the placement rather than failing the update. A later migration renames existing `omacom.elsewhen` entries in `shell.json`, keeping their settings, and removes the retired package and any dev-checkout link to its `/usr/share/omarchy` path, leaving links and checkouts the user made alone. diff --git a/install/user/first-run/enable-user-units.sh b/install/user/first-run/enable-user-units.sh index 0f73262282ec..a9b627376edd 100755 --- a/install/user/first-run/enable-user-units.sh +++ b/install/user/first-run/enable-user-units.sh @@ -13,6 +13,15 @@ set -euo pipefail omarchy-input-method configure --defaults || echo "Input method defaults deferred; run omarchy setup input after login." >&2 +# The clock resync units live in default/, so link them where the user manager +# looks. A link follows the shipped file, so it never goes stale. +mkdir -p "$HOME/.config/systemd/user" +for unit in omarchy-clock-resync.{service,timer}; do + if [[ ! -e /usr/lib/systemd/user/$unit ]]; then + ln -sfn "$OMARCHY_PATH/default/systemd/user/$unit" "$HOME/.config/systemd/user/$unit" + fi +done + systemctl --user daemon-reload # One at a time: given a list, systemctl enables none of it when it cannot find @@ -25,7 +34,8 @@ for unit in \ omarchy-sleep-lock.service \ omarchy-migrate-notify.service \ omarchy-fcitx5.service \ - omarchy-crash-watch.service; do + omarchy-crash-watch.service \ + omarchy-clock-resync.timer; do systemctl --user enable --now "$unit" || failed=1 done diff --git a/migrations/1792360285.sh b/migrations/1792360285.sh new file mode 100644 index 000000000000..adf79eebc7a9 --- /dev/null +++ b/migrations/1792360285.sh @@ -0,0 +1,34 @@ +echo "Catch the bar clock up when the system clock jumps" + +# SystemClock waits out the rest of the minute on a timer that stops during +# suspend, so after a wake the bar kept the old time for up to a minute. The +# timer restarts the clock when the system clock jumps, which a wake is. New +# installs enable it with the other user units; this is for existing ones. + +# The units live in default/, so link them where the user manager looks. A +# link follows the shipped file, so it never goes stale. +mkdir -p "$HOME/.config/systemd/user" +for unit in omarchy-clock-resync.service omarchy-clock-resync.timer; do + if [[ ! -e /usr/lib/systemd/user/$unit ]]; then + ln -sfn "$OMARCHY_PATH/default/systemd/user/$unit" "$HOME/.config/systemd/user/$unit" + fi +done + +systemctl --user daemon-reload >/dev/null 2>&1 || true + +# `systemctl enable` needs a live user manager, which an update from a TTY does +# not have, so fall back to writing the symlink it would have written. +if ! systemctl --user enable omarchy-clock-resync.timer >/dev/null 2>&1; then + wants_dir="$HOME/.config/systemd/user/graphical-session.target.wants" + mkdir -p "$wants_dir" + if [[ -e /usr/lib/systemd/user/omarchy-clock-resync.timer ]]; then + ln -sfn /usr/lib/systemd/user/omarchy-clock-resync.timer "$wants_dir/omarchy-clock-resync.timer" + else + ln -sfn "$HOME/.config/systemd/user/omarchy-clock-resync.timer" "$wants_dir/omarchy-clock-resync.timer" + fi +fi + +# Nothing to start into over SSH; the next graphical login handles it. +if systemctl --user is-active --quiet graphical-session.target; then + systemctl --user start omarchy-clock-resync.timer >/dev/null 2>&1 || true +fi diff --git a/test/shell.d/clock-resync-test.sh b/test/shell.d/clock-resync-test.sh new file mode 100755 index 000000000000..85e21669fd8c --- /dev/null +++ b/test/shell.d/clock-resync-test.sh @@ -0,0 +1,92 @@ +#!/bin/bash + +set -euo pipefail + +source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh" + +units="$ROOT/default/systemd/user" +timer="$units/omarchy-clock-resync.timer" +service="$units/omarchy-clock-resync.service" +first_run="$ROOT/install/user/first-run/enable-user-units.sh" +migration="$ROOT/migrations/1792360285.sh" + +# OnClockChange= is what makes the timer fire when CLOCK_REALTIME jumps against +# CLOCK_MONOTONIC, which a resume from suspend does as well as a clock being set. +grep -Fx 'OnClockChange=yes' "$timer" >/dev/null || + fail "the timer fires when the system clock jumps" +grep -Fx 'OnTimezoneChange=yes' "$timer" >/dev/null || + fail "the timer fires when the timezone changes" +pass "the timer fires when the system clock or the timezone changes" + +# Any calendar or monotonic expression would turn it into a poll. +if grep -Eq '^(OnCalendar|OnActiveSec|OnBootSec|OnStartupSec|OnUnitActiveSec|OnUnitInactiveSec|AccuracySec|RandomizedDelaySec)=' "$timer"; then + fail "the timer waits for the clock to jump instead of counting down to anything" +fi +grep -Fx 'WantedBy=graphical-session.target' "$timer" >/dev/null || + fail "the timer runs with the graphical session" +pass "the timer counts down to nothing and runs with the graphical session" + +grep -Fx 'ExecStart=/usr/bin/omarchy-shell -q omarchy.clock resync' "$service" >/dev/null || + fail "the service tells the shell to resync the clock, quietly" +grep -Fx 'Type=oneshot' "$service" >/dev/null || + fail "the service runs once per jump" +grep -Fx 'ConditionEnvironment=OMARCHY_PATH' "$service" >/dev/null && + grep -Fx 'ConditionEnvironment=WAYLAND_DISPLAY' "$service" >/dev/null || + fail "the service waits for the environment omarchy-shell finds the shell through" +pass "the service tells the running shell to resync the clock" + +# verify also checks that the ExecStart binary exists, so it needs the package. +if command -v systemd-analyze >/dev/null && [[ -x /usr/bin/omarchy-shell ]]; then + verify=$(systemd-analyze --user verify "$timer" "$service" 2>&1) || + fail "systemd accepts the clock resync units" "$verify" + [[ -z $verify ]] || fail "systemd accepts the clock resync units" "$verify" + pass "systemd accepts the clock resync units" +fi + +grep -F 'omarchy-clock-resync.timer' "$first_run" >/dev/null || + fail "new installs enable the clock resync timer" +pass "new installs enable the clock resync timer" + +# The migration, run for a user whose units are not on the machine yet, with +# systemctl stubbed: it must put them where the user manager looks, then enable +# and start the timer, and a second run must change nothing. +tmp=$(mktemp -d) +trap 'rm -rf "$tmp"' EXIT +mkdir -p "$tmp/bin" "$tmp/home" +cat >"$tmp/bin/systemctl" <<'SH' +#!/bin/bash +printf '%s\n' "$*" >>"$SYSTEMCTL_LOG" +exit 0 +SH +chmod +x "$tmp/bin/systemctl" + +run_migration() { + HOME="$tmp/home" OMARCHY_PATH="$ROOT" SYSTEMCTL_LOG="$tmp/systemctl.log" PATH="$tmp/bin:$PATH" \ + bash "$migration" >/dev/null +} + +if [[ -e /usr/lib/systemd/user/omarchy-clock-resync.timer ]]; then + skip "the package already ships the clock resync units; skipping the install check" +else + run_migration + [[ $(readlink "$tmp/home/.config/systemd/user/omarchy-clock-resync.timer") == "$timer" && + $(readlink "$tmp/home/.config/systemd/user/omarchy-clock-resync.service") == "$service" ]] || + fail "the migration links the clock resync units for an existing user" + pass "the migration links the clock resync units for an existing user" +fi + +grep -Fx -- '--user enable omarchy-clock-resync.timer' "$tmp/systemctl.log" >/dev/null || + fail "the migration enables the clock resync timer" +pass "the migration enables the clock resync timer" + +# Over SSH there is no user manager to enable into, so the wants symlink is +# written directly. +cat >"$tmp/bin/systemctl" <<'SH' +#!/bin/bash +[[ $* == "--user enable"* ]] && exit 1 +exit 0 +SH +run_migration +[[ -L $tmp/home/.config/systemd/user/graphical-session.target.wants/omarchy-clock-resync.timer ]] || + fail "the migration links the timer in by hand when systemctl cannot enable it" +pass "the migration links the timer in by hand when systemctl cannot enable it" diff --git a/test/shell.d/config-test.sh b/test/shell.d/config-test.sh index 83397007bf5a..1bf0fbea24ca 100755 --- a/test/shell.d/config-test.sh +++ b/test/shell.d/config-test.sh @@ -126,11 +126,12 @@ for source, destination, legacy in package_defaults: errors.append(f"PKGBUILD does not explicitly install {source} -> {destination}") # A user unit has to be on the machine before anything turns it on: shipped in -# /usr/lib/systemd/user, or copied out of default/ by the command enabling it. +# /usr/lib/systemd/user, or copied or linked out of default/ by the command +# enabling it. def installs_first(text): source = re.search(r'(\w+)="[^"\n]*default/systemd/user/', text) held = rf"|\$\{{?{source[1]}\b" if source else "" - copy = re.search(rf"^[ \t]*(?:sudo[ \t]+)?(?:install|cp)\b[^\n]*(?:default/systemd/user/{held})", text, re.MULTILINE) + copy = re.search(rf"^[ \t]*(?:sudo[ \t]+)?(?:install|cp|ln)\b[^\n]*(?:default/systemd/user/{held})", text, re.MULTILINE) enable = text.find("systemctl --user enable") return bool(copy) and (enable < 0 or copy.start() < enable) diff --git a/test/shell.d/first-run-test.sh b/test/shell.d/first-run-test.sh index 974488181f96..32ba61549834 100644 --- a/test/shell.d/first-run-test.sh +++ b/test/shell.d/first-run-test.sh @@ -42,7 +42,7 @@ chmod +x "$mock_bin/systemctl" "$mock_bin/omarchy-hook-install" enable_user_units() { rm -f "$test_tmp/calls" - PATH="$mock_bin:$PATH" OMARCHY_TEST_CALLS="$test_tmp/calls" OMARCHY_TEST_MISSING_UNIT="$1" \ + HOME="$test_tmp/home" OMARCHY_PATH="$ROOT" PATH="$mock_bin:$PATH" OMARCHY_TEST_CALLS="$test_tmp/calls" OMARCHY_TEST_MISSING_UNIT="$1" \ bash "$ROOT/install/user/first-run/enable-user-units.sh" } @@ -62,6 +62,16 @@ done (( ${#units[@]} > 1 )) || fail "first-run enables each unit on its own" pass "a unit missing from the build costs first-run only that unit" +# Units omarchy-settings does not ship yet are copied where the user manager +# looks before anything enables them, under the user's home and nowhere else. +for unit in omarchy-clock-resync.service omarchy-clock-resync.timer; do + [[ -e /usr/lib/systemd/user/$unit ]] || cmp -s "$ROOT/default/systemd/user/$unit" "$test_tmp/home/.config/systemd/user/$unit" || + fail "first-run puts the clock resync units where the user manager finds them" "$unit" +done +grep -Fxq -- '--user enable --now omarchy-clock-resync.timer' <<<"$clean_run" || + fail "first-run enables the clock resync timer" +pass "first-run enables the clock resync timer" + cat >"$mock_bin/nm-online" <<'SH' #!/bin/bash exit 0 diff --git a/test/shell.d/owe-integration-test.sh b/test/shell.d/owe-integration-test.sh index dec14af0efe5..805fab263a71 100644 --- a/test/shell.d/owe-integration-test.sh +++ b/test/shell.d/owe-integration-test.sh @@ -19,13 +19,13 @@ SH done : >"$TEST_CALLS" -HOME="$work/home" PATH="$work/bin:$PATH" bash "$ROOT/install/user/first-run/enable-user-units.sh" +HOME="$work/home" OMARCHY_PATH="$ROOT" PATH="$work/bin:$PATH" bash "$ROOT/install/user/first-run/enable-user-units.sh" grep -E '^systemctl --user enable --now .*owed.service' "$TEST_CALLS" >/dev/null grep -Fx 'omarchy-hook-install theme-set /usr/share/owe/10-owe-sync' "$TEST_CALLS" >/dev/null pass "fresh installs enable OWE and install the theme refresh hook" : >"$TEST_CALLS" -HOME="$work/home" PATH="$work/bin:$PATH" TEST_INPUT_FAIL=1 bash "$ROOT/install/user/first-run/enable-user-units.sh" +HOME="$work/home" OMARCHY_PATH="$ROOT" PATH="$work/bin:$PATH" TEST_INPUT_FAIL=1 bash "$ROOT/install/user/first-run/enable-user-units.sh" grep -Fx 'omarchy-input-method configure --defaults' "$TEST_CALLS" >/dev/null grep -E '^systemctl --user enable --now .*owed.service' "$TEST_CALLS" >/dev/null pass "failed input defaults do not block enabling first-run services" From 6450ce2f220daaf5c0b78c6922a46bb335ec778c Mon Sep 17 00:00:00 2001 From: Steve Derico <424734+stevederico@users.noreply.github.com> Date: Sat, 21 Nov 2026 08:12:33 -0800 Subject: [PATCH 3/7] Check the timer is enabled only when the clock resync migration ran --- test/shell.d/clock-resync-test.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/shell.d/clock-resync-test.sh b/test/shell.d/clock-resync-test.sh index 85e21669fd8c..091676b8961b 100755 --- a/test/shell.d/clock-resync-test.sh +++ b/test/shell.d/clock-resync-test.sh @@ -73,11 +73,11 @@ else $(readlink "$tmp/home/.config/systemd/user/omarchy-clock-resync.service") == "$service" ]] || fail "the migration links the clock resync units for an existing user" pass "the migration links the clock resync units for an existing user" -fi -grep -Fx -- '--user enable omarchy-clock-resync.timer' "$tmp/systemctl.log" >/dev/null || - fail "the migration enables the clock resync timer" -pass "the migration enables the clock resync timer" + grep -Fx -- '--user enable omarchy-clock-resync.timer' "$tmp/systemctl.log" >/dev/null || + fail "the migration enables the clock resync timer" + pass "the migration enables the clock resync timer" +fi # Over SSH there is no user manager to enable into, so the wants symlink is # written directly. From 19139cb3499709253b97707092ce09bdb3359ef6 Mon Sep 17 00:00:00 2001 From: Steve Derico <424734+stevederico@users.noreply.github.com> Date: Sat, 21 Nov 2026 08:12:33 -0800 Subject: [PATCH 4/7] Date the clock resync migration after the ones quattro has run --- migrations/{1792360285.sh => 1795277547.sh} | 0 test/shell.d/clock-resync-test.sh | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename migrations/{1792360285.sh => 1795277547.sh} (100%) diff --git a/migrations/1792360285.sh b/migrations/1795277547.sh similarity index 100% rename from migrations/1792360285.sh rename to migrations/1795277547.sh diff --git a/test/shell.d/clock-resync-test.sh b/test/shell.d/clock-resync-test.sh index 091676b8961b..3dcfcd8d0b84 100755 --- a/test/shell.d/clock-resync-test.sh +++ b/test/shell.d/clock-resync-test.sh @@ -8,7 +8,7 @@ units="$ROOT/default/systemd/user" timer="$units/omarchy-clock-resync.timer" service="$units/omarchy-clock-resync.service" first_run="$ROOT/install/user/first-run/enable-user-units.sh" -migration="$ROOT/migrations/1792360285.sh" +migration="$ROOT/migrations/1793288999.sh" # OnClockChange= is what makes the timer fire when CLOCK_REALTIME jumps against # CLOCK_MONOTONIC, which a resume from suspend does as well as a clock being set. From 3364c8582ea8910327470d76611552349ac55ba4 Mon Sep 17 00:00:00 2001 From: Steve Derico <424734+stevederico@users.noreply.github.com> Date: Sat, 21 Nov 2026 08:12:33 -0800 Subject: [PATCH 5/7] Keep only the systemd unit check in the clock resync test --- test/shell.d/clock-resync-test.sh | 85 +++---------------------------- 1 file changed, 7 insertions(+), 78 deletions(-) diff --git a/test/shell.d/clock-resync-test.sh b/test/shell.d/clock-resync-test.sh index 3dcfcd8d0b84..0b7953f1d3f9 100755 --- a/test/shell.d/clock-resync-test.sh +++ b/test/shell.d/clock-resync-test.sh @@ -5,88 +5,17 @@ set -euo pipefail source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh" units="$ROOT/default/systemd/user" -timer="$units/omarchy-clock-resync.timer" -service="$units/omarchy-clock-resync.service" -first_run="$ROOT/install/user/first-run/enable-user-units.sh" -migration="$ROOT/migrations/1793288999.sh" -# OnClockChange= is what makes the timer fire when CLOCK_REALTIME jumps against -# CLOCK_MONOTONIC, which a resume from suspend does as well as a clock being set. -grep -Fx 'OnClockChange=yes' "$timer" >/dev/null || - fail "the timer fires when the system clock jumps" -grep -Fx 'OnTimezoneChange=yes' "$timer" >/dev/null || - fail "the timer fires when the timezone changes" -pass "the timer fires when the system clock or the timezone changes" +require_command systemd-analyze -# Any calendar or monotonic expression would turn it into a poll. -if grep -Eq '^(OnCalendar|OnActiveSec|OnBootSec|OnStartupSec|OnUnitActiveSec|OnUnitInactiveSec|AccuracySec|RandomizedDelaySec)=' "$timer"; then - fail "the timer waits for the clock to jump instead of counting down to anything" -fi -grep -Fx 'WantedBy=graphical-session.target' "$timer" >/dev/null || - fail "the timer runs with the graphical session" -pass "the timer counts down to nothing and runs with the graphical session" - -grep -Fx 'ExecStart=/usr/bin/omarchy-shell -q omarchy.clock resync' "$service" >/dev/null || - fail "the service tells the shell to resync the clock, quietly" -grep -Fx 'Type=oneshot' "$service" >/dev/null || - fail "the service runs once per jump" -grep -Fx 'ConditionEnvironment=OMARCHY_PATH' "$service" >/dev/null && - grep -Fx 'ConditionEnvironment=WAYLAND_DISPLAY' "$service" >/dev/null || - fail "the service waits for the environment omarchy-shell finds the shell through" -pass "the service tells the running shell to resync the clock" - -# verify also checks that the ExecStart binary exists, so it needs the package. -if command -v systemd-analyze >/dev/null && [[ -x /usr/bin/omarchy-shell ]]; then - verify=$(systemd-analyze --user verify "$timer" "$service" 2>&1) || +# systemd ignores a key it does not know with only a warning, so a misspelt +# OnClockChange= would leave a timer that never fires. verify also checks that +# the ExecStart binary exists, so it needs the package. +if [[ -x /usr/bin/omarchy-shell ]]; then + verify=$(systemd-analyze --user verify "$units/omarchy-clock-resync.timer" "$units/omarchy-clock-resync.service" 2>&1) || fail "systemd accepts the clock resync units" "$verify" [[ -z $verify ]] || fail "systemd accepts the clock resync units" "$verify" pass "systemd accepts the clock resync units" -fi - -grep -F 'omarchy-clock-resync.timer' "$first_run" >/dev/null || - fail "new installs enable the clock resync timer" -pass "new installs enable the clock resync timer" - -# The migration, run for a user whose units are not on the machine yet, with -# systemctl stubbed: it must put them where the user manager looks, then enable -# and start the timer, and a second run must change nothing. -tmp=$(mktemp -d) -trap 'rm -rf "$tmp"' EXIT -mkdir -p "$tmp/bin" "$tmp/home" -cat >"$tmp/bin/systemctl" <<'SH' -#!/bin/bash -printf '%s\n' "$*" >>"$SYSTEMCTL_LOG" -exit 0 -SH -chmod +x "$tmp/bin/systemctl" - -run_migration() { - HOME="$tmp/home" OMARCHY_PATH="$ROOT" SYSTEMCTL_LOG="$tmp/systemctl.log" PATH="$tmp/bin:$PATH" \ - bash "$migration" >/dev/null -} - -if [[ -e /usr/lib/systemd/user/omarchy-clock-resync.timer ]]; then - skip "the package already ships the clock resync units; skipping the install check" else - run_migration - [[ $(readlink "$tmp/home/.config/systemd/user/omarchy-clock-resync.timer") == "$timer" && - $(readlink "$tmp/home/.config/systemd/user/omarchy-clock-resync.service") == "$service" ]] || - fail "the migration links the clock resync units for an existing user" - pass "the migration links the clock resync units for an existing user" - - grep -Fx -- '--user enable omarchy-clock-resync.timer' "$tmp/systemctl.log" >/dev/null || - fail "the migration enables the clock resync timer" - pass "the migration enables the clock resync timer" + skip "systemd accepts the clock resync units: /usr/bin/omarchy-shell is not installed" fi - -# Over SSH there is no user manager to enable into, so the wants symlink is -# written directly. -cat >"$tmp/bin/systemctl" <<'SH' -#!/bin/bash -[[ $* == "--user enable"* ]] && exit 1 -exit 0 -SH -run_migration -[[ -L $tmp/home/.config/systemd/user/graphical-session.target.wants/omarchy-clock-resync.timer ]] || - fail "the migration links the timer in by hand when systemctl cannot enable it" -pass "the migration links the timer in by hand when systemctl cannot enable it" From 8e7064391e6830379eed8d22f3625589beee3bbc Mon Sep 17 00:00:00 2001 From: Steve Derico <424734+stevederico@users.noreply.github.com> Date: Sat, 21 Nov 2026 08:12:33 -0800 Subject: [PATCH 6/7] Keep the first-run unit list sentence on one line --- docs/file-layout.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/file-layout.md b/docs/file-layout.md index bcd496b62bab..d00dfa09484b 100644 --- a/docs/file-layout.md +++ b/docs/file-layout.md @@ -337,8 +337,7 @@ and/or a working user systemd instance: `systemctl --user enable --now` the shipped user units (`bt-agent`, `omarchy-sleep-lock`, `omarchy-recover-internal-monitor`, `omarchy-migrate-notify.service`, `omarchy-fcitx5.service`, - `omarchy-crash-watch.service`, `omarchy-clock-resync.timer`) so they run in the - first session too. + `omarchy-crash-watch.service`, `omarchy-clock-resync.timer`) so they run in the first session too. Done here, not at finalize, because the user manager isn't reachable from the ISO chroot; `ConditionPath*` in the unit files keeps services inert when they don't apply. From e8702b9d02ae79c4499dd17068b3f41378726508 Mon Sep 17 00:00:00 2001 From: Steve Derico <424734+stevederico@users.noreply.github.com> Date: Sat, 21 Nov 2026 11:40:33 -0800 Subject: [PATCH 7/7] Catch WallClock up on resync instead of toggling enabled --- shell/plugins/panels/clock/BarWidget.qml | 13 +++--- shell/plugins/panels/clock/Panel.qml | 3 +- shell/plugins/panels/clock/WallClock.qml | 8 ++++ .../fixtures/bar-widget-contract/shell.qml | 41 +++++++------------ 4 files changed, 30 insertions(+), 35 deletions(-) diff --git a/shell/plugins/panels/clock/BarWidget.qml b/shell/plugins/panels/clock/BarWidget.qml index 37ab663b2c34..a70597ad78b9 100644 --- a/shell/plugins/panels/clock/BarWidget.qml +++ b/shell/plugins/panels/clock/BarWidget.qml @@ -40,14 +40,13 @@ BarWidget { if (panelLoader.item && panelLoader.item.refresh) panelLoader.item.refresh() } - // SystemClock waits out the rest of the minute on a timer that stops during - // suspend, so after a wake the label kept the time from before it for up to a - // minute. Re-enabling the clock re-reads the time and arms its next tick from - // now, and onDateChanged below puts the result on the label. Unlike refresh() - // this leaves a month the user is browsing in the calendar where it is. + // The timer stops during suspend, so after a wake the label kept the time + // from before it for up to a minute. Resyncing re-reads the time and arms + // its next tick from now, and onDateChanged below puts the result on the + // label. Unlike refresh() this leaves a month the user is browsing in the + // calendar where it is. function resync() { - clock.enabled = false - clock.enabled = true + clock.resync() if (panelLoader.item && panelLoader.item.resync) panelLoader.item.resync() } diff --git a/shell/plugins/panels/clock/Panel.qml b/shell/plugins/panels/clock/Panel.qml index 25f18f2ce3ad..11cd57a9ed1e 100644 --- a/shell/plugins/panels/clock/Panel.qml +++ b/shell/plugins/panels/clock/Panel.qml @@ -124,8 +124,7 @@ Panel { // after a sleep that crossed midnight. Its onDateChanged keeps a browsed // month, where refresh() would send it back to today. function resync() { - clock.enabled = false - clock.enabled = true + clock.resync() } function goToToday() { diff --git a/shell/plugins/panels/clock/WallClock.qml b/shell/plugins/panels/clock/WallClock.qml index da1f87a7f36e..560367f212c6 100644 --- a/shell/plugins/panels/clock/WallClock.qml +++ b/shell/plugins/panels/clock/WallClock.qml @@ -18,6 +18,14 @@ Timer { restart() } + // A timer started before suspend keeps counting down that old interval, so + // after a wake (or a stepped system clock) the label stays stale until the + // next tick. Re-read now and arm the next tick from here. + function resync() { + date = new Date() + arm() + } + onStepChanged: arm() onTriggered: { date = new Date() diff --git a/test/shell.d/fixtures/bar-widget-contract/shell.qml b/test/shell.d/fixtures/bar-widget-contract/shell.qml index 6b5132abaab3..1a8718147bad 100644 --- a/test/shell.d/fixtures/bar-widget-contract/shell.qml +++ b/test/shell.d/fixtures/bar-widget-contract/shell.qml @@ -70,50 +70,39 @@ ShellRoot { return null } - // The SystemClock a QML object declares, found by the properties only it has. - function systemClockOf(item) { + // The WallClock a QML object declares, found by the properties only it has. + function wallClockOf(item) { for (var i = 0; i < item.data.length; i++) { var child = item.data[i] - if (child && ("precision" in child) && ("enabled" in child)) return child + if (child && ("step" in child) && ("date" in child) && typeof child.arm === "function") return child } return null } - // How many times a clock was stopped and started while fn ran. - function restartsDuring(clock, fn) { - var restarts = 0 - var count = function() { if (clock.enabled) restarts++ } - clock.enabledChanged.connect(count) - fn() - clock.enabledChanged.disconnect(count) - return restarts - } - - // A wake leaves SystemClock counting down a minute it started before the - // sleep. Re-enabling it is what re-reads the time, so the resync the system - // clock timer asks for has to restart both the label's clock and the + // A wake leaves WallClock counting down an interval it started before the + // sleep. Resyncing is what re-reads the time, so the catch-up the system + // clock timer asks for has to update both the label's clock and the // calendar's, and has to do it without sending a browsed month back to today. function assertClockResyncs(item) { var calendar = calendarOf(item) root.assertTrue(calendar !== null, "omarchy.clock loads its calendar") if (!calendar) return - var labelClock = systemClockOf(item) - var calendarClock = systemClockOf(calendar) - root.assertTrue(labelClock !== null && calendarClock !== null, "omarchy.clock and its calendar each run a SystemClock") + var labelClock = wallClockOf(item) + var calendarClock = wallClockOf(calendar) + root.assertTrue(labelClock !== null && calendarClock !== null, "omarchy.clock and its calendar each run a WallClock") if (!labelClock || !calendarClock) return calendar.viewMonth = (calendar.viewMonth + 3) % 12 var browsed = calendar.viewMonth - var labelRestarts = 0 - var calendarRestarts = restartsDuring(calendarClock, function() { - labelRestarts = restartsDuring(labelClock, function() { item.resync() }) - }) + var stale = new Date(Date.now() - 5 * 60 * 1000) + labelClock.date = stale + calendarClock.date = stale + item.resync() - root.assertEqual(labelRestarts, 1, "omarchy.clock restarts its clock when the system clock jumps") - root.assertEqual(calendarRestarts, 1, "omarchy.clock restarts its calendar's clock when the system clock jumps") - root.assertTrue(labelClock.enabled && calendarClock.enabled, "omarchy.clock leaves both clocks running after a resync") + root.assertTrue(Math.abs(labelClock.date.getTime() - Date.now()) < 2000, "omarchy.clock catches its label up when the system clock jumps") + root.assertTrue(Math.abs(calendarClock.date.getTime() - Date.now()) < 2000, "omarchy.clock catches its calendar up when the system clock jumps") root.assertEqual(calendar.viewMonth, browsed, "omarchy.clock leaves a browsed month alone when the system clock jumps") }