mabox-tools/local/bin/nitrogen

76 lines
2.2 KiB
Plaintext
Raw Permalink Normal View History

2023-01-18 23:53:23 +01:00
#!/bin/bash
2023-01-17 13:54:30 +01:00
#
# Wrapper for nitrogen, so LightDM wallpaper is synced.
#
# Copyright (C) 2021 Rafael Cavalcanti - rafaelc.org
# Licensed under GPLv3
set -euo pipefail
/usr/bin/nitrogen "$@"
if [[ "${1:-}" == "--restore" ]]; then
exit $?
fi
readonly bg_path="$(awk -F '=' '/file/{print $2}' "$HOME/.config/nitrogen/bg-saved.cfg")"
dbus-send \
--print-reply \
--system \
--dest=org.freedesktop.Accounts \
/org/freedesktop/Accounts/User$(id -u) \
org.freedesktop.DBus.Properties.Set \
string:org.freedesktop.DisplayManager.AccountsService \
string:BackgroundFile \
variant:string:"$bg_path"
2023-01-18 23:53:23 +01:00
# for Mabox Colorizer
WALLPALDIR="$HOME/.cache/colorizer/palettes"
2023-01-17 13:54:30 +01:00
mkdir -p "$WALLPALDIR"
2023-01-18 23:53:23 +01:00
2024-08-13 22:50:59 +02:00
read WALLPATH<<< $(grep file "$HOME/.config/nitrogen/bg-saved.cfg" | tail -1| cut -d'=' -f2) # full path to wallpaper file
2023-01-18 23:53:23 +01:00
# Wallpaper history :)
echo ${WALLPATH} >> $HOME/.cache/colorizer/.wallpaper_history
## get filename for palette and thumbnails
NAME=${WALLPATH////_}
if [[ "${NAME}" =~ ^_home_.* ]]; then
n=${#HOME}
((n++))
NAME=${NAME:${n}}
fi
2024-01-28 11:39:35 +01:00
ext="${WALLPATH##*.}"
#notify-send.sh "Extension" "$ext"
2023-01-18 23:53:23 +01:00
if [ ! -f "$WALLPALDIR/${NAME}.clr" ]; then
2024-01-28 11:39:35 +01:00
if [ "$ext" == "avif" ];then
convert ${WALLPATH} -resize 25% -colors 16 -unique-colors txt:- |grep -v '^#'| awk '{print substr($3,1,3) substr($3,6,2) substr($3,10,2)}' |pastel sort-by brightness |pastel format hex > "$WALLPALDIR/$NAME.clr"
else
convert ${WALLPATH} -resize 25% -colors 16 -unique-colors txt:- |grep -v '^#'| awk '{print substr($3,1,7)}' |pastel sort-by brightness |pastel format hex > "$WALLPALDIR/$NAME.clr"
fi
2023-01-17 13:54:30 +01:00
fi
# GENERATE THUMBNAIL
2023-01-18 23:53:23 +01:00
THUMBDIR="$HOME/.cache/colorizer/thumbs"
2023-01-17 13:54:30 +01:00
mkdir -p ${THUMBDIR}
2023-01-18 23:53:23 +01:00
THUMB="${THUMBDIR}/${NAME}.png"
2023-01-17 13:54:30 +01:00
if [[ ! -f "$THUMB" ]]; then
convert ${WALLPATH} -resize 270x150^ -gravity center -extent 270x150 ${THUMB}
fi
2023-08-30 17:48:49 +02:00
# GENERATE ICON
convert ${WALLPATH} -resize 52x52^ -gravity center -extent 52x52 -bordercolor white -border 5 \
-bordercolor grey60 -border 1 ~/.config/mabox/wpicon.png
killall -SIGUSR1 tint2
2023-01-17 13:54:30 +01:00
# auto generate themes
2024-01-28 11:39:35 +01:00
#if command -v w2theme &> /dev/null
#then
#source ~/.config/colorizer/colorizer.conf
# if [[ "$wall2themes" == "yes" ]];then
# w2theme colorize
# fi
#fi