2021-05-30 01:50:56 +02:00
#!/bin/bash
2023-05-18 16:05:29 +02:00
# jgwallpaperchanger - dynamic menu (or submenu) to configure/set wallpapers
2021-05-30 01:50:56 +02:00
#
2024-09-16 00:47:14 +02:00
if [[ $1 == "-r" || "$1" == "-d" ]];then
2023-06-02 14:47:27 +02:00
me="${0##*/} -s"
else
me="${0##*/} ${1:--s}"
fi
2023-05-30 19:42:51 +02:00
#SLIDESHOW CONF
2021-05-30 01:50:56 +02:00
CONFIG_DIR="$HOME/.config/mbwallpaper"
2023-06-02 14:47:27 +02:00
CONF_FILE="$CONFIG_DIR/mbwallpaper.conf"
2021-05-30 01:50:56 +02:00
WALLPAPERS_LIST="$CONFIG_DIR/wplist"
# Make config directory if not exist
mkdir -p $CONFIG_DIR
# If config file not exist create one with defaults
2023-06-02 14:47:27 +02:00
if [ ! -f $CONF_FILE ]; then
cat <<EOF > ${CONF_FILE}
2021-05-30 01:50:56 +02:00
# Directory with wallpapers
wallpaper_dir=/usr/share/backgrounds/
# Rotate time in seconds
interval=10
2023-06-02 14:47:27 +02:00
# Tint2 panel executor button left click action
t2_button_lclick_action=choose
2021-05-30 01:50:56 +02:00
EOF
fi
# read config variables from file
2023-06-02 14:47:27 +02:00
source <(grep = $CONF_FILE)
2024-09-10 07:02:49 +02:00
wallpaper_dir2=${wallpaper_dir/$HOME/\~}
#notify-send.sh "Wallpaper Dir" "${wallpaper_dir}"
2023-05-30 19:42:51 +02:00
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(){
2024-01-28 21:39:36 +01:00
case $t2_button_lclick_action in
random) mbwallpaper -o;;
choose) pcmanwp;;
2024-09-10 07:02:49 +02:00
preview) mbwallpaper -c;;
menu) jgwallpaperchanger ipc;;
slideshow) run_wallpaperslideshow;;
2024-01-28 21:39:36 +01:00
window) ycolorizer;;
2024-09-10 07:02:49 +02:00
colmenu) colorizer -s;;
2024-01-28 21:39:36 +01:00
esac
2023-05-30 19:42:51 +02:00
}
main(){
2021-05-30 01:50:56 +02:00
case $LANG in
pl*)
2024-09-16 00:47:14 +02:00
_TITLE="Zmieniacz <b>tapet</b>"
_WALLPAPERS="Tapety"
_RANDWALL="<b>Losowa</b> tapeta"
_EDIT_WPDIRS="Edytuj katalogi z tapetami"
_GENERATOR="<b>Generuj</b> <small>(ImageMagick)</small>..."
_CHOOSE_WP="<b>Wybierz</b> tapetę..."
_SLIDESHOW_DESC="Pokaz slajdów"
_SLIDESHOW="pokaz slajdów"
_ABOUT_SLIDESHOW="O pokazie 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>"
_INTERVAL="Interwał slajdów"
_SEC="sekund"
_WPDIR="Katalog"
_WPDIRS="Katalogi z tapetami"
_WPDIRS_DESC="<small><i>dla <b>losowa</b>/<b>podgląd</b>/<b>pokaz slajdów</b></i></small>"
_TOTAL="Razem"
_WPS="tapety w"
_DIRS="katalogach"
_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)"
_P_B_LC_ACTION="Po lewym kliku w przycisk na panelu"
_RAND="losuj"
_CHOOSE="wybierz"
_WALL_MENU="menu tapet"
_WALL_MENU_DESC="Menu Tapet"
_PREVIEW="podgląd"
_COL_WINDOW="okno"
_COL_MENU="menu"
_RANDOM_DESC="Ustaw <b>losową</b> tapetę"
_CHOOSE_DESC="<b>Wybierz</b> tapetę (z menu kontekstowego)"
_PREVIEW_DESC="<b>Podgląd</b> <i>użyj</i> <span bgcolor='#333333' color='#d3d3d3'> <small></small> </span> <span bgcolor='#333333' color='#d3d3d3'> <small></small> </span> <span bgcolor='#333333' color='#d3d3d3'> <small>Enter</small> </span> <span bgcolor='#333333' color='#d3d3d3'> <small>Esc</small> </span>"
_COL_WINDOW_DESC="Colorizer - <b>okno</b>"
_COL_MENU_DESC="Colorizer - dynamiczne <b>menu</b>"
2021-05-30 01:50:56 +02:00
;;
*)
2024-09-16 00:47:14 +02:00
_TITLE="Wallpaper <b>Menu</b>"
_WALLPAPERS="Wallpapers"
_RANDWALL="<b>Random</b> Wallpaper"
_EDIT_WPDIRS="Edit Wallpaper dirs"
_GENERATOR="<b>Generate</b> <small>(ImageMagick)</small>..."
_CHOOSE_WP="<b>Choose</b> Wallpaper <small>(from context menu)</small>"
_SLIDESHOW_DESC="Wallpaper <b>Slideshow</b>"
_SLIDESHOW="slideshow"
_ABOUT_SLIDESHOW="About Slideshow"
_STARTS="Start Slideshow <small>(<i>stopped</i>)</small>"
_STOPS="Stop Slideshow <small>(<i>running - interval: $interval sec.</i>)</small>"
_INTERVAL="Interval"
_SEC="seconds"
_WPDIR="Directory"
_WPDIRS="Directories with Wallpapers"
_WPDIRS_DESC="<small><i>for <b>random</b>/<b>preview</b>/<b>slideshow</b> utils</i></small>"
_TOTAL="Total"
_WPS="wallpapers in"
_DIRS="dirs"
_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="<i>left-click</i> action"
_P_B_LC_ACTION="Panel button left-click action"
_RAND="random"
_CHOOSE="choose"
_WALL_MENU="wallmenu"
_WALL_MENU_DESC="Wallpaper Menu"
_PREVIEW="preview and set"
_COL_WINDOW="window"
_COL_MENU="menu"
_RANDOM_DESC="Set <b>random</b> wallpaper"
_CHOOSE_DESC="<b>Choose</b> wallpaper (<i>from context menu</i>)"
_PREVIEW_DESC="<b>Preview</b> & set <i>use</i> <span bgcolor='#333333' color='#d3d3d3'> <small></small> </span> <span bgcolor='#333333' color='#d3d3d3'> <small></small> </span> <span bgcolor='#333333' color='#d3d3d3'> <small>Enter</small> </span> <span bgcolor='#333333' color='#d3d3d3'> <small>Esc</small> </span>"
_COL_WINDOW_DESC="Colorizer - <b>window</b>"
_COL_MENU_DESC="Colorizer - dynamic <b>menu</b>"
2021-05-30 01:50:56 +02:00
;;
esac
. $HOME/.config/mabox/mabox.conf
2023-06-02 14:47:27 +02:00
2022-06-08 21:46:21 +02:00
2024-09-10 07:02:49 +02:00
help="\nBased on <a href='https://forum.maboxlinux.org/t/chwp-desktop-wallpaper-changer/496'>idea</a> of Mabox forum member Shwaybo.\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)")
2024-09-16 00:47:14 +02:00
[[ "$1" == "-s" || "$1" == "ipc" ]] && : || out+=("^sep($_WALLPAPERS)")
2024-09-10 07:02:49 +02:00
if ! pgrep -f "mbwallpaper -s" > /dev/null; then
2022-12-06 21:55:05 +01:00
#out+=("$NITROGEN,nitrogen")
2024-09-16 00:47:14 +02:00
out+=("<big></big> $_RANDWALL,mbwallpaper -o;$me")
out+=("<big></big> $_CHOOSE_WP,pcmanwp")
2024-09-10 07:02:49 +02:00
out+=("^sep()")
2024-09-16 00:47:14 +02:00
out+=("<big>易</big> $_PREVIEW_DESC,mbwallpaper -c")
out+=("<big></big> $_SLIDESHOW_DESC,^checkout(sshow)")
out+=("<big></big> $_GENERATOR,^pipe(jgwallpapergenerate)")
2023-05-30 19:42:51 +02:00
out+=("^sep()")
2024-09-16 00:47:14 +02:00
out+=("<big></big> $_WPDIR [ <b>${wallpaper_dir2}</b> ],^checkout(wpdirs)")
2024-09-10 07:02:49 +02:00
out2+=("^tag(wpdirs)")
2024-09-16 00:47:14 +02:00
out2+=("^sep($_WPDIRS)")
out2+=("^sep($_WPDIRS_DESC)")
2024-09-10 07:02:49 +02:00
readarray -t wpdirs < <(grep -v '^\s*$\|^#\|^\s*\#' "$CNF_FILE")
2024-09-16 00:47:14 +02:00
[[ -d "$(xdg-user-dir PICTURES)/imagick" ]] && wallp=$(shopt -s nullglob ; set -- $(xdg-user-dir PICTURES)/imagick/*.{jpg,JPG,jpeg,JPEG,png,PNG,avif} ; echo $#)
[[ "$wallp" -gt "1" ]] && wpdirs=("$(xdg-user-dir PICTURES)/imagick" "${wpdirs[@]}")
2024-09-10 07:02:49 +02:00
wpdirs=("/usr/share/backgrounds/" "${wpdirs[@]}")
#notify-send.sh "DIRS" "${#wpdirs[@]}"
2024-09-16 00:47:14 +02:00
wpimgs=0
2024-09-10 07:02:49 +02:00
for dir in "${wpdirs[@]}"
do
2024-09-16 00:47:14 +02:00
wpdir=${dir/\~/$HOME}
wallp=$(shopt -s nullglob ; set -- $wpdir/*.{jpg,JPG,jpeg,JPEG,png,PNG,avif} ; echo $#)
[[ "$wallpaper_dir2" == "${dir}" ]] && out2+=("<big>綠</big> <small>(${wallp})</small> <b>${dir}</b>") || out2+=("<big>祿</big> <small>(${wallp})</small> ${dir},mbwallpaper changedir ${dir};$me")
wpimgs=$((wpimgs+wallp))
2024-09-10 07:02:49 +02:00
done
2024-09-16 00:47:14 +02:00
out2+=("^sep($_TOTAL: <b>$wpimgs</b> $_WPS <b>${#wpdirs[@]}</b> $_DIRS)")
out2+=("<big></big> $_EDIT_WPDIRS,xdg-open $CNF_FILE")
2023-09-08 13:26:04 +02:00
2023-05-30 19:42:51 +02:00
2021-05-30 01:50:56 +02:00
else
2024-09-16 00:47:14 +02:00
out+=("$_STOPS,killall mbwallpaper;pkill -f 'yad --not';$me")
2021-05-30 01:50:56 +02:00
fi
2023-05-30 19:42:51 +02:00
out1+=("^tag(sshow)")
2024-09-16 00:47:14 +02:00
out1+=("^sep($_SLIDESHOW_DESC)")
out1+=("$_STARTS,run_wallpaperslideshow")
out1+=("$_INTERVAL [ <b>$interval</b> ] <small>($_SEC)</small>,^checkout(interval)")
2023-05-30 19:42:51 +02:00
out1+=("^sep()")
2024-09-10 07:02:49 +02:00
#out1+=("<big></big> $EDITCONF ,xdg-open $CONF_FILE")
#out1+=("<big></big> $OPENDIR,pcmanfm -n $wallpaper_dir")
2024-09-16 00:47:14 +02:00
out1+=("$_ABOUT_SLIDESHOW,\"\"\"notify-send.sh -u critical -i mbcc 'Wallpaper Changer - rotate desktop wallpaper every n-seconds' \"$help\" \"\"\"")
2021-05-30 01:50:56 +02:00
out2+=("^tag(interval)")
2024-09-16 00:47:14 +02:00
out2+=("^sep($_INTERVAL)")
2023-06-02 14:47:27 +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} $CONF_FILE;$me")");done
2021-05-30 01:50:56 +02:00
2023-05-30 19:42:51 +02:00
2021-05-30 01:50:56 +02:00
### RUN
2024-08-22 14:40:39 +02:00
if [[ $1 == "-s" || $1 == "-c" || $1 == "-u" || $1 == "ipc" || $1 == "-d" ]]; then
2021-09-24 01:40:09 +02:00
. /usr/share/mb-jgtools/pipemenu-standalone.cfg
2023-09-05 19:04:12 +02:00
2024-08-22 14:40:39 +02:00
2022-06-08 21:46:21 +02:00
case "$1" in
2024-09-16 00:47:14 +02:00
-s) out+=(" ${arrow_string_left} $_LEFTPANEL,mb-jgtools places");;
2023-09-05 19:04:12 +02:00
-c) out+=(" ${arrow_string_left} Colorizer,colorizer -s");;
-u) out+=(" ${arrow_string_left} Settings menu,mb-jgtools settings");;
2024-08-22 14:40:39 +02:00
-d) POSITION_MODE=pointer;;
2023-05-30 19:42:51 +02:00
ipc) POSITION_MODE=${1:-fixed}
2024-09-10 07:02:49 +02:00
out+=("^sep(Mabox Colorizer)")
2024-09-16 00:47:14 +02:00
out+=("$_COLORIZER_HELP,ycolorizer")
out+=("$_COLORIZER_ROOT,colorizer -s")
2023-06-02 14:47:27 +02:00
out+=("^sep()")
2024-09-16 00:47:14 +02:00
out+=("$_COLORIZER_FONTS,colorizer-fonts -s")
2023-09-23 12:24:36 +02:00
out+=("^sep()")
2024-09-16 00:47:14 +02:00
out+=("$_COLORIZER_OB,colorizer-ob -s")
out+=("$_COLORIZER_MENU,colorizer-menus -s")
out+=("$_COLORIZER_CONKY,colorizer-conky -s")
2023-05-30 19:42:51 +02:00
out+=("^sep()")
2024-09-16 00:47:14 +02:00
out+=("$_COLORIZER_PYRADIO,colorizer-pyradio -s")
out+=("$_COLORIZER_CAVA,colorizer-cava -s")
2023-09-05 19:04:12 +02:00
out+=("^sep()")
2023-09-08 13:26:04 +02:00
2024-01-28 21:39:36 +01:00
case $t2_button_lclick_action in
2024-09-16 00:47:14 +02:00
random) out+=(" $_B_LC_ACTION: <b>[ $_RAND ]</b>,^checkout(laction)");;
choose) out+=(" $_B_LC_ACTION: <b>[ $_CHOOSE ]</b>,^checkout(laction)");;
preview) out+=(" $_B_LC_ACTION: <b>[ $_PREVIEW ]</b>,^checkout(laction)");;
menu) out+=(" $_B_LC_ACTION: <b>[ $_WALL_MENU ]</b>,^checkout(laction)");;
slideshow) out+=(" $_B_LC_ACTION: <b>[ $_SLIDESHOW ]</b>,^checkout(laction)");;
window) out+=(" $_B_LC_ACTION: <b>[ $_COL_WINDOW ]</b>,^checkout(laction)");;
colmenu) out+=(" $_B_LC_ACTION: <b>[ $_COL_MENU ]</b>,^checkout(laction)");;
*) out+=(" $_B_LC_ACTION: <b>[ $_CHOOSE ]</b>,^checkout(laction)");;
2024-01-28 21:39:36 +01:00
esac
2023-06-02 14:47:27 +02:00
out2+=("^tag(laction)")
2024-09-16 00:47:14 +02:00
out2+=("^sep($_P_B_LC_ACTION)")
[[ "$t2_button_lclick_action" == "random" ]] && out2+=("<big>綠</big> $_RANDOM_DESC") || out2+=("<big>祿</big> $_RANDOM_DESC,mb-setvar t2_button_lclick_action=random $CONF_FILE")
[[ "$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" == "preview" ]] && out2+=("<big>綠</big> $_PREVIEW_DESC") || out2+=("<big>祿</big> $_PREVIEW_DESC,mb-setvar t2_button_lclick_action=preview $CONF_FILE")
[[ "$t2_button_lclick_action" == "menu" ]] && out2+=("<big>綠</big> $_WALL_MENU_DESC") || out2+=("<big>祿</big> $_WALL_MENU_DESC,mb-setvar t2_button_lclick_action=menu $CONF_FILE")
[[ "$t2_button_lclick_action" == "slideshow" ]] && out2+=("<big>綠</big> $_SLIDESHOW_DESC") || out2+=("<big>祿</big> $_SLIDESHOW_DESC,mb-setvar t2_button_lclick_action=slideshow $CONF_FILE")
2024-01-28 21:39:36 +01:00
out2+=("^sep()")
2024-09-16 00:47:14 +02:00
[[ "$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" == "colmenu" ]] && out2+=("<big>綠</big> $_COL_MENU_DESC") || out2+=("<big>祿</big> $_COL_MENU_DESC,mb-setvar t2_button_lclick_action=colmenu $CONF_FILE")
2023-05-30 19:42:51 +02:00
;;
2022-06-08 21:46:21 +02:00
esac
2024-09-16 00:47:14 +02:00
#. $HOME/.config/mabox/mabox.conf
2021-05-30 01:50:56 +02:00
2021-06-03 14:06:57 +02:00
2021-06-01 13:38:06 +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
2023-09-05 19:04:12 +02:00
JGWIDTH=$((jgtools_padding + 270 + jgtools_padding))
MENU_PADDING_TOP=$((jgtools_padding + 150))
2022-05-14 23:17:53 +02:00
#WALLPAPER
2024-08-13 22:54:48 +02:00
read WALLPATH<<< $(grep file "$HOME"/.config/nitrogen/bg-saved.cfg | tail -1 | 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
2024-09-16 00:47:14 +02:00
magick 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"
2024-09-16 00:47:14 +02:00
MENU_MARGIN_Y="80"
2021-05-30 01:50:56 +02:00
mkconfigfile
cat <<EOF > ${MENU_ITEMS}
2023-09-05 19:04:12 +02:00
@icon,,$((jgtools_padding )),$((jgtools_padding)),270,150,4,left,top,,,${THUMB}
2024-09-16 00:47:14 +02:00
@rect,,$((jgtools_padding)),$((jgtools_padding + 119)),270,28,0,left,top,#222222 20,#222222 70,
@text,,$((jgtools_padding + 6)),$((jgtools_padding + 100)),100,28,0,left,top,#DDDDDD 60,${WINCLR},<span size='41600' font_family='Ubuntu'><big></big></span>
@text,,$((jgtools_padding + 84)),$((jgtools_padding + 119)),150,28,0,left,top,#FFFFFF ,${WINCLR},<span size='10400' font_family='Ubuntu'>$_TITLE</span>
2021-05-30 01:50:56 +02:00
$(printf '%s\n' "${out[@]}")
2023-05-30 19:42:51 +02:00
$(printf '%s\n' "${out1[@]}")
2021-05-30 01:50:56 +02:00
$(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()"
2024-09-16 00:47:14 +02:00
printf '%s\n' "<i>$_REMOVE</i>,mb-setvar places_jgwallpaperchanger=false;mb-jgtools places"
2021-05-30 01:50:56 +02:00
fi
2023-05-30 19:42:51 +02:00
printf '%s\n' "${out1[@]}"
2021-05-30 01:50:56 +02:00
printf '%s\n' "${out2[@]}"
2023-05-30 19:42:51 +02:00
}
case "$1" in
lclick) lclick;;
2024-09-16 00:47:14 +02:00
*) time main "$@";;
2023-05-30 19:42:51 +02:00
esac