Motion-Wallpaper-Omarchy/wallpaper.sh
Gavin Nugent ee9d894ad9 TUI: float from Walker, follow Omarchy theme, center the layout
Launcher
  - .desktop now wraps the toggle in `xdg-terminal-exec --app-id=TUI.float`
    so Hyprland's existing floating-window rule treats it like btop / impala
    instead of opening a tiled fullscreen terminal.

Theme integration
  - Read ~/.config/omarchy/current/theme/colors.toml at startup; map
    accent/color1/color2/color8 → COLOR_ACCENT/ERROR/OK/MUTED. Catppuccin
    fallback if the file is missing.
  - Push the theme into gum's own widget chrome (cursor, selected row,
    headers, prompts, confirm) via GUM_* env vars so the menu cursor and
    highlight follow the active theme instead of gum's pink defaults.

Centered layout
  - Compute panel width / margin / top-pad from `tput cols` + `tput lines`.
  - Status panel rendered with --margin to center horizontally; title
    centered inside the box.
  - GUM_CHOOSE_CURSOR padded with PANEL_INDENT so menu rows line up with
    the panel's left edge.
  - prompt_header indents the per-prompt label and appends a centered,
    muted nav hint; gum's flush-left help footer suppressed via
    GUM_CHOOSE_SHOW_HELP=false (also filter / file).
  - center_screen() clears + pads before each gum prompt so the UI sits
    vertically centered on every navigation step.

Stopped-state menu
  - Replaced the "panel flashes then drops into file picker" flow with a
    gum-choose menu first: Start with <last video> / Pick a video and
    start / Turn autostart ON|OFF / Cancel. Status panel stays visible.

$HOME-confined browser
  - Replaced gum file (alt-screen, can navigate above $HOME via its
    built-in up key) with a gum-choose-driven browser. The "Up one
    folder" entry is omitted when at $HOME, so escape is structurally
    impossible. Lists folders first, then video files; remembers
    LAST_DIR; bounces back to $HOME on empty leaves and bails if even
    $HOME has no entries (instead of looping).

Centralized strings
  - All ~50 user-facing labels live in a single TXT_* block at the top
    of the script, grouped by purpose (header / menu / confirm /
    success / error / notification). Format strings use printf %s.

Robustness
  - Clamp PANEL_WIDTH ≤ TERM_COLS for narrow floating windows.
  - Empty-dir warning rendered with the same horizontal margin as
    everything else.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-25 13:45:08 +01:00

185 lines
6.3 KiB
Bash
Executable file

#!/usr/bin/env bash
# ==============================================================================
# Motion Wallpaper Installer for Omarchy / Hyprland
#
# Installs:
# ~/.local/bin/motion-wallpaper-toggle runtime TUI
# ~/.local/bin/motion-wallpaper-watcher auto-pause watcher
# ~/.local/bin/motion-wallpaper-theme-watcher theme-change watcher
# ~/.local/share/applications/motion-wallpaper-toggle.desktop app entry
# ~/.local/share/icons/hicolor/scalable/apps/motion-wallpaper.svg icon
# ~/.config/systemd/user/motion-wallpaper.service optional autostart unit
#
# Dependencies:
# mpv, jq, gum, socat, libnotify (pacman)
# mpvpaper (AUR, via yay or paru)
# ==============================================================================
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
echo "=== Motion wallpaper installer for Omarchy / Hyprland ==="
if ! command -v pacman >/dev/null 2>&1; then
echo "This script expects a pacman-based system (Arch/Omarchy). Aborting." >&2
exit 1
fi
# ----- source files ------------------------------------------------------------
TOGGLE_SRC="$SCRIPT_DIR/motion-wallpaper-toggle"
WATCHER_SRC="$SCRIPT_DIR/motion-wallpaper-watcher"
THEME_WATCHER_SRC="$SCRIPT_DIR/motion-wallpaper-theme-watcher"
UNIT_SRC="$SCRIPT_DIR/motion-wallpaper.service"
ICON_SRC="$SCRIPT_DIR/icons/motion-wallpaper.svg"
for f in "$TOGGLE_SRC" "$WATCHER_SRC" "$THEME_WATCHER_SRC" "$UNIT_SRC" "$ICON_SRC"; do
if [ ! -f "$f" ]; then
echo "Missing installer asset: $f" >&2
exit 1
fi
done
# ----- dependencies ------------------------------------------------------------
# Check what's already there so we don't invoke sudo when nothing needs doing.
MISSING_REPO=()
for cmd in mpv jq gum socat notify-send; do
command -v "$cmd" >/dev/null 2>&1 || MISSING_REPO+=("$cmd")
done
# notify-send maps to libnotify; translate for the pacman call below.
MISSING_PKGS=()
for cmd in "${MISSING_REPO[@]}"; do
case "$cmd" in
notify-send) MISSING_PKGS+=("libnotify") ;;
*) MISSING_PKGS+=("$cmd") ;;
esac
done
if [ "${#MISSING_PKGS[@]}" -gt 0 ]; then
echo "Installing required packages: ${MISSING_PKGS[*]}"
sudo pacman -S --needed "${MISSING_PKGS[@]}"
else
echo "✓ Repo dependencies already installed (mpv, jq, gum, socat, libnotify)"
fi
if command -v mpvpaper >/dev/null 2>&1; then
echo "✓ mpvpaper already installed"
else
echo
echo "Installing mpvpaper from AUR..."
AUR_HELPER=""
if command -v yay >/dev/null 2>&1; then AUR_HELPER="yay"
elif command -v paru >/dev/null 2>&1; then AUR_HELPER="paru"
fi
if [ -n "$AUR_HELPER" ]; then
echo "Using $AUR_HELPER to install mpvpaper..."
"$AUR_HELPER" -S --needed mpvpaper
else
cat >&2 <<'MSG'
ERROR: No AUR helper (yay/paru) found.
Install one first, then re-run this installer:
sudo pacman -S --needed base-devel git
git clone https://aur.archlinux.org/yay.git
cd yay && makepkg -si
MSG
exit 1
fi
if ! command -v mpvpaper >/dev/null 2>&1; then
echo "ERROR: mpvpaper is not installed. Cannot continue." >&2
exit 1
fi
fi
# ----- install files -----------------------------------------------------------
install -D -m 755 "$TOGGLE_SRC" "$HOME/.local/bin/motion-wallpaper-toggle"
install -D -m 755 "$WATCHER_SRC" "$HOME/.local/bin/motion-wallpaper-watcher"
install -D -m 755 "$THEME_WATCHER_SRC" "$HOME/.local/bin/motion-wallpaper-theme-watcher"
# Install custom SVG icon into the hicolor theme — Walker and other XDG-aware
# launchers will find it by name (Icon=motion-wallpaper) without needing a
# full path in the .desktop entry.
ICON_DIR="$HOME/.local/share/icons/hicolor/scalable/apps"
install -D -m 644 "$ICON_SRC" "$ICON_DIR/motion-wallpaper.svg"
# Refresh the icon cache if gtk-update-icon-cache is available. Harmless if
# not — launchers that read SVGs directly will pick it up regardless.
if command -v gtk-update-icon-cache >/dev/null 2>&1; then
gtk-update-icon-cache -f -q "$HOME/.local/share/icons/hicolor" 2>/dev/null || true
fi
mkdir -p "$HOME/.local/share/applications"
# Launch in a floating terminal via Omarchy's TUI.float app-id, which the
# default Hyprland windowrule (system.conf) tags as a floating window — same
# pattern omarchy-tui-install uses for user-added TUIs (impala, btop, etc.).
cat > "$HOME/.local/share/applications/motion-wallpaper-toggle.desktop" <<EOF
[Desktop Entry]
Version=1.0
Type=Application
Name=Motion Wallpaper
Comment=Toggle animated video wallpaper on/off (TUI)
Exec=xdg-terminal-exec --app-id=TUI.float -e $HOME/.local/bin/motion-wallpaper-toggle
Icon=motion-wallpaper
Terminal=false
Categories=Utility;Settings;DesktopSettings;
Keywords=wallpaper;video;animated;background;
EOF
# Poke the desktop database so launchers re-index immediately.
if command -v update-desktop-database >/dev/null 2>&1; then
update-desktop-database -q "$HOME/.local/share/applications" 2>/dev/null || true
fi
install -D -m 644 "$UNIT_SRC" "$HOME/.config/systemd/user/motion-wallpaper.service"
systemctl --user daemon-reload >/dev/null 2>&1 || true
# Walker's data provider (Elephant) caches the desktop index in memory. Nudge
# it so the new entry + icon show up without the user having to log out.
if systemctl --user --quiet is-active elephant.service 2>/dev/null; then
systemctl --user restart elephant.service || true
fi
# ----- done --------------------------------------------------------------------
echo
echo "=== Install complete ==="
echo
echo "✓ motion-wallpaper-toggle installed to ~/.local/bin/"
echo "✓ 'Motion Wallpaper' added to your application menu"
echo "✓ systemd unit installed (not enabled)"
echo
if [[ ":$PATH:" != *":$HOME/.local/bin:"* ]]; then
cat <<'MSG'
⚠️ ~/.local/bin is not in your PATH. Add to your shell rc:
export PATH="$HOME/.local/bin:$PATH"
MSG
fi
cat <<EOF
Usage:
motion-wallpaper-toggle # interactive (toggle / change video)
motion-wallpaper-toggle status # print current state
motion-wallpaper-toggle stop # stop and restore normal wallpaper
Tip: drop videos in ~/Videos/Wallpapers/ for quick-pick access.
Optional Hyprland keybind (avoid SUPER+W — that's Close window in Omarchy):
bind = SUPER ALT, W, exec, \$HOME/.local/bin/motion-wallpaper-toggle
Persist across logins via systemd:
systemctl --user enable --now motion-wallpaper.service
Logs: ~/.cache/motion-wallpaper.log
EOF