mabox-pipemenus/usr/bin/jgwallpaperchanger

293 lines
9.6 KiB
Plaintext
Raw Permalink Normal View History

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
#
2023-06-02 14:47:27 +02:00
if [[ $1 == "-r" ]];then
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
# Wallpaper setter program: nitrogen or feh
setter=nitrogen
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)
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;;
window) ycolorizer;;
menu) colorizer -s;;
esac
2023-05-30 19:42:51 +02:00
}
main(){
2021-05-30 01:50:56 +02:00
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"
2023-05-30 19:42:51 +02:00
EDIT_WPDIRS="Edytuj katalogi z tapetami"
2022-02-18 20:34:22 +01:00
GENERATOR="Generuj (ImageMagick)..."
2023-06-02 14:47:27 +02:00
CHOOSE_WP="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>"
2023-05-30 19:42:51 +02:00
STOPS="Zatrzymaj Pokaz slajdów <small>(<i>działający - interwał: $interval sek.</i>)</small>"
2021-05-30 01:50:56 +02:00
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"
2023-05-30 19:42:51 +02:00
OBTHEME="Motyw Openbox"
2024-01-28 21:39:36 +01:00
MENUPANELS="Menu i Panele"
2023-06-02 14:47:27 +02:00
COLORIZER_HELP="Okno główne i Pomoc"
2023-09-23 12:24:36 +02:00
COLORIZER_ROOT="<b>Colorizer</b> menu główne"
COLORIZER_FONTS="Konfiguruj <b>Czcionki</b>"
2023-09-05 19:04:12 +02:00
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>"
2023-06-02 14:47:27 +02:00
B_LC_ACTION="Akcja przycisku (lewy klik)"
RAND="losuj"
CHOOSE="wybierz"
2024-01-28 21:39:36 +01:00
COL_WINDOW="okno"
COL_MENU="menu"
2023-06-04 13:41:55 +02:00
RANDOM_DESC="Ustaw <b>losową</b> tapetę"
CHOOSE_DESC="<b>Wybierz</b> tapetę (z menu kontekstowego)"
2024-01-28 21:39:36 +01:00
COL_WINDOW_DESC="Colorizer - <b>okno</b>"
COL_MENU_DESC="Colorizer - dynamiczne <b>menu</b>"
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"
2023-05-30 19:42:51 +02:00
EDIT_WPDIRS="Edit Wallpaper dirs"
2022-02-18 20:34:22 +01:00
GENERATOR="Generate (ImageMagick)..."
2023-09-05 19:04:12 +02:00
CHOOSE_WP="Choose Wallpaper <small>(from context menu)</small>"
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>"
2023-05-30 19:42:51 +02:00
STOPS="Stop Slideshow <small>(<i>running - interval: $interval sec.</i>)</small>"
2021-05-30 01:50:56 +02:00
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"
2023-05-30 19:42:51 +02:00
OBTHEME="Openbox Theme"
MENUPANELS="Menus/Panels"
2023-06-02 14:47:27 +02:00
COLORIZER_HELP="Main Window and Help"
2023-09-23 12:24:36 +02:00
COLORIZER_ROOT="<b>Colorizer</b> rootmenu"
COLORIZER_FONTS="Configure <b>Fonts</b>"
2023-06-04 13:41:55 +02:00
COLORIZER_OB="<b>Openbox</b> module"
2023-09-23 12:24:36 +02:00
COLORIZER_MENU="<b>Menus/SidePanels</b> module"
2023-06-04 13:41:55 +02:00
COLORIZER_CONKY="<b>Conky</b> module"
2023-09-05 19:04:12 +02:00
COLORIZER_PYRADIO="<b>PyRadio</b> module"
COLORIZER_CAVA="<b>Cava</b> module"
2023-06-04 13:41:55 +02:00
B_LC_ACTION="Button <i>left-click</i> action"
2023-06-02 14:47:27 +02:00
RAND="random"
CHOOSE="choose"
2024-01-28 21:39:36 +01:00
COL_WINDOW="window"
COL_MENU="menu"
2023-06-04 13:41:55 +02:00
RANDOM_DESC="Set <b>random</b> wallpaper"
CHOOSE_DESC="<b>Choose</b> wallpaper (<i>from context menu</i>)"
2024-01-28 21:39:36 +01:00
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
2023-05-19 00:17:14 +02: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")
2023-05-30 19:42:51 +02:00
out+=("<big></big> $RANDWALL,mbwallpaper -o;$me")
2023-09-08 13:26:04 +02:00
out+=("<big>󰉔</big> $CHOOSE_WP,pcmanwp")
2023-05-19 00:17:14 +02:00
#out+=("$GENERATOR,^pipe(jgwallpapergenerate)")
2023-05-30 19:42:51 +02:00
out+=("<big>󰧸</big> $SLIDESHOW,^checkout(sshow)")
out+=("^sep()")
out+=("<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
2023-05-18 16:05:29 +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)")
out1+=("^sep($SLIDESHOW)")
out1+=("$STARTS,run_wallpaperslideshow;$me")
2023-06-02 14:47:27 +02:00
out1+=("\"\"\"$WALLDIR: <small>[ <b>$wallpaper_dir</b> ]</small>\"\"\",xdg-open $CONF_FILE")
2023-05-30 19:42:51 +02:00
out1+=("$INTERVAL [ <b>$interval</b> ] <small>($SEC)</small>,^checkout(interval)")
out1+=("^sep()")
2023-06-02 14:47:27 +02:00
out1+=("<big></big> $EDITCONF ,xdg-open $CONF_FILE")
2023-05-30 19:42:51 +02:00
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'\"\"\"")
2021-05-30 01:50:56 +02:00
out2+=("^tag(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
2023-05-30 19:42:51 +02:00
if [[ $1 == "-s" || $1 == "-c" || $1 == "-u" || $1 == "ipc" ]]; then
2021-09-24 01:40:09 +02:00
. /usr/share/mb-jgtools/pipemenu-standalone.cfg
2023-09-05 19:04:12 +02:00
2022-06-08 21:46:21 +02:00
case "$1" in
2023-09-05 19:04:12 +02:00
-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");;
2023-05-30 19:42:51 +02:00
ipc) POSITION_MODE=${1:-fixed}
2023-06-02 14:47:27 +02:00
out+=("^sep(Colorizer)")
out+=("$COLORIZER_HELP,ycolorizer")
out+=("$COLORIZER_ROOT,colorizer -s")
out+=("^sep()")
2023-09-23 12:24:36 +02:00
out+=("$COLORIZER_FONTS,colorizer-fonts -s")
out+=("^sep()")
2023-06-02 14:47:27 +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()")
2023-09-05 19:04:12 +02:00
out+=("$COLORIZER_PYRADIO,colorizer-pyradio -s")
out+=("$COLORIZER_CAVA,colorizer-cava -s")
out+=("^sep()")
2023-09-08 13:26:04 +02:00
2024-01-28 21:39:36 +01:00
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
2023-06-02 14:47:27 +02:00
out2+=("^tag(laction)")
2023-06-04 13:41:55 +02:00
out2+=("^sep(Panel button left-click action)")
2024-01-28 21:39:36 +01:00
[[ "$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")
2023-05-30 19:42:51 +02:00
;;
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
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
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}
2023-09-05 19:04:12 +02:00
@icon,,$((jgtools_padding )),$((jgtools_padding)),270,150,4,left,top,,,${THUMB}
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()"
printf '%s\n' "<i>$REMOVE</i>,mb-setvar places_jgwallpaperchanger=false;mb-jgtools places"
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;;
*) main "$@";;
esac