mabox-pipemenus/usr/bin/jgwallpaperchanger

295 lines
9.6 KiB
Bash
Executable File

#!/bin/bash
# jgwallpaperchanger - dynamic menu (or submenu) to configure/set wallpapers
#
if [[ $1 == "-r" ]];then
me="${0##*/} -s"
else
me="${0##*/} ${1:--s}"
fi
#SLIDESHOW CONF
CONFIG_DIR="$HOME/.config/mbwallpaper"
CONF_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 $CONF_FILE ]; then
cat <<EOF > ${CONF_FILE}
# Directory with wallpapers
wallpaper_dir=/usr/share/backgrounds/
# Rotate time in seconds
interval=10
# Wallpaper setter program: nitrogen or feh
setter=nitrogen
# Tint2 panel executor button left click action
t2_button_lclick_action=choose
EOF
fi
# read config variables from file
source <(grep = $CONF_FILE)
COLORIZER_CONF="$HOME/.config/colorizer/colorizer.conf"
source ${COLORIZER_CONF}
#WP_DIRS
CNF_FILE="$HOME/.config/mabox/wallp_dirs.conf"
if [ ! -f $CNF_FILE ]; then
cat <<EOF > ${CNF_FILE}
# User wallpapers directories - one per line
# Used by "Choose wallpaper" PCmanFM wrapper
# Set wallpapers using context (right click) menu in file manager
~/wallpapers/
EOF
fi
lclick(){
case $t2_button_lclick_action in
random) mbwallpaper -o;;
choose) pcmanwp;;
window) ycolorizer;;
menu) colorizer -s;;
esac
}
main(){
case $LANG in
pl*)
TITLE="Zmieniacz tapet"
NITROGEN="Nitrogen"
WALLPAPERS="Tapety"
RANDWALL="Losowa tapeta"
EDIT_WPDIRS="Edytuj katalogi z tapetami"
GENERATOR="Generuj (ImageMagick)..."
CHOOSE_WP="Wybierz tapetę..."
SLIDESHOW="Pokaz slajdów"
STARTS="Uruchom Pokaz slajdów <small>(<i>zatrzymany</i>)</small>"
STOPS="Zatrzymaj Pokaz slajdów <small>(<i>działający - interwał: $interval sek.</i>)</small>"
CONF="Konfiguracja"
WALLDIR="Katalog z tapetami"
INTERVAL="Interwał slajdów"
SEC="sekund"
EDITCONF="Edytuj plik konfiguracyjny"
OPENDIR="Otwórz katalog z tapetami"
LEFTPANEL="Lewy panel"
OBTHEME="Motyw Openbox"
MENUPANELS="Menu i Panele"
COLORIZER_HELP="Okno główne i Pomoc"
COLORIZER_ROOT="<b>Colorizer</b> menu główne"
COLORIZER_FONTS="Konfiguruj <b>Czcionki</b>"
COLORIZER_OB="Moduł <b>Openbox</b>"
COLORIZER_MENU="Moduł <b>Menu</b>"
COLORIZER_CONKY="Moduł <b>Conky</b>"
COLORIZER_PYRADIO="Moduł <b>PyRadio</b>"
COLORIZER_CAVA="Moduł <b>Cava</b>"
B_LC_ACTION="Akcja przycisku (lewy klik)"
RAND="losuj"
CHOOSE="wybierz"
COL_WINDOW="okno"
COL_MENU="menu"
RANDOM_DESC="Ustaw <b>losową</b> tapetę"
CHOOSE_DESC="<b>Wybierz</b> tapetę (z menu kontekstowego)"
COL_WINDOW_DESC="Colorizer - <b>okno</b>"
COL_MENU_DESC="Colorizer - dynamiczne <b>menu</b>"
;;
*)
TITLE="Wallpaper Changer"
NITROGEN="Nitrogen"
WALLPAPERS="Wallpapers"
RANDWALL="Random Wallpaper"
EDIT_WPDIRS="Edit Wallpaper dirs"
GENERATOR="Generate (ImageMagick)..."
CHOOSE_WP="Choose Wallpaper <small>(from context menu)</small>"
SLIDESHOW="Slideshow"
STARTS="Start Slideshow <small>(<i>stopped</i>)</small>"
STOPS="Stop Slideshow <small>(<i>running - interval: $interval sec.</i>)</small>"
CONF="Configuration"
WALLDIR="Images dir"
INTERVAL="Slideshow Interval"
SEC="seconds"
EDITCONF="Edit config file"
OPENDIR="Open wallpaper directory"
LEFTPANEL="Left panel"
OBTHEME="Openbox Theme"
MENUPANELS="Menus/Panels"
COLORIZER_HELP="Main Window and Help"
COLORIZER_ROOT="<b>Colorizer</b> rootmenu"
COLORIZER_FONTS="Configure <b>Fonts</b>"
COLORIZER_OB="<b>Openbox</b> module"
COLORIZER_MENU="<b>Menus/SidePanels</b> module"
COLORIZER_CONKY="<b>Conky</b> module"
COLORIZER_PYRADIO="<b>PyRadio</b> module"
COLORIZER_CAVA="<b>Cava</b> module"
B_LC_ACTION="Button <i>left-click</i> action"
RAND="random"
CHOOSE="choose"
COL_WINDOW="window"
COL_MENU="menu"
RANDOM_DESC="Set <b>random</b> wallpaper"
CHOOSE_DESC="<b>Choose</b> wallpaper (<i>from context menu</i>)"
COL_WINDOW_DESC="Colorizer - <b>window</b>"
COL_MENU_DESC="Colorizer - dynamic <b>menu</b>"
;;
esac
. $HOME/.config/mabox/mabox.conf
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"
#out+=("^sep($TITLE)")
out+=("^sep($WALLPAPERS)")
if ! pgrep mbwallpaper > /dev/null; then
#out+=("$NITROGEN,nitrogen")
out+=("<big></big> $RANDWALL,mbwallpaper -o;$me")
out+=("<big>󰉔</big> $CHOOSE_WP,pcmanwp")
#out+=("$GENERATOR,^pipe(jgwallpapergenerate)")
out+=("<big>󰧸</big> $SLIDESHOW,^checkout(sshow)")
out+=("^sep()")
out+=("<big></big> $EDIT_WPDIRS,xdg-open $CNF_FILE")
else
out+=("$STOPS,killall mbwallpaper;pkill -f 'yad --not';$me")
fi
out1+=("^tag(sshow)")
out1+=("^sep($SLIDESHOW)")
out1+=("$STARTS,run_wallpaperslideshow;$me")
out1+=("\"\"\"$WALLDIR: <small>[ <b>$wallpaper_dir</b> ]</small>\"\"\",xdg-open $CONF_FILE")
out1+=("$INTERVAL [ <b>$interval</b> ] <small>($SEC)</small>,^checkout(interval)")
out1+=("^sep()")
out1+=("<big></big> $EDITCONF ,xdg-open $CONF_FILE")
out1+=("<big></big> $OPENDIR,pcmanfm -n $wallpaper_dir")
out1+=("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'\"\"\"")
out2+=("^tag(interval)")
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} $CONF_FILE;$me")");done
### RUN
if [[ $1 == "-s" || $1 == "-c" || $1 == "-u" || $1 == "ipc" || $1 == "-d" ]]; then
. /usr/share/mb-jgtools/pipemenu-standalone.cfg
case "$1" in
-s) out+=(" ${arrow_string_left} $LEFTPANEL,mb-jgtools places");;
-c) out+=(" ${arrow_string_left} Colorizer,colorizer -s");;
-u) out+=(" ${arrow_string_left} Settings menu,mb-jgtools settings");;
-d) POSITION_MODE=pointer;;
ipc) POSITION_MODE=${1:-fixed}
out+=("^sep(Colorizer)")
out+=("$COLORIZER_HELP,ycolorizer")
out+=("$COLORIZER_ROOT,colorizer -s")
out+=("^sep()")
out+=("$COLORIZER_FONTS,colorizer-fonts -s")
out+=("^sep()")
out+=("$COLORIZER_OB,colorizer-ob -s")
out+=("$COLORIZER_MENU,colorizer-menus -s")
out+=("$COLORIZER_CONKY,colorizer-conky -s")
out+=("^sep()")
out+=("$COLORIZER_PYRADIO,colorizer-pyradio -s")
out+=("$COLORIZER_CAVA,colorizer-cava -s")
out+=("^sep()")
case $t2_button_lclick_action in
random) out+=("$B_LC_ACTION: <b>[ $RAND ]</b>,^checkout(laction)");;
choose) out+=("$B_LC_ACTION: <b>[ $CHOOSE ]</b>,^checkout(laction)");;
window) out+=("$B_LC_ACTION: <b>[ $COL_WINDOW ]</b>,^checkout(laction)");;
menu) out+=("$B_LC_ACTION: <b>[ $COL_MENU ]</b>,^checkout(laction)");;
*) out+=("$B_LC_ACTION: <b>[ $CHOOSE ]</b>,^checkout(laction)");;
esac
out2+=("^tag(laction)")
out2+=("^sep(Panel button left-click action)")
[[ "$t2_button_lclick_action" == "choose" ]] && out2+=("<big>綠</big> $CHOOSE_DESC") || out2+=("<big>祿</big> $CHOOSE_DESC,mb-setvar t2_button_lclick_action=choose $CONF_FILE")
[[ "$t2_button_lclick_action" == "random" ]] && out2+=("<big>綠</big> $RANDOM_DESC") || out2+=("<big>祿</big> $RANDOM_DESC,mb-setvar t2_button_lclick_action=random $CONF_FILE")
out2+=("^sep()")
[[ "$t2_button_lclick_action" == "window" ]] && out2+=("<big>綠</big> $COL_WINDOW_DESC") || out2+=("<big>祿</big> $COL_WINDOW_DESC,mb-setvar t2_button_lclick_action=window $CONF_FILE")
[[ "$t2_button_lclick_action" == "menu" ]] && out2+=("<big>綠</big> $COL_MENU_DESC") || out2+=("<big>祿</big> $COL_MENU_DESC,mb-setvar t2_button_lclick_action=menu $CONF_FILE")
;;
esac
. $HOME/.config/mabox/mabox.conf
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
MENU_PADDING_TOP=${jgtools_padding:-0}
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
JGWIDTH=$((jgtools_padding + 270 + jgtools_padding))
MENU_PADDING_TOP=$((jgtools_padding + 150))
#WALLPAPER
read WALLPATH<<< $(grep file "$HOME"/.config/nitrogen/bg-saved.cfg | tail -1 | cut -d'=' -f2)
THUMBDIR="$HOME/.cache/colorizer/thumbs"
mkdir -p ${THUMBDIR}
NAME=${WALLPATH////_}
if [[ "${NAME}" =~ ^_home_.* ]]; then
n=${#HOME}
((n++))
NAME=${NAME:${n}}
fi
THUMB="${THUMBDIR}/${NAME}.png"
if [[ ! -f "$THUMB" ]]
then
convert ${WALLPATH} -resize 270x150^ -gravity center -extent 270x150 ${THUMB}
fi
#TEMP POSITION:
MENU_VALIGN="top"
MENU_MARGIN_Y="60"
mkconfigfile
cat <<EOF > ${MENU_ITEMS}
@icon,,$((jgtools_padding )),$((jgtools_padding)),270,150,4,left,top,,,${THUMB}
$(printf '%s\n' "${out[@]}")
$(printf '%s\n' "${out1[@]}")
$(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' "${out1[@]}"
printf '%s\n' "${out2[@]}"
}
case "$1" in
lclick) lclick;;
*) main "$@";;
esac