Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
5 changes: 1 addition & 4 deletions agents/skills/shell-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

Read this before editing the Quickshell desktop under `shell/`.

The Quickshell desktop runs as a single long-running process out of
`shell/`. Hyprland autostart launches it directly with `quickshell -n -p`;
do not start additional standalone Quickshell instances for individual
components.
The plugin-hosting desktop runs as one long-running process out of `shell/`, supervised by `omarchy-launch-shell`. Do not start additional standalone Quickshell instances for individual plugins. The small `shell/bar-reservation/` companion is deliberately independent: it owns bar space while the plugin host restarts or crashes and never loads plugins. See [`docs/bar-reservation.md`](../../docs/bar-reservation.md) for its lifecycle and VM testing requirements.

Run `omarchy-restart-shell` after making changes to QML files.

Expand Down
29 changes: 29 additions & 0 deletions bin/omarchy-launch-shell
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,33 @@
# omarchy:summary=Launch the Omarchy shell with its log kept in the journal
# omarchy:hidden=true

# Keep the reservation host outside the process that loads plugins. The display
# hash keeps the Unix socket short and separates simultaneous Wayland sessions.
bar_reservation_call() {
[[ -n ${OMARCHY_BAR_SOCKET:-} ]] || return 0
timeout --kill-after=1s 1s quickshell ipc -n -p "$OMARCHY_PATH/shell/bar-reservation" call reservation "$1" >/dev/null 2>&1 || true
}

unset OMARCHY_BAR_SOCKET OMARCHY_BAR_CLIENT
if [[ -n ${XDG_RUNTIME_DIR:-} && -n ${WAYLAND_DISPLAY:-} && -f $OMARCHY_PATH/shell/bar-reservation/shell.qml ]]; then
bar_display_id=$(printf '%s' "$WAYLAND_DISPLAY" | sha256sum | cut -c1-16)
export OMARCHY_BAR_SOCKET="$XDG_RUNTIME_DIR/omarchy-bar-$bar_display_id.sock"
if ! QS_DISABLE_FILE_WATCHER=1 QS_NO_RELOAD_POPUP=1 \
timeout --kill-after=1s 5s quickshell -d -n -p "$OMARCHY_PATH/shell/bar-reservation" >/dev/null 2>&1 ||
! bar_reservation_reply=$(timeout --kill-after=1s 1s quickshell ipc -n -p "$OMARCHY_PATH/shell/bar-reservation" call reservation ping 2>/dev/null) ||
[[ $bar_reservation_reply != "ok" ]]; then
# The daemon launcher can exit 0 even when its QML failed to load.
logger -t omarchy-shell "Bar reservation host unavailable; using the bar's own exclusive zone."
unset OMARCHY_BAR_SOCKET
fi
fi
if [[ -n ${OMARCHY_BAR_SOCKET:-} ]]; then
# Quickshell re-execs itself after SIGSEGV while its core-dump child can
# still hold the old socket. Preserve one logical owner across that exec.
read -r OMARCHY_BAR_CLIENT </proc/sys/kernel/random/uuid
export OMARCHY_BAR_CLIENT
fi

# Quickshell only logs to its instance runtime dir (tmpfs), so when the shell
# dies the idle/lock event trail is gone after a reboot. The journal keeps it
# across sessions, bounded and timestamped, under the omarchy-shell tag.
Expand Down Expand Up @@ -83,9 +110,11 @@ while true; do

if (( ++attempts > 5 )); then
logger -t omarchy-shell "Giving up on the Omarchy shell after $attempts relaunches in under a minute."
bar_reservation_call failed
exit 1
fi

bar_reservation_call crashed
logger -t omarchy-shell "Omarchy shell exited with status $status; relaunching."
sleep 1
done
30 changes: 24 additions & 6 deletions bin/omarchy-restart-shell
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,26 @@ session_omarchy_path=$(systemctl --user show-environment 2>/dev/null | sed -n 's
CONFIG_DIR="$session_omarchy_path/shell"
[[ -f $CONFIG_DIR/shell.qml ]] || { echo "Omarchy shell config not found: $CONFIG_DIR" >&2; exit 1; }

# Allow running from outside the session (e.g. over ssh) by deriving the
# Hyprland instance signature from the newest instance runtime dir.
if [[ -z ${HYPRLAND_INSTANCE_SIGNATURE:-} ]]; then
hypr_dir=$(find "${XDG_RUNTIME_DIR:-/run/user/$UID}/hypr" -mindepth 1 -maxdepth 1 -type d -printf '%T@ %p\n' 2>/dev/null | sort -n | tail -n 1 | cut -d' ' -f2-)
[[ -n $hypr_dir ]] && export HYPRLAND_INSTANCE_SIGNATURE=${hypr_dir##*/}
# Bind every IPC and kill to the compositor being restarted. An SSH caller may
# have no display; --any-display would instead select another session's host
# and kill its healthy main shell. An explicit signature takes precedence over
# a stale caller display. Without either, choose the newest live compositor.
session=$(hyprctl instances -j 2>/dev/null | jq -er \
--arg signature "${HYPRLAND_INSTANCE_SIGNATURE:-}" --arg display "${WAYLAND_DISPLAY:-}" '
(if $signature != "" then map(select(.instance == $signature))
elif $display != "" then map(select(.wl_socket == $display))
else . end) | max_by(.time) | select(. != null) |
select((.instance | type) == "string" and (.wl_socket | type) == "string") |
[.instance, .wl_socket] | @tsv') || {
echo "Could not identify the Hyprland session to restart." >&2
exit 1
}
IFS=$'\t' read -r HYPRLAND_INSTANCE_SIGNATURE WAYLAND_DISPLAY <<<"$session"
if [[ -z $HYPRLAND_INSTANCE_SIGNATURE || -z $WAYLAND_DISPLAY ]]; then
echo "Hyprland did not report a display for the session to restart." >&2
exit 1
fi
export HYPRLAND_INSTANCE_SIGNATURE WAYLAND_DISPLAY

# Restarting a live lock client would kill the lock screen and strand the
# session behind Hyprland's failsafe. But a LOCK session without an active
Expand Down Expand Up @@ -76,9 +90,13 @@ if notifications_ready; then
notifications_were_running=1
fi

# Announce a deliberate restart before the bar disappears. Failure of the
# reservation host must not prevent recovery of the main shell.
timeout --kill-after=1s 1s quickshell ipc -n -p "$CONFIG_DIR/bar-reservation" call reservation restarting >/dev/null 2>&1 || true

# Each kill stops the oldest matching instance and only returns once it has
# fully exited, so the no-duplicate launch below can't race a dying shell.
while timeout 5 quickshell kill -p "$CONFIG_DIR" --any-display >/dev/null 2>&1; do :; done
while timeout 5 quickshell kill -p "$CONFIG_DIR" >/dev/null 2>&1; do :; done

# Spawn from Hyprland so the shell inherits the canonical session environment,
# not transient variables from a terminal, SSH connection, or development tool.
Expand Down
39 changes: 39 additions & 0 deletions docs/bar-reservation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Bar space during shell recovery

The built-in bar keeps its screen space when plugins reload or the main shell stops. An independent Quickshell configuration at `shell/bar-reservation/` owns the layer-shell exclusive zones. The interactive bar uses `ExclusionMode.Ignore`, so it occupies that same strip without reserving it a second time.

The reservation process loads no plugins, authentication services, or main-shell singletons. Its surfaces sit on the bottom layer, accept no pointer or keyboard input, and are transparent during normal operation. During an outage they use the last bar colors and show a short status message. Fullscreen windows can cover them normally; session-lock surfaces remain above them.

![The bar space remains reserved while the shell restarts.](images/bar-recovery.png)

## Lifetime and state

`omarchy-launch-shell` starts one reservation host per configuration and Wayland display with `quickshell -d -n`. A socket under `XDG_RUNTIME_DIR`, named using a hash of the display name, connects the two processes. The socket is private to the user's runtime directory; this is coordination between processes belonging to the same user, not a security boundary against that user.

The main shell sends bounded, versioned JSON containing only screen names, edge, thickness, visibility, readiness, and opaque foreground/background colors. Incomplete and oversized frames and invalid fields are rejected. The receiver retains detached scalar values, accepts one active owner, and never evaluates code or starts commands supplied through the protocol. Loading a new bar does not clear the previous snapshot.

The host retains the last reservation when the connection closes. If a replacement shell sends an unsupported snapshot, the host releases that ownerless reservation before disconnecting it, so the replacement can safely reserve its own space. Rejecting a second client while an owner is still connected never releases the owner's reservation. A launcher UUID survives Quickshell’s crash-handler re-exec, allowing the replacement to take over from its own inherited socket while a core-dump child still holds it open. A different launcher cannot take over a live reservation. A deliberate restart announces “Shell restarting…”, including when requested outside the desktop’s environment. The restart command resolves the selected Hyprland instance to its Wayland display, and scopes both notification and shell shutdown to that display; an explicit stale instance fails without touching another session. The existing launcher reports “Shell crashed — restarting…” when it retries an abnormal exit, and “Shell stopped — restart required” when its retry budget is exhausted. A clean stop without a restart request shows “Shell unavailable”. These messages describe observed lifecycle events; there is no speculative crash diagnosis.

The launcher requires a successful `ping` response before passing the reservation socket to the main shell; a successful daemon launch alone does not prove that the host's QML loaded. Without a configured socket, the built-in bar maps immediately and owns its own zone. With one, it waits for the initial snapshot acknowledgement and initial widget loading, with a two-second fallback, before mapping. If the reservation process disconnects, the bar resumes owning its own zone. A transport connection alone never relinquishes that fallback reservation: the client waits for the host to acknowledge its snapshot. Reconnection uses a fresh socket for compatibility with Quickshell 0.3.1 and backs off from one second to at most thirty seconds after failed attempts. An accepted snapshot resets that delay, and configuration changes shorten it so corrected settings recover promptly. A failure of the reservation host must not prevent launching or restarting the main shell.

## Configuration and monitors

The main shell supplies the actual bar thickness, including theme changes and sizes above 256 pixels, and updates all connected screen names. The protocol accepts the same nonnegative signed 32-bit sizes as the native bar and exclusive-zone properties. Each reservation surface is tied to its `QuickshellScreen`, so unplugging a screen removes that surface. A newly connected screen receives a reservation once the main shell publishes it. A returning screen with a previously known name can retain its last reservation while the main shell is down.

Hidden bars reserve no space. While the shell is ready, its current hidden-state snapshot takes precedence over the host’s flag cache, so a missed directory event cannot override a successful `syncHidden`. During outages the host watches and rechecks the existing `bar-off` flag once per second, so the user can release the space while the main shell is unavailable. Moving the bar to another edge is an intentional layout change. Shell recovery at that edge preserves the resulting layout.

Full replacement bars from third-party plugins continue to own their existing exclusive zones; selecting one releases the built-in reservation. Arbitrary third-party surfaces cannot be moved between processes without changing their plugin contract. This change protects the built-in bar and its hosted widgets, not every possible replacement bar implementation.

## Limits

A second Qt Quick process has a resource cost. The accelerated QA VM measured approximately 80 MiB proportional resident memory for this process after repeated restarts; that figure depends on Qt, the graphics driver, and monitor configuration.

The reservation host itself still depends on the compositor and Qt. Losing that host or the entire compositor can cause a layout change. Its job is to survive failure or restart of the much larger process that loads plugins. It does not add a new restart policy for the main shell, override intentional stops, or restart a healthy lock client.

The reservation host stays running across main-shell restarts; changes to its QML take effect at the next session start. During development, stop its specific configuration in the disposable VM before restarting the main shell. Do not restart every Quickshell process indiscriminately.

## Verification

`test/shell.d/bar-reservation-test.sh` covers the state protocol and bounded frame assembly. `test/shell.d/bar-reservation-lifecycle-test.sh` runs the actual host and client QML with isolated homes and runtime directories on Qt's offscreen platform. It checks unset sockets, acknowledgement before handoff, missed hidden-flag events, large bars, display isolation, duplicate ownership, re-exec while an inherited socket remains open, invalid replacements after restart, rejection backoff, corrected settings, and hosts that return after a failed connection. Only the host's layer-shell surface is replaced for this test; compositor geometry is checked in the VM. The launcher and restart tests cover readiness failures, recovery messages, abnormal exits, retry limits, session environment, duplicate main-shell instances, and lock preservation.

Run `test/acceptance.d/bar-reservation-test.sh` in a disposable Omarchy VM. It opens a real tiled terminal, samples its position and size and the compositor's reservations throughout deliberate outages, restarts, `SIGKILL`, and `SIGSEGV`. A changed PID or layer-surface address proves that recovery completed; Quickshell re-execs in the same PID after `SIGSEGV`. It exercises all four edges, repeated restarts, hidden, transparent and 300-pixel bars, and host reconnection; saves the samples as JSON, captures screenshots, and restores configuration and the test window on exit. This graphical test is excluded from `test/all`.
Binary file added docs/images/bar-recovery.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 36 additions & 0 deletions shell/bar-reservation/State.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Only scalar display data crosses from the plugin host into the reservation host.
function parse(text) {
if (typeof text !== "string" || text.length > 16384) return null
var value
try { value = JSON.parse(text) } catch (_) { return null }
if (!value || value.version !== 1) return null
var client = value.client === undefined ? "" : value.client
if (typeof client !== "string" || (client !== "" && !/^[0-9a-f-]{36}$/.test(client))) return null
if (value.loading === true) return { loading: true, client: client }
if (!Array.isArray(value.screens) || value.screens.length > 32) return null
if (["top", "bottom", "left", "right"].indexOf(value.position) < 0) return null
// barSize and the layer-shell exclusive zone are signed 32-bit integers.
// Do not impose a smaller limit than the bar's actual configuration supports.
if (!Number.isInteger(value.size) || value.size < 0 || value.size > 2147483647) return null
if (typeof value.hidden !== "boolean" || typeof value.ready !== "boolean") return null
var names = []
for (var i = 0; i < value.screens.length; i++) {
var name = value.screens[i]
if (typeof name !== "string" || name.length > 128 || names.indexOf(name) >= 0) return null
names.push(name)
}
var color = /^#[0-9a-fA-F]{6}$/
if (!color.test(value.background) || !color.test(value.foreground)) return null
return { loading: false, client: client, screens: names, position: value.position, size: value.size,
hidden: value.hidden, ready: value.ready, background: value.background, foreground: value.foreground }
}
// SplitParser's empty marker delivers chunks without accumulating an unbounded
// unfinished line in C++. Bound our own buffer before attempting JSON parsing.
function append(pending, chunk) {
if (pending.length + chunk.length > 65536) return null
var lines = (pending + chunk).split("\n")
var rest = lines.pop()
if (rest.length > 16384 || lines.some(function(line) { return line.length > 16384 })) return null
return { lines: lines, pending: rest }
}
if (typeof module !== "undefined") module.exports = { parse, append }
Loading