diff --git a/packages/omamobile-shell/plugins/README.md b/packages/omamobile-shell/plugins/README.md index 0580c6726..39d3383e4 100644 --- a/packages/omamobile-shell/plugins/README.md +++ b/packages/omamobile-shell/plugins/README.md @@ -881,13 +881,13 @@ names an output directory). ## Testing in the desktop harness -`phone/dev/run-desktop` copies the shell and runs it in a nested Hyprland, so -point IPC at that copy and its Wayland display, never at -`/usr/share/omarchy/shell` (your real desktop): +`phone/dev/run-desktop` copies the shell into an Omarchy tree of its own and +runs it in a nested Hyprland, so point IPC at that tree and its Wayland +display, never at `/usr/share/omarchy` (your real desktop): ```sh -HOME=~/android/phone-dev/home WAYLAND_DISPLAY=wayland-2 \ - quickshell ipc -p ~/android/phone-dev/shell call shell listPlugins +OMARCHY_PATH=~/android/phone-dev/omarchy WAYLAND_DISPLAY=wayland-2 \ + omarchy-shell shell listPlugins ``` (`quickshell list --all` shows which `wayland-N` the nested shell is on.) diff --git a/phone/README.md b/phone/README.md index 1dee95243..dc4e81728 100644 --- a/phone/README.md +++ b/phone/README.md @@ -17,7 +17,40 @@ inside it. It uses a private home directory under `~/android/phone-dev/home` that links your current Omarchy theme and this directory's plugins, so your real `~/.config/omarchy` is never touched. Plugin edits hot-reload. -Inside the window, `ALT+Return` opens a terminal. +Inside the window, `ALT+Return` opens a terminal. The window never locks on +its own, as in a phone emulator: the harness turns the profile's idle lock +off in its copy of `shell.json`. + +The session has the package's `bin/` on `PATH`, so apps launch through +`omamobile-launch` as on the phone. The helpers that would act on this +computer (`omamobile-bt-agent`, `omamobile-fp-enroll`, `omamobile-set-pin`) +are replaced by stand-ins in `dev/bin` that refuse to run. + +The session shares this computer's D-Bus, so an app that starts through +D-Bus activation (Files, for one) would open on the desktop. `dev/bin`'s +`gtk-launch` starts those without the session bus, so they open in the +window but lose what they do over it (for Files, the Trash, Recent and +Network locations), and what they open has no session bus either: a page +Files opens in the browser starts the browser without its keyring. An app +that hands off to an instance already open on the desktop still opens +there, and that includes the browser and so Omarchy's web apps; while one +started in the window is running, the desktop's own launches of it open in +the window instead. + +The app list shows this computer's own entries too, Omarchy's web apps +among them, and hides what the desktop hides. + +The shell runs from an Omarchy tree of its own, `~/android/phone-dev/omarchy`: +a copy of your Omarchy's shell, with everything else linked to your Omarchy. +`OMARCHY_PATH` points there in the session, so `omarchy-shell` (and the +panels it opens, such as recents) reaches the nested shell and never your +desktop's. A `dev/bin` stand-in keeps that working in a terminal, whose bash +resets `OMARCHY_PATH`, and another refuses `omarchy-restart-shell`, which +would restart your desktop's shell. From a desktop terminal, reach the +nested shell with +`OMARCHY_PATH=~/android/phone-dev/omarchy WAYLAND_DISPLAY=wayland-N omarchy-shell …`. +Harnesses from before this kept the copy in `~/android/phone-dev/shell`; +nothing uses it now, so it can be deleted. ## Layout @@ -26,4 +59,4 @@ Inside the window, `ALT+Return` opens a terminal. | `profile/shell.json` | Phone layout for the shell (bar, plugins, idle) | | `plugins/` | Phone plugins: status bar, quick settings, launcher and agent bar ([plugins/README.md](plugins/README.md)) | | `screenshots/` | The phone profile in the desktop harness | -| `dev/` | Desktop harness: nested Hyprland config and launcher | +| `dev/` | Desktop harness: nested Hyprland config, launcher, and stand-ins for helpers that would act on the desktop (`dev/bin`) | diff --git a/phone/dev/bin/gtk-launch b/phone/dev/bin/gtk-launch new file mode 100755 index 000000000..4142dde68 --- /dev/null +++ b/phone/dev/bin/gtk-launch @@ -0,0 +1,43 @@ +#!/bin/bash +# SPDX-License-Identifier: MIT +# Desktop harness stand-in for gtk-launch, which app launches reach through +# uwsm-app with the caller's PATH (omamobile-launch, Omarchy's app library). +# The nested session shares this computer's session bus, so GIO starts an +# entry with DBusActivatable=true through D-Bus activation, with the user +# manager's environment, and the app opens on the desktop (Files, for one). +# For those entries only, run gtk-launch with its bus address at /dev/null +# (unset, GLib would still find the bus at $XDG_RUNTIME_DIR/bus): GIO then +# runs the entry's Exec here. Every other entry starts as it would anyway. +# +# Limits: +# - an app started without the session bus loses what it does over it: for +# Files, the Trash, Recent and Network locations (moving files to the +# trash still works), and settings changes aren't saved; +# - what such an app opens has no session bus either: a page Files opens in +# the browser starts the browser without its keyring, unless the browser +# is already open on the desktop; +# - an app that hands off to an instance already open on the desktop +# (Telegram, Brave) still opens there. +# +# GIO activates an entry over D-Bus only when its name is a bus name, as +# org.gnome.Nautilus is, so the check below asks the same of the entry GIO +# resolves. It runs /usr/bin/python3: a python3 earlier on PATH (mise, a +# virtualenv) may have no PyGObject, and the app would open on the desktop. +if [[ -n ${1:-} && $1 != -* ]] && /usr/bin/python3 -I - "$1" <<'EOF' +import os, sys +import gi +gi.require_version("GioUnix", "2.0") +from gi.repository import Gio, GioUnix +app_id = sys.argv[1] if sys.argv[1].endswith(".desktop") else sys.argv[1] + ".desktop" +try: + app = GioUnix.DesktopAppInfo.new(app_id) +except TypeError: # no such entry, which gtk-launch reports itself + sys.exit(1) +name = os.path.basename(app.get_filename()).removesuffix(".desktop") +bus_name = Gio.dbus_is_name(name) and not name.startswith(":") +sys.exit(0 if app.get_boolean("DBusActivatable") and bus_name else 1) +EOF +then + export DBUS_SESSION_BUS_ADDRESS=unix:path=/dev/null +fi +exec /usr/bin/gtk-launch "$@" diff --git a/phone/dev/bin/omamobile-bt-agent b/phone/dev/bin/omamobile-bt-agent new file mode 100755 index 000000000..670267ac8 --- /dev/null +++ b/phone/dev/bin/omamobile-bt-agent @@ -0,0 +1,8 @@ +#!/bin/bash +# SPDX-License-Identifier: MIT +# Desktop harness stand-in for omamobile-bt-agent, which would make itself the +# default Bluetooth agent of this computer. The error event is what the +# quick-settings Bluetooth panel shows. +echo '{"event": "error", "message": "Not available in the desktop harness"}' +echo "omamobile-bt-agent: not run in the desktop harness: it would act on this computer's Bluetooth" >&2 +exit 1 diff --git a/phone/dev/bin/omamobile-fp-enroll b/phone/dev/bin/omamobile-fp-enroll new file mode 100755 index 000000000..521273b7a --- /dev/null +++ b/phone/dev/bin/omamobile-fp-enroll @@ -0,0 +1,10 @@ +#!/bin/bash +# SPDX-License-Identifier: MIT +# Desktop harness stand-in for omamobile-fp-enroll, which would enroll on this +# computer's fingerprint reader through fprintd. The fingerprint plugin then +# reports no sensor. +if [[ ${1:-} == enroll ]]; then + echo '{"event": "error", "kind": "no-device", "message": "Not available in the desktop harness"}' +fi +echo "omamobile-fp-enroll: not run in the desktop harness: it would act on this computer's fingerprint reader" >&2 +exit 1 diff --git a/phone/dev/bin/omamobile-set-pin b/phone/dev/bin/omamobile-set-pin new file mode 100755 index 000000000..e85979226 --- /dev/null +++ b/phone/dev/bin/omamobile-set-pin @@ -0,0 +1,6 @@ +#!/bin/bash +# SPDX-License-Identifier: MIT +# Desktop harness stand-in for omamobile-set-pin, which sets the account +# password: on this computer, the password of the desktop's own account. +echo "omamobile-set-pin: not run in the desktop harness: it would change this computer's account password" >&2 +exit 1 diff --git a/phone/dev/bin/omarchy-restart-shell b/phone/dev/bin/omarchy-restart-shell new file mode 100755 index 000000000..184354543 --- /dev/null +++ b/phone/dev/bin/omarchy-restart-shell @@ -0,0 +1,9 @@ +#!/bin/bash +# SPDX-License-Identifier: MIT +# Desktop harness stand-in for omarchy-restart-shell (the menu's Update > +# Process > Shell, omarchy-font-set, omarchy-refresh-shell). The real one +# takes OMARCHY_PATH from the systemd user manager, which is the desktop's, +# and stops that shell on every display: from here it would restart this +# computer's desktop shell. +echo "omarchy-restart-shell: not run in the desktop harness: it would restart this computer's desktop shell; close and reopen run-desktop instead" >&2 +exit 1 diff --git a/phone/dev/bin/omarchy-shell b/phone/dev/bin/omarchy-shell new file mode 100755 index 000000000..5e00f8f84 --- /dev/null +++ b/phone/dev/bin/omarchy-shell @@ -0,0 +1,8 @@ +#!/bin/bash +# SPDX-License-Identifier: MIT +# Desktop harness stand-in for omarchy-shell. The nested shell runs from +# run-desktop's own Omarchy tree, which an interactive bash takes out of +# OMARCHY_PATH again (Omarchy's env-bootstrap), so put it back and run the +# real omarchy-shell from that tree. +export OMARCHY_PATH="${PHONE_DEV_OMARCHY_PATH:?not in the desktop harness}" +exec "$OMARCHY_PATH/bin/omarchy-shell" "$@" diff --git a/phone/dev/hyprland.lua b/phone/dev/hyprland.lua index 0c75e6256..b436ee14e 100644 --- a/phone/dev/hyprland.lua +++ b/phone/dev/hyprland.lua @@ -20,8 +20,9 @@ hl.config({ misc = { disable_hyprland_logo = true, disable_splash_rendering = true, disable_watchdog_warning = true }, }) --- The outer desktop owns SUPER, so the phone session uses ALT -hl.bind("ALT + RETURN", hl.dsp.exec_cmd("alacritty"), { description = "Terminal" }) +-- The outer desktop owns SUPER, so the phone session uses ALT. The default +-- terminal, started directly rather than through uwsm, opens in this session +hl.bind("ALT + RETURN", hl.dsp.exec_cmd("xdg-terminal-exec"), { description = "Terminal" }) hl.on("hyprland.start", function() -- Omarchy's shell, from the dev copy, with the phone profile's home directory diff --git a/phone/dev/run-desktop b/phone/dev/run-desktop index 0db97a5a3..54e41eaf2 100755 --- a/phone/dev/run-desktop +++ b/phone/dev/run-desktop @@ -8,20 +8,56 @@ set -euo pipefail ROOT="$(cd "$(dirname "$(readlink -f "$0")")/../.." && pwd)" -DEV="${PHONE_DEV:-$HOME/android/phone-dev}" -OMARCHY_PATH="${OMARCHY_PATH:-/usr/share/omarchy}" +# Absolute and without a trailing slash: omarchy-shell finds the shell by +# this exact string (qs ipc, and from Omarchy 4.5 the shell's socket name) +DEV="$(realpath -m -- "${PHONE_DEV:-$HOME/android/phone-dev}")" +OMARCHY_SRC="$(readlink -f -- "${OMARCHY_PATH:-/usr/share/omarchy}")" +LAYOUT="$DEV/omarchy" FAKE_HOME="$DEV/home" -# A private copy of the shell gives it its own config path, so IPC calls -# can't reach the desktop's running shell by accident (and vice versa) -mkdir -p "$DEV" -rsync -a --delete "$OMARCHY_PATH/shell/" "$DEV/shell/" +if [[ -n ${PHONE_DEV_OMARCHY_PATH:-} ]]; then + echo "run-desktop: run it from the desktop, not from inside the harness" >&2 + exit 1 +fi +if [[ ! -f $OMARCHY_SRC/shell/shell.qml ]]; then + echo "run-desktop: no Omarchy shell in $OMARCHY_SRC" >&2 + exit 1 +fi + +# The nested session's own Omarchy tree. Its shell is a private copy, which +# gives it its own config path, so IPC calls can't reach the desktop's +# running shell by accident (and vice versa); the rest links to the real +# tree. OMARCHY_PATH points here in the nested session, so omarchy-shell +# finds the nested shell at $OMARCHY_PATH/shell. +mkdir -p "$LAYOUT" +rsync -a --delete "$OMARCHY_SRC/shell/" "$LAYOUT/shell/" +for entry in "$OMARCHY_SRC"/*; do + name=${entry##*/} + [[ $name == shell ]] && continue + # ln -sfn onto a real directory would put the link inside it + if [[ -L $LAYOUT/$name || ! -e $LAYOUT/$name ]]; then + ln -sfn "$entry" "$LAYOUT/$name" + fi +done +# Links to what a newer Omarchy no longer has +find "$LAYOUT" -mindepth 1 -maxdepth 1 -xtype l -delete mkdir -p "$FAKE_HOME/.config/omarchy" "$FAKE_HOME/.local/state/omarchy" ln -sfn "$HOME/.local/state/omarchy/current" "$FAKE_HOME/.local/state/omarchy/current" ln -sfn "$ROOT/packages/omamobile-shell/plugins" "$FAKE_HOME/.config/omarchy/plugins" -# Copied, not linked: the shell writes to shell.json when settings change -cp "$ROOT/packages/omamobile-shell/profile/shell.json" "$FAKE_HOME/.config/omarchy/shell.json" +# Copied, not linked: the shell writes to shell.json when settings change. +# Without the idle lock (0 is off), as a phone emulator never locks: the +# profile's lock after 60 s would lock the window behind this computer's +# account password, and omarchy-system-lock's cleanup reaches the desktop. +python3 -I - "$ROOT/packages/omamobile-shell/profile/shell.json" "$FAKE_HOME/.config/omarchy/shell.json" <<'EOF' +import json, sys +with open(sys.argv[1]) as f: + config = json.load(f) +config.setdefault("idle", {})["lock"] = 0 +with open(sys.argv[2], "w") as f: + json.dump(config, f, indent=2) + f.write("\n") +EOF # Once the nested window appears on the desktop, float it at the phone's # 13:6 aspect. Uses the desktop compositor's own dispatchers; no config changes. @@ -41,5 +77,25 @@ print(c[-1]["address"] if c else "")') done ) & -export PHONE_DEV_SHELL_CMD="env HOME=$FAKE_HOME OMARCHY_PATH=$OMARCHY_PATH quickshell -p $DEV/shell" +# The phone package's commands, as on the phone (every launch goes through +# omamobile-launch), behind dev/bin's stand-ins for those that would act on +# this computer +export PATH="$ROOT/phone/dev/bin:$ROOT/packages/omamobile-shell/bin:$PATH" + +# The nested session's Omarchy, for everything it starts. An interactive +# bash sets OMARCHY_PATH back to the system's (Omarchy's env-bootstrap), so +# dev/bin's omarchy-shell takes it from PHONE_DEV_OMARCHY_PATH. +export OMARCHY_PATH="$LAYOUT" PHONE_DEV_OMARCHY_PATH="$LAYOUT" + +# The shell has its own HOME, and Omarchy's app library looks in +# $HOME/.local/share for which entries are hidden and for icons (and, +# without uwsm's XDG_DATA_HOME, for this computer's own entries, Omarchy's +# web apps among them). So the real data directory goes first in the +# shell's XDG_DATA_DIRS, for omamobile-launch too, and its entries win over +# the system's as they do on the desktop. +data_dirs="${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}" +# Hyprland runs it with sh -c +printf -v PHONE_DEV_SHELL_CMD '%q ' env HOME="$FAKE_HOME" OMARCHY_PATH="$OMARCHY_PATH" \ + XDG_DATA_DIRS="$data_dirs" quickshell -p "$OMARCHY_PATH/shell" +export PHONE_DEV_SHELL_CMD exec env -u HYPRLAND_INSTANCE_SIGNATURE Hyprland -c "$ROOT/phone/dev/hyprland.lua"