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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ release is checked here and released on by hand.
the on-screen keyboard stays above the control center until it is put
away, instead of being covered by it where it couldn't be dismissed.

- `omarchy-restart-shell` works on the tablet. It restarts the shell in the
Labwc session, also from ssh, and brings the PIN back after a shell that
died while locked.

## [0.4.8] - 2026-12-03

### Desktop
Expand Down
68 changes: 68 additions & 0 deletions desktop/shell/bin/omarchy-restart-shell
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/bin/bash

# omarchy:summary=Restart the Omarchy shell
# omarchy:examples=omarchy restart shell

# The tablet's own version of upstream's command, which asks Hyprland; the
# tablet runs Labwc. It also works from outside the session (ssh, a TTY),
# which is when it is needed most: a shell that died leaves the screen as it
# was, with nothing that takes a tap.
#
# The new shell gets the environment Labwc gives the programs it starts, so
# the commands it runs and the display it registers under (which omarchy-shell
# and Settings look it up by) are the session's. It runs as a service of the
# user's systemd: polkit counts that as the graphical session, which
# NetworkManager's rule asks for (60-omarchy-tablet-network.rules), and a
# process started from ssh directly is not.
#
# Like the session's first shell it starts locked (OMARCHY_START_LOCKED): one
# that died while locked leaves the session locked with nothing on it, and
# only a new lock brings the PIN back.

set -euo pipefail

runtime=${XDG_RUNTIME_DIR:-/run/user/$UID}
export XDG_RUNTIME_DIR=$runtime
export DBUS_SESSION_BUS_ADDRESS=${DBUS_SESSION_BUS_ADDRESS:-unix:path=$runtime/bus}

labwc=$(pgrep -u "$UID" -xo labwc) || { echo "Omarchy shell: no Labwc session to restart it in." >&2; exit 1; }
display=$(ls -t "$runtime"/wayland-[0-9]* 2>/dev/null | grep -v '\.lock$' | head -n1) ||
{ echo "Omarchy shell: Labwc's display is not there." >&2; exit 1; }

# Labwc's own environment, and what it adds for the programs it starts.
setenv=()
while IFS= read -r -d '' variable; do
case ${variable%%=*} in _ | PWD | OLDPWD | SHLVL) continue ;; esac
setenv+=("--setenv=$variable")
done < "/proc/$labwc/environ"
setenv+=("--setenv=WAYLAND_DISPLAY=${display##*/}" "--setenv=LABWC_PID=$labwc")

omarchy_path=$(tr '\0' '\n' < "/proc/$labwc/environ" | sed -n 's/^OMARCHY_PATH=//p')
config="${omarchy_path:-/usr/share/omarchy}/shell/shell.qml"
[[ -f $config ]] || { echo "Omarchy shell config not found: $config" >&2; exit 1; }

# The session's shell: Labwc's autostart's (qs), or an earlier restart's
# (systemd-run gives it as /usr/bin/qs).
shell="(.*/)?qs -p $config"
systemctl --user stop omarchy-shell.service 2>/dev/null || true
pkill -u "$UID" -xf "$shell" || true
for _ in {1..50}; do
pgrep -u "$UID" -xf "$shell" >/dev/null || break
sleep 0.1
done

systemd-run --user --unit=omarchy-shell --collect --quiet \
-p WorkingDirectory="$HOME" -p StandardOutput="truncate:$runtime/omarchy-shell.log" \
"${setenv[@]}" qs -p "$config"

# Ready when it answers on its IPC, as Settings and the bar's buttons reach it.
export WAYLAND_DISPLAY=${display##*/} OMARCHY_PATH=${omarchy_path:-/usr/share/omarchy}
for _ in {1..100}; do
if OMARCHY_SHELL_IPC_TIMEOUT=0.5s omarchy-shell lock status >/dev/null 2>&1; then
echo "Omarchy shell restarted."
exit 0
fi
sleep 0.2
done
echo "Omarchy shell did not become ready after restart; see $runtime/omarchy-shell.log" >&2
exit 1
29 changes: 29 additions & 0 deletions tests/test_restart_shell_labwc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""omarchy-restart-shell restarts the shell into the Labwc session (desktop/shell/bin)."""
from pathlib import Path
import unittest

SCRIPT = Path(__file__).resolve().parents[1] / 'desktop/shell/bin/omarchy-restart-shell'


class RestartShellLabwc(unittest.TestCase):
def setUp(self):
self.text = SCRIPT.read_text()

def test_it_asks_labwc_not_hyprland(self):
self.assertNotIn('hyprctl', self.text)
self.assertIn('pgrep -u "$UID" -xo labwc', self.text)

def test_the_new_shell_has_the_sessions_display_and_environment(self):
self.assertIn('< "/proc/$labwc/environ"', self.text)
self.assertIn('--setenv=WAYLAND_DISPLAY=', self.text)

def test_it_runs_under_the_users_systemd_for_polkit(self):
self.assertIn('systemd-run --user --unit=omarchy-shell', self.text)

def test_it_replaces_labwcs_shell_and_an_earlier_restarts(self):
self.assertIn('shell="(.*/)?qs -p $config"', self.text)
self.assertIn('systemctl --user stop omarchy-shell.service', self.text)


if __name__ == '__main__':
unittest.main()