tmp fix random bgs
This commit is contained in:
parent
deef81028d
commit
7fd2bc4192
3 changed files with 90 additions and 15 deletions
|
|
@ -4,6 +4,7 @@ Before=gnome-session-pre.target
|
||||||
ConditionPathIsDirectory=%h/.config/gnome-settings
|
ConditionPathIsDirectory=%h/.config/gnome-settings
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
|
Environment=FRESH_SESSION=1
|
||||||
Type=oneshot
|
Type=oneshot
|
||||||
ExecStart=%h/.local/bin/restore-gnome
|
ExecStart=%h/.local/bin/restore-gnome
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,13 +8,25 @@
|
||||||
# - Pairs => Both "<name>-d.jpg" and "<name>-l.jpg" exist
|
# - Pairs => Both "<name>-d.jpg" and "<name>-l.jpg" exist
|
||||||
# - Singles => Any other "*.jpg" not following the -d/-l scheme,
|
# - Singles => Any other "*.jpg" not following the -d/-l scheme,
|
||||||
# used as dark and light at the same time
|
# used as dark and light at the same time
|
||||||
|
#
|
||||||
|
# The live `gsettings` URIs point at uniquely named copies
|
||||||
|
# because `gnome-shell` caches background images by file URI;
|
||||||
|
# `restore-gnome` cleans up that temporary state during the next login
|
||||||
|
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
|
|
||||||
|
XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
|
||||||
|
XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}"
|
||||||
|
XDG_STATE_HOME="${XDG_STATE_HOME:-$HOME/.local/state}"
|
||||||
|
|
||||||
|
|
||||||
SOURCE_DIR="$HOME/Cloud/Null-Tech/Backgrounds"
|
SOURCE_DIR="$HOME/Cloud/Null-Tech/Backgrounds"
|
||||||
TARGET_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/backgrounds"
|
TARGET_DIR="$XDG_DATA_HOME/backgrounds"
|
||||||
STATE_FILE="${XDG_STATE_HOME:-$HOME/.local/state}/current-background.txt"
|
|
||||||
|
|
||||||
|
LOCAL_INI="$XDG_CONFIG_HOME/gnome-settings/local/temporary_background.ini"
|
||||||
|
STATE_FILE="$XDG_STATE_HOME/current-background.txt"
|
||||||
|
|
||||||
|
|
||||||
[ -d "$SOURCE_DIR" ] || { echo "No such folder: $SOURCE_DIR" >&2; exit 1; }
|
[ -d "$SOURCE_DIR" ] || { echo "No such folder: $SOURCE_DIR" >&2; exit 1; }
|
||||||
|
|
@ -43,33 +55,87 @@ candidates=$(
|
||||||
done
|
done
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
if [ -z "$candidates" ]; then
|
if [ -z "$candidates" ]; then
|
||||||
echo "No usable *.jpg files in: $SOURCE_DIR" >&2
|
echo "No usable *.jpg files in: $SOURCE_DIR" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
echo "Found $(printf '%s\n' "$candidates" | wc -l) candidate(s)"
|
echo "Found $(printf '%s\n' "$candidates" | wc -l) candidate(s)"
|
||||||
|
|
||||||
|
|
||||||
# The glob expands alphabetically => "$candidates" is already sorted
|
# The glob expands alphabetically => "$candidates" is already sorted
|
||||||
# => Pick the first candidate sorting strictly after the last-used one,
|
# => Pick the first candidate sorting strictly after the last-used one,
|
||||||
# falling back to the first (e.g., for start, wrap-around, or missing state file)
|
# falling back to the first one if necessary
|
||||||
last=$(cat "$STATE_FILE" 2>/dev/null || true)
|
# (e.g., for start, wrap-around, or missing state file)
|
||||||
chosen=$(printf '%s\n' "$candidates" | awk -F '\t' -v last="$last" '$1 > last { print; exit }')
|
last_background=$(cat "$STATE_FILE" 2>/dev/null || true)
|
||||||
[ -n "$chosen" ] || chosen=$(printf '%s\n' "$candidates" | head -n 1)
|
next_background=$(printf '%s\n' "$candidates" | awk -F '\t' -v last_background="$last_background" '$1 > last_background { print; exit }')
|
||||||
|
[ -n "$next_background" ] || next_background=$(printf '%s\n' "$candidates" | head -n 1)
|
||||||
|
|
||||||
|
|
||||||
dark=$(printf '%s' "$chosen" | cut -f 1)
|
dark_source=$(printf '%s' "$next_background" | cut -f 1)
|
||||||
light=$(printf '%s' "$chosen" | cut -f 2)
|
light_source=$(printf '%s' "$next_background" | cut -f 2)
|
||||||
echo "Chosen: $(basename "$dark")"
|
echo "Chosen background: $(basename "$dark_source")"
|
||||||
|
|
||||||
|
|
||||||
mkdir -p "$TARGET_DIR" "$(dirname "$STATE_FILE")"
|
dark_target="$TARGET_DIR/dark.jpg"
|
||||||
cp -- "$dark" "$TARGET_DIR/dark.jpg"
|
light_target="$TARGET_DIR/light.jpg"
|
||||||
cp -- "$light" "$TARGET_DIR/light.jpg"
|
|
||||||
printf '%s\n' "$dark" > "$STATE_FILE"
|
# Create a unique name per run
|
||||||
|
# so that the URIs below never repeat
|
||||||
|
timestamp=$(date +%s)
|
||||||
|
|
||||||
|
dark_live_target="$TARGET_DIR/dark-tmp-$timestamp.jpg"
|
||||||
|
light_live_target="$TARGET_DIR/light-tmp-$timestamp.jpg"
|
||||||
|
|
||||||
|
|
||||||
|
mkdir -p \
|
||||||
|
"$TARGET_DIR" \
|
||||||
|
"$(dirname "$LOCAL_INI")" \
|
||||||
|
"$(dirname "$STATE_FILE")"
|
||||||
|
|
||||||
|
|
||||||
|
# Fixed-name copies, referenced as login-time defaults in the *.ini files
|
||||||
|
cp -- "$dark_source" "$dark_target"
|
||||||
|
cp -- "$light_source" "$light_target"
|
||||||
|
|
||||||
|
|
||||||
|
# Uniquely named copies for the live `gsettings` URIs
|
||||||
|
# to ensure `gnome-shell` uses the correct files right away
|
||||||
|
cp -- "$dark_source" "$dark_live_target"
|
||||||
|
cp -- "$light_source" "$light_live_target"
|
||||||
|
|
||||||
|
|
||||||
|
printf '%s\n' "$dark_source" > "$STATE_FILE"
|
||||||
|
|
||||||
|
|
||||||
|
Background=org.gnome.desktop.background
|
||||||
|
Screensaver=org.gnome.desktop.screensaver
|
||||||
|
|
||||||
|
gsettings set $Background picture-uri-dark "file://$dark_live_target"
|
||||||
|
gsettings set $Background picture-uri "file://$light_live_target"
|
||||||
|
gsettings set $Screensaver picture-uri "file://$dark_live_target"
|
||||||
|
|
||||||
|
|
||||||
|
# Persist the unique URIs for `restore-gnome`,
|
||||||
|
# which loads local/*.ini after the base *.ini files
|
||||||
|
cat > "$LOCAL_INI" <<EOF
|
||||||
|
# Written by $(basename "$0") - do not edit
|
||||||
|
|
||||||
|
[org/gnome/desktop/background]
|
||||||
|
|
||||||
|
picture-uri-dark='file://$dark_live_target'
|
||||||
|
picture-uri='file://$light_live_target'
|
||||||
|
|
||||||
|
|
||||||
|
[org/gnome/desktop/screensaver]
|
||||||
|
|
||||||
|
picture-uri='file://$dark_live_target'
|
||||||
|
EOF
|
||||||
|
|
||||||
|
|
||||||
|
# Remove the uniquely named copies of previously chosen wallpapers
|
||||||
|
find "$TARGET_DIR" -name 'dark-tmp-*.jpg' ! -name "dark-tmp-$timestamp.jpg" -delete
|
||||||
|
find "$TARGET_DIR" -name 'light-tmp-*.jpg' ! -name "light-tmp-$timestamp.jpg" -delete
|
||||||
|
|
||||||
|
|
||||||
echo "Installed as: $TARGET_DIR/{dark,light}.jpg"
|
echo "Installed as: $TARGET_DIR/{dark,light}.jpg"
|
||||||
|
|
|
||||||
|
|
@ -88,6 +88,14 @@ dconf dump / > "$BACKUP_DIR/$(date +%Y%m%d-%H%M%S).ini"
|
||||||
ls -1t "$BACKUP_DIR"/*.ini | tail -n +11 | xargs -r rm --
|
ls -1t "$BACKUP_DIR"/*.ini | tail -n +11 | xargs -r rm --
|
||||||
|
|
||||||
|
|
||||||
|
# Remove temporary background image files
|
||||||
|
# created by ~/.local/bin/randomize-background
|
||||||
|
if [ "${FRESH_SESSION:-}" = "1" ]; then
|
||||||
|
echo "Removing session-scoped background image files"
|
||||||
|
rm -f "$XDG_CONFIG_HOME/gnome-settings/local/temporary_background.ini"
|
||||||
|
find "$XDG_DATA_HOME/backgrounds" -name '*-tmp-*.jpg' -delete 2>/dev/null || true
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
echo "Resetting managed subtrees in dconf"
|
echo "Resetting managed subtrees in dconf"
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue