Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions default/systemd/user/omarchy-clock-resync.service
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions default/systemd/user/omarchy-clock-resync.timer
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion docs/file-layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +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`) 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.
Expand Down
6 changes: 6 additions & 0 deletions docs/omarchy-shell.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 11 additions & 1 deletion install/user/first-run/enable-user-units.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
34 changes: 34 additions & 0 deletions migrations/1795277547.sh
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions shell/plugins/panels/clock/BarWidget.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved
}

function cycleFormat() {
var current = String(configuredFormat)
var next = Model.nextClockFormat(formatRing, current)
Expand Down Expand Up @@ -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() }
Expand Down
8 changes: 8 additions & 0 deletions shell/plugins/panels/clock/Panel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
21 changes: 21 additions & 0 deletions test/shell.d/clock-resync-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

set -euo pipefail

source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"

units="$ROOT/default/systemd/user"

require_command systemd-analyze

# 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"
else
skip "systemd accepts the clock resync units: /usr/bin/omarchy-shell is not installed"
fi
5 changes: 3 additions & 2 deletions test/shell.d/config-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
12 changes: 11 additions & 1 deletion test/shell.d/first-run-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand All @@ -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
Expand Down
56 changes: 56 additions & 0 deletions test/shell.d/fixtures/bar-widget-contract/shell.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved
}
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) {
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/shell.d/owe-integration-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading