From 97a82c631cb3463bb3527aa03de7072367475c28 Mon Sep 17 00:00:00 2001 From: acrogenesis Date: Sun, 30 Aug 2026 21:41:38 -0600 Subject: [PATCH 01/45] Add responsive theme backgrounds --- bin/omarchy-bar-text-color | 96 +++++- bin/omarchy-menu-images | 3 +- bin/omarchy-theme-bg-current | 2 +- bin/omarchy-theme-bg-next | 3 +- bin/omarchy-theme-bg-resolve | 338 ++++++++++++++++++++ bin/omarchy-theme-set | 3 +- bin/omarchy-theme-set-templates | 17 + bin/omarchy-theme-switcher | 3 +- default/agents/skills/omarchy/theming.md | 22 ++ docs/theming.md | 41 +++ manual/39-backgrounds.md | 26 ++ manual/43-making-your-own-theme.md | 20 ++ shell/Ui/BackgroundMedia.qml | 22 +- shell/Ui/BackgroundResolver.qml | 133 ++++++++ shell/Ui/WallpaperImage.qml | 99 ++++++ shell/Ui/qmldir | 2 + shell/plugins/background/Background.qml | 184 ++++++++++- shell/plugins/image-picker/list.sh | 3 +- shell/plugins/lock/LockView.qml | 21 +- shell/plugins/lock/Service.qml | 2 + test/cli | 34 ++ test/shell.d/background-enumeration-test.sh | 209 ++++++++++++ test/shell.d/background-resolve-test.sh | 278 ++++++++++++++++ test/shell.d/background-test.sh | 191 +++++++++++ test/shell.d/menu-images-test.sh | 24 +- test/shell.d/theme-staging-test.sh | 4 + 26 files changed, 1729 insertions(+), 51 deletions(-) create mode 100755 bin/omarchy-theme-bg-resolve create mode 100644 shell/Ui/BackgroundResolver.qml create mode 100644 shell/Ui/WallpaperImage.qml create mode 100644 test/shell.d/background-enumeration-test.sh create mode 100644 test/shell.d/background-resolve-test.sh diff --git a/bin/omarchy-bar-text-color b/bin/omarchy-bar-text-color index 35cd0eadd2a9..7343d297f669 100755 --- a/bin/omarchy-bar-text-color +++ b/bin/omarchy-bar-text-color @@ -74,14 +74,12 @@ valid_hex "$background_color" || fallback [[ $bar_size =~ ^[0-9]+$ ]] || fallback omarchy-cmd-present magick || fallback -if [[ -z $background_path ]]; then - background_path=$(readlink -f "$HOME/.local/state/omarchy/current/background" 2>/dev/null || true) -fi -[[ -f $background_path ]] || fallback - if [[ -z $screen_size ]]; then if omarchy-cmd-present hyprctl && omarchy-cmd-present jq; then - screen_size=$(hyprctl monitors -j 2>/dev/null | jq -r '.[0] | "\(.width)x\(.height)"' 2>/dev/null || true) + # hyprctl reports the raw mode resolution; an odd transform (90/270 degree + # rotation) swaps the logical axes the shell renders with, so swap here too. + screen_size=$(hyprctl monitors -j 2>/dev/null | + jq -r '.[0] | if ((.transform // 0) % 2) == 1 then "\(.height)x\(.width)" else "\(.width)x\(.height)" end' 2>/dev/null || true) fi fi [[ $screen_size =~ ^([0-9]+)x([0-9]+)$ ]] || fallback @@ -90,6 +88,46 @@ screen_width=${BASH_REMATCH[1]} screen_height=${BASH_REMATCH[2]} ((screen_width > 0 && screen_height > 0 && bar_size > 0)) || fallback +# The resolver picks the per-screen variant and render metadata so the sampled +# pixels match what the shell actually paints on this screen. +sample_path="" +fill="crop" +fill_color="$background_color" +resolver_args=(--screen "${screen_width}x${screen_height}" --fields) +[[ -n $background_path ]] && resolver_args+=(--canonical "$background_path") + +if resolved=$(omarchy-theme-bg-resolve "${resolver_args[@]}" 2>/dev/null); then + while IFS=$'\t' read -r key value; do + case "$key" in + path) + sample_path="$value" + ;; + fill) + [[ $value =~ ^(crop|fit|center|tile)$ ]] && fill="$value" + ;; + fill_color) + valid_hex "$value" && fill_color="$value" + ;; + esac + done <<<"$resolved" +fi + +# Resolver missing or failed: sample the canonical background as before. +if [[ ! -f $sample_path ]]; then + if [[ -z $background_path ]]; then + background_path=$(readlink -f "$HOME/.local/state/omarchy/current/background" 2>/dev/null || true) + fi + [[ -f $background_path ]] || fallback + sample_path="$background_path" + fill="crop" +fi + +# Video wallpapers always use an aspect crop in BackgroundMedia. Sample their +# first frame with the same geometry, regardless of still-image metadata. +if [[ ${sample_path,,} =~ \.(mp4|m4v|mov|webm|mkv|avi)$ ]]; then + fill="crop" +fi + case "$position" in top) crop="${screen_width}x${bar_size}+0+0" @@ -109,14 +147,44 @@ right) ;; esac -# Sample the first frame only. Without the selector a video background makes -# ImageMagick decode the whole file and emit one value per frame, and the match -# below then fails into the fallback colour. -pixel=$(magick "$background_path[0]" -auto-orient \ - -resize "${screen_width}x${screen_height}^" \ - -gravity center -extent "${screen_width}x${screen_height}" \ - -gravity NorthWest -crop "$crop" +repage \ - -resize '1x1!' -format '%[fx:int(255*r)],%[fx:int(255*g)],%[fx:int(255*b)]' info:- 2>/dev/null || true) +screen="${screen_width}x${screen_height}" +sample_format='%[fx:int(255*r)],%[fx:int(255*g)],%[fx:int(255*b)]' + +case "$fill" in +fit) + pixel=$(magick -size "$screen" "xc:$fill_color" \ + \( "$sample_path[0]" -auto-orient -resize "$screen" \) \ + -gravity center -composite \ + -gravity NorthWest -crop "$crop" +repage \ + -resize '1x1!' -format "$sample_format" info:- 2>/dev/null || true) + ;; +center) + pixel=$(magick -size "$screen" "xc:$fill_color" \ + \( "$sample_path[0]" -auto-orient \) \ + -gravity center -composite \ + -gravity NorthWest -crop "$crop" +repage \ + -resize '1x1!' -format "$sample_format" info:- 2>/dev/null || true) + ;; +tile) + # The shell paints a fill_color rectangle under tiled images too, so a tile + # with transparency must be composited over it before sampling. + pixel=$(magick -size "$screen" "xc:$fill_color" \ + \( -size "$screen" "tile:$sample_path[0]" \) \ + -composite \ + -gravity NorthWest -crop "$crop" +repage \ + -resize '1x1!' -format "$sample_format" info:- 2>/dev/null || true) + ;; +*) + # crop: cover-resize and center like the shell's PreserveAspectCrop. A + # non-center focal shifts the crop window slightly; the averaged bar strip + # barely moves, so sampling stays centered. + pixel=$(magick "$sample_path[0]" -auto-orient \ + -resize "${screen}^" \ + -gravity center -extent "$screen" \ + -gravity NorthWest -crop "$crop" +repage \ + -resize '1x1!' -format "$sample_format" info:- 2>/dev/null || true) + ;; +esac [[ $pixel =~ ^([0-9]+),([0-9]+),([0-9]+)$ ]] || fallback sample=$(printf '#%02x%02x%02x' "${BASH_REMATCH[1]}" "${BASH_REMATCH[2]}" "${BASH_REMATCH[3]}") diff --git a/bin/omarchy-menu-images b/bin/omarchy-menu-images index 8305cb0fdd72..0f8d26c5fc6c 100755 --- a/bin/omarchy-menu-images +++ b/bin/omarchy-menu-images @@ -135,7 +135,8 @@ else image_signature=$(stat -Lc '%s:%Y' "$image") || continue rows_signature+="$image:$image_signature"$'\n' done < <(find -L "$dir" -maxdepth 1 -type f \ - \( -iname '*.jpg' -o -iname '*.jpeg' -o -iname '*.png' -o -iname '*.gif' -o -iname '*.bmp' -o -iname '*.webp' \ + ! -name '*@*' \ + \( -iname '*.jpg' -o -iname '*.jpeg' -o -iname '*.png' -o -iname '*.gif' -o -iname '*.bmp' -o -iname '*.webp' -o -iname '*.svg' \ -o -iname '*.mp4' -o -iname '*.m4v' -o -iname '*.mov' -o -iname '*.webm' -o -iname '*.mkv' -o -iname '*.avi' \) \ -print0 2>/dev/null | sort -z) fi diff --git a/bin/omarchy-theme-bg-current b/bin/omarchy-theme-bg-current index b50764a58ceb..c52711b5219e 100755 --- a/bin/omarchy-theme-bg-current +++ b/bin/omarchy-theme-bg-current @@ -6,7 +6,7 @@ BACKGROUND_PATH=$(readlink -f "$HOME/.local/state/omarchy/current/background" 2>/dev/null) if [[ -n $BACKGROUND_PATH ]]; then - basename -- "$BACKGROUND_PATH" | perl -pe 's/\.[^.]+$//; s/^\d+-//; s/-/ /g; s/\b(\w)/\U$1/g' + basename -- "$BACKGROUND_PATH" | perl -pe 's/\.[^.]+$//; s/@[^@]+$//; s/^\d+-//; s/-/ /g; s/\b(\w)/\U$1/g' else echo "Unknown" fi diff --git a/bin/omarchy-theme-bg-next b/bin/omarchy-theme-bg-next index f9907d7a3cdc..20ba9a56ba6d 100755 --- a/bin/omarchy-theme-bg-next +++ b/bin/omarchy-theme-bg-next @@ -10,7 +10,8 @@ CURRENT_BACKGROUND_LINK="$HOME/.local/state/omarchy/current/background" mapfile -d '' -t BACKGROUNDS < <( find -L "$USER_BACKGROUNDS_PATH" "$THEME_BACKGROUNDS_PATH" -maxdepth 1 -type f \ - \( -iname '*.jpg' -o -iname '*.jpeg' -o -iname '*.png' -o -iname '*.gif' -o -iname '*.bmp' -o -iname '*.webp' \ + ! -name '*@*' \ + \( -iname '*.jpg' -o -iname '*.jpeg' -o -iname '*.png' -o -iname '*.gif' -o -iname '*.bmp' -o -iname '*.webp' -o -iname '*.svg' \ -o -iname '*.mp4' -o -iname '*.m4v' -o -iname '*.mov' -o -iname '*.webm' -o -iname '*.mkv' -o -iname '*.avi' \) \ -print0 2>/dev/null | sort -z ) diff --git a/bin/omarchy-theme-bg-resolve b/bin/omarchy-theme-bg-resolve new file mode 100755 index 000000000000..1d9f8f12a9b7 --- /dev/null +++ b/bin/omarchy-theme-bg-resolve @@ -0,0 +1,338 @@ +#!/bin/bash + +# omarchy:summary=Resolve the background variant and render metadata for a screen +# omarchy:args=[--screen x] [--canonical ] [--fields] +# omarchy:hidden=true + +# The single implementation of background resolution, shared by the CLI and the +# shell: picks the aspect-ratio variant closest to the screen, reads render +# metadata from backgrounds.toml beside the image, and rasterizes SVG +# backgrounds to a cached PNG sized for the screen. Pure read plus cache write; +# the current-background symlink is never touched here. + +SCREEN="" +SCREEN_W=0 +SCREEN_H=0 +CANONICAL="" +OUTPUT="json" + +usage() { + echo "Usage: omarchy-theme-bg-resolve [--screen x] [--canonical ] [--fields]" +} + +while (( $# > 0 )); do + case "$1" in + --screen) + if (( $# < 2 )); then + usage >&2 + exit 1 + fi + + SCREEN="$2" + shift 2 + ;; + --canonical) + if (( $# < 2 )); then + usage >&2 + exit 1 + fi + + CANONICAL="$2" + shift 2 + ;; + --fields) + OUTPUT="fields" + shift + ;; + -h | --help) + usage + exit 0 + ;; + *) + usage >&2 + exit 1 + ;; + esac +done + +if [[ -n $SCREEN ]]; then + if [[ $SCREEN =~ ^([1-9][0-9]*)x([1-9][0-9]*)$ ]]; then + SCREEN_W=${BASH_REMATCH[1]} + SCREEN_H=${BASH_REMATCH[2]} + else + usage >&2 + exit 1 + fi +fi + +[[ -n $CANONICAL ]] || CANONICAL="$HOME/.local/state/omarchy/current/background" +CANONICAL=$(readlink -f -- "$CANONICAL" 2>/dev/null) || CANONICAL="" +if [[ -z $CANONICAL || ! -f $CANONICAL ]]; then + exit 1 +fi + +BG_DIR=$(dirname "$CANONICAL") +CANONICAL_NAME=$(basename "$CANONICAL") +STEM="${CANONICAL_NAME%.*}" + +probe_dimensions() { + magick identify -ping -format '%w %h' "${1}[0]" 2>/dev/null +} + +# Candidates are the canonical file plus its aspect-ratio variants: sibling +# regular files named @