mabox-pipemenus/usr/bin/jgwallpaperchanger

175 lines
5.2 KiB
Plaintext
Raw Normal View History

2021-05-30 01:50:56 +02:00
#!/bin/bash
2021-08-31 22:56:45 +02:00
# jgwallpaperchanger - submenu to configure wallpapers
2021-05-30 01:50:56 +02:00
#
CONFIG_DIR="$HOME/.config/mbwallpaper"
CONFIG_FILE="$CONFIG_DIR/mbwallpaper.conf"
WALLPAPERS_LIST="$CONFIG_DIR/wplist"
# Make config directory if not exist
mkdir -p $CONFIG_DIR
# If config file not exist create one with defaults
if [ ! -f $CONFIG_FILE ]; then
cat <<EOF > ${CONFIG_FILE}
# Directory with wallpapers
wallpaper_dir=/usr/share/backgrounds/
# Rotate time in seconds
interval=10
# Wallpaper setter program: nitrogen or feh
setter=nitrogen
EOF
fi
# read config variables from file
source <(grep = $CONFIG_FILE)
case $LANG in
pl*)
2021-08-31 22:56:45 +02:00
TITLE="Zmieniacz tapet"
2022-02-18 20:34:22 +01:00
NITROGEN="Nitrogen"
2021-06-01 12:14:29 +02:00
WALLPAPERS="Tapety"
2021-05-30 01:50:56 +02:00
RANDWALL="Losowa tapeta"
2022-02-18 20:34:22 +01:00
GENERATOR="Generuj (ImageMagick)..."
2021-05-30 01:50:56 +02:00
CHOOSE="Wybierz tapetę..."
2022-02-18 20:34:22 +01:00
SLIDESHOW="Pokaz slajdów"
2021-05-30 01:50:56 +02:00
STARTS="Uruchom Pokaz slajdów <small>(<i>zatrzymany</i>)</small>"
STOPS="Zatrzymaj Pokaz slajdów <small>(<i>działający</i>)</small>"
CONF="Konfiguracja"
WALLDIR="Katalog z tapetami"
2023-01-20 15:28:49 +01:00
INTERVAL="Interwał slajdów"
2021-05-30 01:50:56 +02:00
SEC="sekund"
EDITCONF="Edytuj plik konfiguracyjny"
OPENDIR="Otwórz katalog z tapetami"
2021-06-03 14:06:57 +02:00
LEFTPANEL="Lewy panel"
2021-05-30 01:50:56 +02:00
;;
*)
2021-08-31 22:56:45 +02:00
TITLE="Wallpaper Changer"
2022-02-18 20:34:22 +01:00
NITROGEN="Nitrogen"
2021-06-01 12:14:29 +02:00
WALLPAPERS="Wallpapers"
2021-05-30 01:50:56 +02:00
RANDWALL="Random Wallpaper"
2022-02-18 20:34:22 +01:00
GENERATOR="Generate (ImageMagick)..."
2021-05-30 01:50:56 +02:00
CHOOSE="Choose Wallpaper..."
2022-02-18 20:34:22 +01:00
SLIDESHOW="Slideshow"
2021-05-30 01:50:56 +02:00
STARTS="Start Slideshow <small>(<i>stopped</i>)</small>"
STOPS="Stop Slideshow <small>(<i>running</i>)</small>"
CONF="Configuration"
2023-01-20 15:28:49 +01:00
WALLDIR="Images dir"
2021-05-30 01:50:56 +02:00
INTERVAL="Slideshow Interval"
SEC="seconds"
EDITCONF="Edit config file"
OPENDIR="Open wallpaper directory"
2021-06-03 14:06:57 +02:00
LEFTPANEL="Left panel"
2021-05-30 01:50:56 +02:00
;;
esac
. $HOME/.config/mabox/mabox.conf
2022-06-08 21:46:21 +02:00
if [[ $1 == "-r" ]];then
me="${0##*/} -s"
else
me="${0##*/} ${1:--s}"
fi
2023-01-20 15:28:49 +01:00
help='\nBased on Mabox forum member Shwaybo <a href="https://forum.maboxlinux.org/t/chwp-desktop-wallpaper-changer/496">idea</a>.\n\nchange wallpapers from a directory, never using the same picture twice until all the pictures have been shown, and rotating x number of seconds (configurable) before the next wallpaper change.\n'
2021-05-30 01:50:56 +02:00
2021-08-31 22:56:45 +02:00
#out+=("^sep($TITLE)")
2021-06-01 12:14:29 +02:00
out+=("^sep($WALLPAPERS)")
2021-05-30 01:50:56 +02:00
if ! pgrep mbwallpaper > /dev/null; then
2022-12-06 21:55:05 +01:00
#out+=("$NITROGEN,nitrogen")
2021-05-30 01:50:56 +02:00
out+=("$RANDWALL,mbwallpaper -o;$me")
2022-12-23 23:30:00 +01:00
out+=("$CHOOSE,pcmanwp")
2022-02-18 20:34:22 +01:00
out+=("$GENERATOR,^pipe(jgwallpapergenerate)")
out+=("^sep(<i>$SLIDESHOW</i>)")
2021-05-30 01:50:56 +02:00
out+=("$STARTS,run_wallpaperslideshow;$me")
else
out+=("$STOPS,killall mbwallpaper;$me")
fi
2022-02-18 20:34:22 +01:00
out+=("^sep()")
2023-01-20 15:28:49 +01:00
out+=("\"\"\"$WALLDIR: <small>[ <b>$wallpaper_dir</b> ]</small>\"\"\",xdg-open $CONFIG_FILE")
2021-05-30 01:50:56 +02:00
out+=("$INTERVAL [ <b>$interval</b> ] <small>($SEC)</small>,^checkout(interval)")
out+=("^sep()")
2022-08-17 14:19:31 +02:00
out+=("$EDITCONF ,xdg-open $CONFIG_FILE")
2021-05-30 01:50:56 +02:00
out+=("$OPENDIR,pcmanfm -n $wallpaper_dir")
2023-01-20 15:28:49 +01:00
out+=("About Slideshow,\"\"\"notify-send.sh -u critical -i mbcc 'Wallpaper Changer - rotate desktop wallpaper every n-seconds' '$help' -o 'Edit configuration file:geany ~/.config/mbwallpaper/mbwallpaper.conf'\"\"\"")
2021-05-30 01:50:56 +02:00
out2+=("^tag(interval)")
2021-08-31 22:56:45 +02:00
for i in 3 5 10 30 60 120 300 600 1800 3600; do out2+=("$(printf "<tt> %4s</tt>,%s" "$i" "mb-setvar interval=${i} $CONFIG_FILE;$me")");done
2021-05-30 01:50:56 +02:00
### RUN
2022-08-03 00:13:09 +02:00
if [[ $1 == "-s" || $1 == "-c" || $1 == "-u" ]]; then
2021-09-24 01:40:09 +02:00
. /usr/share/mb-jgtools/pipemenu-standalone.cfg
2022-06-08 21:46:21 +02:00
out+=("^sep()")
case "$1" in
-s) out+=(" ⮜ $LEFTPANEL,mb-jgtools places");;
-c) out+=(" ⮜ Colorizer,colorizer -s");;
2022-08-03 00:13:09 +02:00
-u) out+=(" ⮜ Settings menu,mb-jgtools settings");;
2022-06-08 21:46:21 +02:00
esac
2021-05-30 01:50:56 +02:00
. $HOME/.config/mabox/mabox.conf
2021-06-03 14:06:57 +02:00
if [[ $panels_heightpos == "top" ]]; then
MENU_VALIGN="top"
MENU_MARGIN_Y=${panels_topmargin:-0}
elif [[ $panels_heightpos == "bottom" ]]; then
MENU_VALIGN="bottom"
MENU_MARGIN_Y=${panels_topmargin:-0}
else
MENU_VALIGN="center"
fi
2021-05-31 15:00:35 +02:00
MENU_PADDING_TOP=${jgtools_padding:-0}
2021-05-30 01:50:56 +02:00
MENU_HALIGN="left"
jgmenu_icon_size=0
JGWIDTH=40
menu_margin_x=${submenu_spacing:-0}
[ $(pidof picom) ] && MENU_RADIUS=$jgtools_radius
[ -z $jgmenu_use_borders ] && menu_border=0
2022-05-14 23:17:53 +02:00
JGWIDTH=$((jgtools_padding + 278 + jgtools_padding))
MENU_PADDING_TOP=$((jgtools_padding + 158))
#WALLPAPER
read WALLPATH<<< $(grep file "$HOME"/.config/nitrogen/bg-saved.cfg | cut -d'=' -f2)
2023-01-20 15:28:49 +01:00
THUMBDIR="$HOME/.cache/colorizer/thumbs"
2022-05-14 23:17:53 +02:00
mkdir -p ${THUMBDIR}
2023-01-20 15:28:49 +01:00
NAME=${WALLPATH////_}
if [[ "${NAME}" =~ ^_home_.* ]]; then
n=${#HOME}
((n++))
NAME=${NAME:${n}}
fi
THUMB="${THUMBDIR}/${NAME}.png"
2022-05-14 23:17:53 +02:00
if [[ ! -f "$THUMB" ]]
then
2023-01-20 15:28:49 +01:00
convert ${WALLPATH} -resize 270x150^ -gravity center -extent 270x150 ${THUMB}
2022-05-14 23:17:53 +02:00
fi
2023-01-20 15:28:49 +01:00
#TEMP POSITION:
2022-06-08 21:46:21 +02:00
MENU_VALIGN="top"
MENU_MARGIN_Y="60"
2021-05-30 01:50:56 +02:00
mkconfigfile
cat <<EOF > ${MENU_ITEMS}
2022-05-14 23:17:53 +02:00
@icon,,$((jgtools_padding + 4)),$((jgtools_padding + 4)),270,150,4,left,top,,,${THUMB}
2021-05-30 01:50:56 +02:00
$(printf '%s\n' "${out[@]}")
$(printf '%s\n' "${out2[@]}")
EOF
jgmenu --config-file=${CONFIG_FILE} --csv-file=${MENU_ITEMS} 2>/dev/null
exit 0
fi
printf '%s\n' "${out[@]}"
if [[ $1 == "-r" ]]; then
case $LANG in
pl*) REMOVE="Usuń to menu z panelu";;
es*) REMOVE="Eliminar este menú del panel";;
*) REMOVE="Remove this menu from panel";;
esac
printf '%s\n' "^sep()"
printf '%s\n' "<i>$REMOVE</i>,mb-setvar places_jgwallpaperchanger=false;mb-jgtools places"
fi
printf '%s\n' "${out2[@]}"