Files
mabox-tools/local/bin/nitrogen
2026-04-27 09:30:34 +02:00

147 lines
5.3 KiB
Bash
Executable File

#!/bin/bash
#
# Wrapper for nitrogen, which uses feh but save config to nitrogen save file
# needed for nitrogen by feh replacement
source ~/.config/colorizer/colorizer.conf
NITROGEN_FILE="$HOME/.config/nitrogen/bg-saved.cfg"
if [[ "$XDG_SESSION_TYPE" == "wayland" ]]; then
mb-wall "${2}"
exit 0
fi
set -euo pipefail
if [[ "$1" == "default" ]];then
feh --bg-fill /usr/share/backgrounds/marek-piwnicki-FgagFhxW4Sc-unsplash.jpg
sd "file=.*$" "file=/usr/share/backgrounds/marek-piwnicki-FgagFhxW4Sc-unsplash.jpg" "$NITROGEN_FILE"
else
# jeśli restore to tylo przywróć i przerwij
if [[ "${1:-}" == "--restore" ]]; then
wp="$(awk -F '=' '/file/{print $2}' "$HOME/.config/nitrogen/bg-saved.cfg"|tail -1)"
feh --bg-fill ${wp}
exit $?
fi
ARGS="$*"
#notify-send.sh "All ARGS" "\n\n$ARGS"
# TU translacja opcji z nitrogenowych na opcje feh
# NITROGEN | FEH |
# --set-centered | --bg-center |
#
# REPLACE ARGS
ARGS="${ARGS/ --save/}"
ARGS="${ARGS/--set-centered/--bg-center}"
ARGS="${ARGS/--set-scaled/--bg-scale}"
ARGS="${ARGS/--set-tiled/--bg-tile}"
ARGS="${ARGS/--set-zoom-fill/--bg-fill}"
wallp="${ARGS##* }"
if [[ -f "${wallp}" ]];then
feh ${ARGS}
sd "file=.*$" "file=${wallp}" "$NITROGEN_FILE"
fi
fi
readonly bg_path="$(awk -F '=' '/file/{print $2}' "$HOME/.config/nitrogen/bg-saved.cfg"|tail -1)"
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"
# for Mabox Colorizer
WALLPALDIR="$HOME/.cache/colorizer/palettes"
mkdir -p "$WALLPALDIR"
read WALLPATH<<< $(grep file "$HOME/.config/nitrogen/bg-saved.cfg" | tail -1| cut -d'=' -f2) # full path to wallpaper file
# GENERATE ICON 52x32
magick ${WALLPATH} -resize 104x64^ -gravity center -extent 96x56 -bordercolor '#FFFFFF' -border 3 \
-bordercolor '#222222' -border 1 ~/.config/mabox/wpicon_wide.png
# GENERATE ICON SQUARE
magick ${WALLPATH} -resize 64x64^ -gravity center -extent 58x58 -bordercolor white -border 2 \
-bordercolor grey60 -border 1 ~/.config/mabox/wpicon.png
#killall -SIGUSR1 tint2
tint2-send refresh-execp mb-t2wall
# 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
ext="${WALLPATH##*.}"
#notify-send.sh "Extension" "$ext"
if [ ! -f "$WALLPALDIR/${NAME}.clr" ]; then
if [ "$ext" == "avif" ];then
magick ${WALLPATH} -resize 25% /tmp/out.jpg
magick /tmp/out.jpg -colors 12 -unique-colors txt:- |grep -v '^#'| awk '{print substr($3,1,7)}' |pastel sort-by brightness |pastel format hex > "$WALLPALDIR/$NAME.clr"
else
magick ${WALLPATH} -resize 25% -colors 12 -unique-colors txt:- |grep -v '^#'| awk '{print substr($3,1,7)}' |pastel sort-by brightness |pastel format hex > "$WALLPALDIR/$NAME.clr"
fi
fi
cat "$WALLPALDIR/${NAME}.clr" > "$HOME/.config/mabox/wpcolors.clr"
readarray -t w < "$HOME/.config/mabox/wpcolors.clr"
cat <<EOF > "$HOME/.config/mabox/wpcolors.svg"
<svg xmlns="http://www.w3.org/2000/svg" width="272" height="270">
<defs>
<filter id="f1">
<feDropShadow dx="2" dy="2" stdDeviation="1" flood-opacity="0.6"/>
</filter>
</defs>
<rect x="0" y="0" width="270" height="150" fill="#EEE" filter="url(#f1)" />
<rect x="1" y="156" width="61" height="33" stroke="#DDD" stroke-width="2" fill="${w[0]}" filter="url(#f1)" />
<rect x="70" y="156" width="61" height="33" stroke="#DDD" stroke-width="2" fill="${w[1]}" filter="url(#f1)" />
<rect x="139" y="156" width="61" height="33" stroke="#DDD" stroke-width="2" fill="${w[2]}" filter="url(#f1)" />
<rect x="208" y="156" width="61" height="33" stroke="#DDD" stroke-width="2" fill="${w[3]}" filter="url(#f1)" />
<rect x="1" y="196" width="61" height="33" stroke="#DDD" stroke-width="2" fill="${w[4]}" filter="url(#f1)" />
<rect x="70" y="196" width="61" height="33" stroke="#DDD" stroke-width="2" fill="${w[5]}" filter="url(#f1)" />
<rect x="139" y="196" width="61" height="33" stroke="#DDD" stroke-width="2" fill="${w[6]}" filter="url(#f1)" />
<rect x="208" y="196" width="61" height="33" stroke="#DDD" stroke-width="2" fill="${w[-5]}" filter="url(#f1)" />
<rect x="1" y="235" width="61" height="33" stroke="#DDD" stroke-width="2" fill="${w[-4]}" filter="url(#f1)" />
<rect x="70" y="235" width="61" height="33" stroke="#DDD" stroke-width="2" fill="${w[-3]}" filter="url(#f1)" />
<rect x="139" y="235" width="61" height="33" stroke="#DDD" stroke-width="2" fill="${w[-2]}" filter="url(#f1)" />
<rect x="208" y="235" width="61" height="33" stroke="#DDD" stroke-width="2" fill="${w[-1]}" filter="url(#f1)" />
</svg>
EOF
# GENERATE THUMBNAIL
THUMBDIR="$HOME/.cache/colorizer/thumbs"
mkdir -p ${THUMBDIR}
THUMB="${THUMBDIR}/${NAME}.png"
if [[ ! -f "$THUMB" ]]; then
magick ${WALLPATH} -resize 270x150^ -gravity center -extent 266x146 -bordercolor '#DDDDDD' -border 2 ${THUMB}
cp ${THUMB} "$HOME/.config/mabox/wpthumb.png"
else
cp ${THUMB} "$HOME/.config/mabox/wpthumb.png"
fi
if [[ "$1" != "default" ]];then
# AUTOTHEMING - generate themes after wallpaper is changed
if [[ "$wall2themes" == "yes" ]];then
w2theme colorize
fi
fi