#!/bin/bash
# jgwallpaperchanger - panel executor/dynamic menu (or submenu) to configure/set wallpapers 
#


if [[ $1 == "-r" || "$1" == "-d" ]];then
me="${0##*/} -s"
else
me="${0##*/} ${1:--s}"
fi
## Favorited wp list
FAVWP="$HOME/.config/mabox/wp_fav.csv"

#SLIDESHOW CONF
CONFIG_DIR="$HOME/.config/mbwallpaper"
CONF_FILE="$CONFIG_DIR/mbwallpaper.conf"
WALLPAPERS_LIST="$CONFIG_DIR/wplist"

## SYSTEM AND USER SAVED THEMES
OB_SYSTHEMES="/usr/share/mabox-colorizer/colorschemes/ob.csv"
OB_USERTHEMES="$HOME/.config/colorizer/openbox/userthemes.csv"

# 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
# Tint2 panel executor button left click action
t2_button_lclick_action=random
EOF
fi

# read config variables from file
source <(grep = $CONF_FILE)
wallpaper_dir2=${wallpaper_dir/$HOME/\~}
#notify-send.sh "Wallpaper Dir" "${wallpaper_dir}"

wp_icon=${wp_icon:-"wide"}

#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 "Random", "Choose wallpaper" PCmanFM wrapper, "Slideshow", Preview and set" utils
# From File Manager set wallpapers using context (right click) menu 
~/wallpapers/
EOF
fi

lclick(){
case $t2_button_lclick_action in
    random) mbwallpaper -o;;
    randfav) jgwallpaperchanger randomfav;;
    choose) pcmanwp;;
    preview) mbwallpaper -c;;
    menu) jgwallpaperchanger ipc;;
    slideshow) run_wallpaperslideshow;;
    window) ycolorizer;;
    colmenu) colorizer -s;;
    *) mbwallpaper -o;;
esac
}
wheelup() {
case $t2_button_wheelup_action in
	random) mbwallpaper -o;;
	win-switch) skippy-xd --expose;;
	desk-switch) skippy-xd --paging;;
	win-prev) skippy-xd --switch --prev;;
	win-next) skippy-xd --switch --next;;
	show-desk) show_desktop;;
	*) show_desktop;;
esac
}
wheeldown() {
case $t2_button_wheeldown_action in
	random) mbwallpaper -o;;
	win-switch) skippy-xd --expose;;
	desk-switch) skippy-xd --paging;;
	win-prev) skippy-xd --switch --prev;;
	win-next) skippy-xd --switch --next;;
	show-desk) show_desktop;;
	*) show_desktop;;
esac
}


main(){
. /usr/share/mb-jgtools/jgtools.inc

profile=${profile:-mabox}

case $LANG in
    pl*)
    _TITLE="Tapety i <b>stylizacja</b> pulpitu"
    _WALLPAPERS="Tapety"
    _RANDWALL="<b>Losowa</b> tapeta"
    _FAVORITES="Ulubione..."
    _FAVORITES_WP="Ulubione tapety"
    _RAND_FAV="Losowa z Ulubionych"
    _ADD_FAV="<b>Dodaj bieżącą</b> do Ulubionych"
    _REMOVE_FROM_FAV="Usuń z Ulubionych"
    _AND_SET_RANDOM="... i ustaw losową"
    _YES_REMOVE="Tak, usuń"
    _EDIT_FAV="Edytuj Ulubione"
    _DEFAULT_WP="Przywróć <b>domyślną</b>"
    _EDIT_WPDIRS="Edytuj katalogi z tapetami"
    _GENERATOR="<b>Generuj</b> <small>(ImageMagick)</small>..."
    _CHOOSE_WP="<b>Wybierz</b> tapetę..."
    _OPEN_DIR="Otwórz katalog i..."
    _USE_CONTEXTMENU="<small>użyj menu kontekstowego</small>"
    _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"
    _INTERVAL_DESC="Interwał Pokazu Slajdów"
    _SEC="sekund"
    _WPDIR="Kolekcje tapet"
    _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_PICOM="Kompozytor <b>Picom</b>"
    _COLORIZER_OB="Moduł <b>Openbox</b>"
    _COLORIZER_MENU="Moduł <b>Menu</b>"
    _COLORIZER_CONKY="<b>Menadżer</b> Widżetów <b>Conky</b>"
    _COLORIZER_PYRADIO="Moduł <b>PyRadio</b>"
    _COLORIZER_CAVA="Moduł <b>Cava</b>"
    _PANEL_ICON_ACTIONS="Ikona na panelu i akcje"
    _WIDE_ICON="Szeroka ikona"
    
    _B_LC_ACTION="lewy klik"
    _B_LC_ACTION="<i>lewy-klik</i>"
    _P_B_LC_ACTION="Po lewym kliku w przycisk na panelu"
    _B_WU_ACTION="<i>kółko-w-górę</i>"
    _P_B_WU_ACTION="Akcja dla kółko-w-górę"
    _B_WD_ACTION="<i>kółko-w-dół</i>"
    _P_B_WD_ACTION="Akcja dla kółko w dół"
    _RAND="losuj"
    _CHOOSE="wybierz"
    _WALL_MENU="menu tapet"
    _WALL_MENU_DESC="Menu Tapet"
    _PREVIEW="podgląd"
    _COL_WINDOW="okno"
    _COL_MENU="menu"
    _SHOW_DESK="show-desk"
    _WIN_SWITCH="win-switch"
    _DESK_SWITCH="desk-switch"
    _RANDOM_DESC="Ustaw <b>losową</b> tapetę"
    _RANDOMFAV_DESC="Ustaw <b>losową</b> z <b>ulubionych</b>"
    _CHOOSE_DESC="<b>Wybierz</b> tapetę (z menu kontekstowego)"
    _PREVIEW_DESC="<b>Zobacz</b> i ustaw"
    _COL_WINDOW_DESC="Colorizer - <b>okno</b>"
    _COL_MENU_DESC="Colorizer - dynamiczne <b>menu</b>"
    _SHOW_DESK_DESC="Pokaż pulpit"
    _WIN_SWITCH_DESC="Wybierz Okno (skippy-xd)"
    _DESK_SWITCH_DESC="Wybierz Pulpit (skippy-xd)"
    _GOBACK="<i>powrót</i>"
    
    _AUTOTHEMING="Auto theming (beta)"
    _ON_WP_CHANGE="(po zmianie tapety)"
    _AUTOTH_SETTINGS="Ustawienia Auto theming"
    _APPLY_COLORSCHEME_TO="Zastosuj kolory tapety do..."
    _APPLY_TO_ALL="<b>Wszystko</b>"
    _APPLY_REVERSE="<b>Wszystko</b> odwrotnie (jasny 󰑖  ciemny)"
    _APPLY_ONLY_TO="Zastosuj tylko do..."
    _RESET_WP_THEMES="Reset tapety i motywów"
    _ENABLED="włączony"
    _DISABLED="wyłączony"
    _LIGHTBG="<b>jasny</b> wariant"
    _DARKBG="<b>ciemny</b> wariant"
    _NONE="<b>none</b> wyłączone"
    
    _DESKTOP_STYLING="Stylizacja Pulpitu"
    _OB_WD="<b>OpenBox</b> Dekoracje Okien"
    _MABOX_MENUS=" <b>Menu</b> Maboxa"
    SYSTEM_THEMES="Systemowe"
    YOUR_THEMES="Moje motywy"
    SAVE_CURRTHEME="Zapisz aktualną kobfigurację jako..."
    OPEN_THEMEFILE="Odwórz plik z motywami w edytorze"
    THEME="Motyw"
    APPLY="Zastosuj"
    APPLY_THEME="Pełny motyw (kolory, czcionki i rozmiar)"
    APPLY_SCHEME="Tylko kolory"
    DELETE="Usuń"
    DELETE_THEME="Usuń motyw"
    OBTHEME_LBL="Motyw OpenBox"
    MONOCHROMATIC="Monochromatyczny"
    CHOOSE_AND_PICK="Wybierz wariant i pobierz kolor..."
    GENERATEFROMWP="Generuj z kolorów tapety..."
    EXACT="Dokładny"
    LIGHTBG="Jasne tło"
    DARKBG="Ciemne tło"
    RANDOMIZE="Generuj losowo"
    
    ;;
    *)
    _TITLE="Wallpaper &amp; Desktop <b>styling</b>"
    _WALLPAPERS="Wallpapers"
    _RANDWALL="<b>Random</b> Wallpaper"
    _FAVORITES="Favorite..."
    _FAVORITES_WP="Favorite Wallpapers"
    _RAND_FAV="Random from Favorites"
    _ADD_FAV="<b>Add current</b> to favorites"
    _REMOVE_FROM_FAV="Remove from Favorites"
    _AND_SET_RANDOM="... and set random"
    _YES_REMOVE="Yes, remove"
    _EDIT_FAV="Edit Favorites"
    _DEFAULT_WP="Restore <b>default</b>"
    _EDIT_WPDIRS="Edit Wallpaper dirs"
    _GENERATOR="<b>Generate</b> <small>(ImageMagick)</small>..."
    _CHOOSE_WP="<b>Choose</b> Wallpaper"
    _OPEN_DIR="Open directory and..."
    _USE_CONTEXTMENU="<small>use 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"
    _INTERVAL_DESC="Slideshow Interval"
    _SEC="seconds"
    _WPDIR="Wallpaper <b>Collections</b>"
    _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_CONKY="<b>Conky</b> Widget <b>Manager</b>"
    _COLORIZER_HELP="Main Window and Help"
    _COLORIZER_ROOT="<b>Colorizer</b> rootmenu"
    _COLORIZER_FONTS="Configure <b>Fonts</b>"
    _COLORIZER_PICOM="<b>Compositor</b> settings <b>(Picom)</b>"
    _PANEL_ICON_ACTIONS="Panel icon and actions"
    _WIDE_ICON="Wide icon"
    _B_LC_ACTION="<i>left-click</i>"
    _P_B_LC_ACTION="Panel icon left-click action"
    _B_WU_ACTION="<i>wheel-up</i>"
    _P_B_WU_ACTION="Panel icon wheel-up action"
    _B_WD_ACTION="<i>wheel-down</i>"
    _P_B_WD_ACTION="Panel icon wheel-down action"
    _RAND="random"
    _CHOOSE="choose"
    _WALL_MENU="wallmenu"
    _WALL_MENU_DESC="Wallpaper Menu"
    _PREVIEW="preview and set"
    _COL_WINDOW="window"
    _COL_MENU="menu"
    _SHOW_DESK="show-desk"
    _WIN_SWITCH="win-switch"
    _DESK_SWITCH="desk-switch"
    _RANDOM_DESC="Set <b>random</b> wallpaper"
    _RANDOMFAV_DESC="Set <b>random</b> from <b>favorites</b>"
    _CHOOSE_DESC="<b>Choose</b> wallpaper (<i>from context menu</i>)"
    _PREVIEW_DESC="<b>Preview</b> &amp; set"
    _COL_WINDOW_DESC="Colorizer - <b>window</b>"
    _COL_MENU_DESC="Colorizer - dynamic <b>menu</b>"
    _SHOW_DESK_DESC="Toggle ShowDesktop"
    _WIN_SWITCH_DESC="Windows Switcher (skippy-xd)"
    _DESK_SWITCH_DESC="Desktop Switcher (skippy-xd)"
    _GOBACK="<i>go back</i>"
    
    _AUTOTHEMING="Auto theming (beta)"
    _ON_WP_CHANGE="(on wallpaper change)"
    _AUTOTH_SETTINGS="Auto theming settings"
    _APPLY_COLORSCHEME_TO="Apply wallpaper colors to..."
    _APPLY_TO_ALL="<b>All</b> elements"
    _APPLY_REVERSE="<b>All</b> elements inversely (dark 󰑖 light)"
    _APPLY_ONLY_TO="Apply only to..."
    _RESET_WP_THEMES="Reset (wallpaper and themes)"
    _ENABLED="enabled"
    _DISABLED="disabled"
    _LIGHTBG="<b>light</b> variant"
    _DARKBG="<b>dark</b> variant"
    _NONE="<b>none</b> (disabled)"
    
    _DESKTOP_STYLING="Desktop styling"
    _OB_WD="<b>OpenBox</b> Window Decorations"
    _MABOX_MENUS="Mabox <b>Menus</b>"
    _CHANGE_THEME="Change theme"
    _CLICK_TO_APPLY="<i>click to apply</i>"
    SYSTEM_THEMES="System themes..."
    YOUR_THEMES="Your themes..."
    THEME="Theme"
    _GENERATE="Generate..."
    MONOCHROMATIC="Monochromatic <i>(pick color)</i>"
    CHOOSE_AND_PICK="Choose variant and pick color..."
    GENERATEFROMWP="...from wallpaper colors..."
    EXACT="exact"
    LIGHTBG="light variant"
    DARKBG="dark variant"
    RANDOMIZE="Random"
    _MORE_OPTIONS="<i>need more options?</i>"
    _COLOR_TUNING="<i>color tuning?</i>"
    _SAVE_OWN="<i>save/delete own themes?</i>"
    _USE="<i>use...</i>"
    ;;
esac

#. $HOME/.config/mabox/mabox.conf
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"

# WALLPAPER FAVORITES
if [[ ! -f "${FAVWP}" ]];then
cat <<EOF > ${FAVWP}
# Favorite wallpapers
# LABEL(NAME),PATH_TO_WALLPAPER_FILE
EOF
fi
# Wallpath 
read WALLPATH<<< $(grep file "$HOME"/.config/nitrogen/bg-saved.cfg |  tail -1 | cut -d'=' -f2)
wallpap=${WALLPATH/$HOME/\~}

#notify-send.sh "Wallpaper" "$wallpap"
# Read favorites
fav=0
isfav=0
while IFS=, read -r label wpfile
do
    if [[ "${wallpap}" == "${wpfile}" ]];then
    #notify-send.sh "FAV" "${wpfile}"
    favs+=("\"\"\"<big>${ron}</big>   ${label}\"\"\",^checkout(delfav)")
    out3+=("^tag(delfav)")
    out3+=("^sep($_REMOVE_FROM_FAV)")
    out3+=("^sep(<small>$_AND_SET_RANDOM ?</small>)")
    out3+=("\"\"\"$_YES_REMOVE <b>${label}</b>\"\"\",jgwallpaperchanger remfav ${wpfile:1};$me")
    isfav=1
    else
    favs+=("\"\"\"<big>${roff}</big>   ${label}\"\"\",nitrogen --set-scaled --save $wpfile;$me")
    fi
    ((fav++))
done < <(sort $FAVWP |grep -v '^\s*$\|^#\|^\s*#')
#done < <(grep -v '^\s*$\|^#\|^\s*#' "$FAVWP")

out+=("^sep($_WALLPAPERS)")
[[ "$1" == "-s" || "$1" == "ipc" || "$1" == "-d" ]] && : || out+=("^sep($_WALLPAPERS)")
if ! pgrep -f "mbwallpaper -s" > /dev/null; then
    #out+=("$NITROGEN,nitrogen")
    out+=("<big></big>   $_RANDWALL,mbwallpaper -o;$me")
    out+=("<span  fgcolor='red'><big></big></span>   $_FAVORITES 	[ <b>$fav</b> ],^checkout(favwp)")
    out2+=("^tag(favwp)")
    out2+=("^sep($_FAVORITES_WP)")
    if [[ "$wallpap" != "/usr/share/backgrounds/marek-piwnicki-FgagFhxW4Sc-unsplash.jpg" ]]; then
    :
    else
    isfav=1
    fi
    
    if [[ "${isfav}" != "1" ]];then
    out2+=("<span  fgcolor='red'><big>󱐮</big></span>   $_ADD_FAV,jgwallpaperchanger addfav ${wallpap};$me")
    out2+=("^sep()")
    fi
    
    out2+=("<big></big>   $_RAND_FAV,jgwallpaperchanger randomfav;$me")
    out2+=("^sep()")
    
    
    out2+=("${favs[@]}")
    out2+=("^sep()")
    out2+=("<big></big>   $_EDIT_FAV,xdg-open $FAVWP")
    if [[ "$wallpap" != "/usr/share/backgrounds/marek-piwnicki-FgagFhxW4Sc-unsplash.jpg" ]]; then
    out2+=("^sep()")
    out2+=("<big>󰦛</big>   $_DEFAULT_WP,nitrogen --set-scaled --save /usr/share/backgrounds/marek-piwnicki-FgagFhxW4Sc-unsplash.jpg;$me")
    fi
    
    
    
    
    #out+=("<big>󰉔</big>   $_CHOOSE_WP,pcmanwp")
    out+=("<big></big>   $_CHOOSE_WP,^checkout(choosefromdirs)")
    out2+=("^tag(choosefromdirs)")
    out2+=("^sep($_OPEN_DIR)")
    out2+=("^sep($_USE_CONTEXTMENU)")
    ### Needed for CHOOSE_WP and WPDIRS (Collections)
    readarray -t wpdirs < <(grep -v '^\s*$\|^#\|^\s*\#' "$CNF_FILE")
    
    [[ -d "$(xdg-user-dir PICTURES)/imagick" ]] && wallp=$(shopt -s nullglob ; set -- $(xdg-user-dir PICTURES)/imagick/*.{jpg,JPG,jpeg,JPEG,png,PNG,webp,WEBP,avif,AVIF} ; echo $#)
    if [[ "$wallp" -gt "1" ]];then 
    imagickdir="$(xdg-user-dir PICTURES)/imagick"
    imagickdir=${imagickdir/$HOME/\~}
    wpdirs=("$imagickdir" "${wpdirs[@]}")
    fi
    
    wpdirs=("/usr/share/backgrounds/" "${wpdirs[@]}")
    
    wpimgs=0
    for dir in "${wpdirs[@]}"
    do
    wpdir=${dir/\~/$HOME}
    wallp=$(shopt -s nullglob ; set -- $wpdir/*.{jpg,JPG,jpeg,JPEG,png,PNG,avif,AVIF,webp,WEBP} ; echo $#)
    out2+=("<small>(${wallp})</small> ${dir},pcmanfm ${dir}")
    wpimgs=$((wpimgs+wallp))
    done
    
    out+=("^sep()")
    out+=("<big></big>   $_PREVIEW_DESC,mbwallpaper -c")
    out+=("<big>󰧸</big>   $_SLIDESHOW_DESC,^checkout(sshow)")
    out+=("<big>󱡄</big>   $_GENERATOR,^pipe(jgwallpapergenerate)")
    out+=("^sep()")
    
    out2+=("^tag(wpdirs)")
    out2+=("^sep($_WPDIRS)")
    out2+=("^sep($_WPDIRS_DESC)")
    
    
    #notify-send.sh "DIRS" "${#wpdirs[@]}"
    
    
    wpimgs=0
    for dir in "${wpdirs[@]}"
    do
    wpdir=${dir/\~/$HOME}
    wallp=$(shopt -s nullglob ; set -- $wpdir/*.{jpg,JPG,jpeg,JPEG,png,PNG,avif,AVIF,webp,WEBP} ; echo $#)
    [[ "$wallpaper_dir2" == "${dir}" ]] &&  out2+=("<big>${ron}</big>   <small>(${wallp})</small> <b>${dir}</b>") || out2+=("<big>${roff}</big>   <small>(${wallp})</small> ${dir},mbwallpaper changedir ${dir};$me")
    wpimgs=$((wpimgs+wallp))
    done
    out2+=("^sep($_TOTAL: <b>$wpimgs</b> $_WPS <b>${#wpdirs[@]}</b> $_DIRS)")
    out2+=("<big></big>   $_EDIT_WPDIRS,xdg-open $CNF_FILE")
    out+=("<big>󰉔</big>  $_WPDIR [ <b>${#wpdirs[@]}</b> ],^checkout(wpdirs)")
    
    else
    out+=("<big></big>   $_STOPS,killall mbwallpaper;pkill -f 'yad --not';$me")
fi


out1+=("^tag(sshow)")
out1+=("^sep($_SLIDESHOW_DESC)")
out1+=("<big></big>   $_STARTS,run_wallpaperslideshow")
out1+=("^sep($_INTERVAL_DESC)")
[[ "${interval}" == "10" ]] && out1+=("<big>${ron}</big>   10s,mb-setvar interval=10 $CONF_FILE;$me") || out1+=("<big>${roff}</big>   10s,mb-setvar interval=10 $CONF_FILE;$me")
[[ "${interval}" == "30" ]] && out1+=("<big>${ron}</big>   30s,mb-setvar interval=30 $CONF_FILE;$me") || out1+=("<big>${roff}</big>   30s,mb-setvar interval=30 $CONF_FILE;$me")
[[ "${interval}" == "60" ]] && out1+=("<big>${ron}</big>    1m ,mb-setvar interval=60 $CONF_FILE;$me") || out1+=("<big>${roff}</big>    1m,mb-setvar interval=60 $CONF_FILE;$me")
[[ "${interval}" == "120" ]] && out1+=("<big>${ron}</big>    2m ,mb-setvar interval=120 $CONF_FILE;$me") || out1+=("<big>${roff}</big>    2m,mb-setvar interval=120 $CONF_FILE;$me")
[[ "${interval}" == "300" ]] && out1+=("<big>${ron}</big>    5m ,mb-setvar interval=300 $CONF_FILE;$me") || out1+=("<big>${roff}</big>    5m,mb-setvar interval=300 $CONF_FILE;$me")
[[ "${interval}" == "600" ]] && out1+=("<big>${ron}</big>   10m ,mb-setvar interval=600 $CONF_FILE;$me") || out1+=("<big>${roff}</big>   10m,mb-setvar interval=600 $CONF_FILE;$me")
[[ "${interval}" == "900" ]] && out1+=("<big>${ron}</big>   15m ,mb-setvar interval=900 $CONF_FILE;$me") || out1+=("<big>${roff}</big>   15m,mb-setvar interval=900 $CONF_FILE;$me")
[[ "${interval}" == "1800" ]] && out1+=("<big>${ron}</big>   30m ,mb-setvar interval=1800 $CONF_FILE;$me") || out1+=("<big>${roff}</big>   30m,mb-setvar interval=1800 $CONF_FILE;$me")
[[ "${interval}" == "3600" ]] && out1+=("<big>${ron}</big>    1h ,mb-setvar interval=3600 $CONF_FILE;$me") || out1+=("<big>${roff}</big>    1h,mb-setvar interval=3600 $CONF_FILE;$me")
#out1+=("<big></big>   $EDITCONF ,xdg-open $CONF_FILE")
#out1+=("<big></big>   $OPENDIR,pcmanfm -n $wallpaper_dir")
out1+=("^sep()")
out1+=("$_ABOUT_SLIDESHOW,\"\"\"notify-send.sh -u critical -i mbcc 'Wallpaper Changer - rotate desktop wallpaper every n-seconds' \"$help\" \"\"\"")

    #WALLPAPER and wallpaper colors
    WALLPALDIR="$HOME/.cache/colorizer/palettes"
    
    THUMBDIR="$HOME/.cache/colorizer/thumbs"
    mkdir -p ${THUMBDIR}
    NAME=${WALLPATH////_}
    if [[ "${NAME}" =~ ^_home_.* ]]; then
        n=${#HOME}
        ((n++))
        NAME=${NAME:${n}}
    fi
    ext="${WALLPATH##*.}"
    THUMB="${THUMBDIR}/${NAME}.png"
    if [[ ! -f "$THUMB" ]]; then
        magick ${WALLPATH} -resize 270x150^ -gravity center -extent 270x150 ${THUMB}
    fi
    # wp colors
    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
    
    mapfile -t w < "$WALLPALDIR/$NAME.clr"
    #if [[ "${#w[@]}" -lt 8 ]]; then
    #w+=("#2e3440" "#4c566a" "#5e81ac" "#bf616b" "#b48ead" "#a3be8c" "#ebcb8b" "#d8dee9" "#eceff4")
    #fi

if [ "${profile}" != "basic" ];then
### AUT0 THEMING
### AUTOTHEMING
COLORIZER_CONF="$HOME/.config/colorizer/colorizer.conf"
source ${COLORIZER_CONF}

out+=("^sep($_AUTOTHEMING)")
out+=("^sep(<i><small>$_ON_WP_CHANGE</small></i>)")

out+=("<big></big>   $_APPLY_COLORSCHEME_TO,^checkout(applyto)")
out2+=("^tag(applyto)")
[[ "${2}" == "applyto" ]] && out2+=("${arrow_string_left} ${arrow_string_left} ${arrow_string_left}   $_GOBACK,^back()")
out2+=("^sep($_APPLY_COLORSCHEME_TO)")
out2+=("<big></big>   $_APPLY_TO_ALL,w2theme colorize;$me applyto")
out2+=("<big></big>   $_APPLY_REVERSE,w2theme reverse;$me applyto")
out2+=("^sep($_APPLY_ONLY_TO)")
out2+=("^sep(Menu)")
out2+=(" $_LIGHTBG,w2theme menu light;$me applyto")
out2+=(" $_LIGHTBG 2,w2theme menu light2;$me applyto")
out2+=(" $_DARKBG,w2theme menu dark;$me applyto")
out2+=(" $_DARKBG 2,w2theme menu dark2;$me applyto")
out2+=("^sep(Conky)")
out2+=(" $_LIGHTBG,w2theme conky light;$me applyto")
out2+=(" $_DARKBG,w2theme conky dark;$me applyto")
out2+=("^sep(OpenBox)")
out2+=(" $_LIGHTBG,w2theme ob light;$me applyto")
out2+=(" $_DARKBG,w2theme ob dark;$me applyto")
[[ "${2}" == "applyto" ]] && out2+=("^sep()" "${arrow_string_left} ${arrow_string_left} ${arrow_string_left}   $_GOBACK,^back()")

out+=("^sep()")


[[ "$wall2themes" == "yes" ]] && out+=("<big>${cbon}</big>   $_AUTOTH_SETTINGS,^checkout(autotheming)") || out+=("<big>${cboff}</big>   $_AUTOTH_SETTINGS,^checkout(autotheming)")

out2+=("^tag(autotheming)")
[[ "${2}" == "autoth" ]] && out2+=("${arrow_string_left} ${arrow_string_left} ${arrow_string_left}   $_GOBACK,^back()")
out2+=("^sep($_AUTOTH_SETTINGS (beta))")
[[ "$wall2themes" == "yes" ]] && out2+=("<big>${ron}</big>   $_ENABLED") || out2+=("<big>${roff}</big>   $_ENABLED,mb-setvar wall2themes=yes $COLORIZER_CONF;$me")
[[ "$wall2themes" != "yes" ]] && out2+=("<big>${ron}</big>   $_DISABLED") || out2+=("<big>${roff}</big>   $_DISABLED,mb-setvar wall2themes=no $COLORIZER_CONF;$me")

out2+=("^sep(<i>OpenBox</i>)")
[[ "$wall2themes_ob" == "light" ]] && out2+=("<big>${ron}</big>   $_LIGHTBG") || out2+=("<big>${roff}</big>   $_LIGHTBG,mb-setvar wall2themes_ob=light $COLORIZER_CONF;$me autoth")   
[[ "$wall2themes_ob" == "dark" ]] && out2+=("<big>${ron}</big>   $_DARKBG") || out2+=("<big>${roff}</big>   $_DARKBG,mb-setvar wall2themes_ob=dark $COLORIZER_CONF;$me autoth")   
out2+=("^sep()")
[[ "$wall2themes_ob" == "none" ]] && out2+=("<big>${ron}</big>   $_NONE") || out2+=("<big>${roff}</big>   $_NONE,mb-setvar wall2themes_ob=none $COLORIZER_CONF;$me autoth")
out2+=("^sep(<i>Menu</i>)")
[[ "$wall2themes_menu" == "light" ]] && out2+=("<big>${ron}</big>   $_LIGHTBG") || out2+=("<big>${roff}</big>   $_LIGHTBG,mb-setvar wall2themes_menu=light $COLORIZER_CONF;$me autoth")   
[[ "$wall2themes_menu" == "dark" ]] && out2+=("<big>${ron}</big>   $_DARKBG") || out2+=("<big>${roff}</big>   $_DARKBG,mb-setvar wall2themes_menu=dark $COLORIZER_CONF;$me autoth")   
out2+=("^sep()")
[[ "$wall2themes_menu" == "none" ]] && out2+=("<big>${ron}</big>   $_NONE") || out2+=("<big>${roff}</big>   $_NONE,mb-setvar wall2themes_menu=none $COLORIZER_CONF;$me autoth")
out2+=("^sep(<i>Conky</i>)")
[[ "$wall2themes_conky" == "light" ]] && out2+=("<big>${ron}</big>   $_LIGHTBG") || out2+=("<big>${roff}</big>   $_LIGHTBG,mb-setvar wall2themes_conky=light $COLORIZER_CONF;$me autoth")   
[[ "$wall2themes_conky" == "dark" ]] && out2+=("<big>${ron}</big>   $_DARKBG") || out2+=("<big>${roff}</big>   $_DARKBG,mb-setvar wall2themes_conky=dark $COLORIZER_CONF;$me autoth")   
out2+=("^sep()")
[[ "$wall2themes_conky" == "none" ]] && out2+=("<big>${ron}</big>   $_NONE") || out2+=("<big>${roff}</big>   $_NONE,mb-setvar wall2themes_conky=none $COLORIZER_CONF;$me autoth")  

out2+=("^sep(PyRadio / Cava)")
out2+=("PyRadio and Cava,^checkout(pycava)")
out3+=("^tag(pycava)")
out3+=("^sep(Pyradio)")
[[ "$wall2themes_pyradio" == "light" ]] && out3+=("<big>${ron}</big>   $_LIGHTBG") || out3+=("<big>${roff}</big>   $_LIGHTBG,mb-setvar wall2themes_pyradio=light $COLORIZER_CONF;$me autoth")   
[[ "$wall2themes_pyradio" == "dark" ]] && out3+=("<big>${ron}</big>   $_DARKBG") || out3+=("<big>${roff}</big>   $_DARKBG,mb-setvar wall2themes_pyradio=dark $COLORIZER_CONF;$me autoth")   
out3+=("^sep()")
[[ "$wall2themes_pyradio" == "none" ]] && out3+=("<big>${ron}</big>   $_NONE") || out3+=("<big>${roff}</big>   $_NONE,mb-setvar wall2themes_pyradio=none $COLORIZER_CONF;$me autoth")
out3+=("^sep(Cava)")
out3+=("^sep(<small><i>not implemented yet</i></small>)")
out3+=("Use Colorizer Cava,colorizer-cava -s")


palettes=$(shopt -s nullglob ; set -- $WALLPALDIR/*.clr ; echo $#)
if [[ "$palettes" -gt "1" ]];then
out2+=("^sep()")
out2+=("<big></big>   Remove cached palletes (<b>$palettes</b>),rm $WALLPALDIR/*.clr;$me")
fi

[[ "${2}" == "autoth" ]] && out2+=("^sep()" "${arrow_string_left} ${arrow_string_left} ${arrow_string_left}   $_GOBACK,^back()")





out+=("^sep()")
out+=("<big>󰅙</big>   $_RESET_WP_THEMES,w2theme resetall;$me")


### STYLES
out+=("^sep($_DESKTOP_STYLING)")
out+=("<big></big>   $_OB_WD,^checkout(obox)")
out+=("<big></big>   $_MABOX_MENUS,^checkout(jgmenus)")

case "$2" in
    obox)option="--checkout=obox";;
    jgmenus)option="--checkout=jgmenus";;
    conky)option="--checkout=conky";;
    autoth)option="--checkout=autotheming";;
    applyto)option="--checkout=applyto";;
    *)option="";;
esac

## OPENBOX
out1+=("^tag(obox)")
out1+=("^sep($_OB_WD)")
[[ "${2}" == "obox" ]] && out1+=("${arrow_string_left} ${arrow_string_left} ${arrow_string_left}   $_GOBACK,^back()")

out1+=("^sep($SYSTEM_THEMES)" "^sep()")
n=1
while IFS="|" read -r abg abgto afg aline nbg nbgto nfg nline grad txtjust pheight pwidth handle bord bevel buttons fsize fname ndslimc weight slant scheme_name
do
((n=n+1))
out1+=("<big><span bgcolor='${abg}' fgcolor='${afg}'><span bgcolor='${abgto}'>   </span><small>   <tt>$(printf '%-20s' "${scheme_name}")</tt>   </small><span bgcolor='${abgto}'>   </span></span> <span bgcolor='${nbgto}'>  </span><span bgcolor='${nbg}' fgcolor='${nfg}'><small>  <tt><i>in</i></tt>  </small></span><span bgcolor='${nbgto}'>  </span></big>,obtctl applytheme sys ${n};$me obox" "^sep()")
done < <(tail -n +2 "$OB_SYSTHEMES")

# OB User themes
if [ "$(grep -c ^ $OB_USERTHEMES)" -gt "1" ];then
out1+=("^sep($YOUR_THEMES)" "^sep()")
n=1
while IFS="|" read -r abg abgto afg aline nbg nbgto nfg nline grad txtjust pheight pwidth handle bord bevel buttons fsize fname ndslimc weight slant scheme_name
do
((n=n+1))
out1+=("<big><span bgcolor='${abg}' fgcolor='${afg}'><span bgcolor='${abgto}'>   </span><small>   <tt>$(printf '%-20s' "${scheme_name}")</tt>   </small><span bgcolor='${abgto}'>   </span></span> <span bgcolor='${nbgto}'>  </span><span bgcolor='${nbg}' fgcolor='${nfg}'><small>  <tt><i>in</i></tt>  </small></span><span bgcolor='${nbgto}'>  </span></big>,obtctl applytheme usr ${n};$me obox" "^sep()")
done < <(tail -n +2 "$OB_USERTHEMES")
fi

out1+=("^sep($_GENERATE)")
out1+=("<big></big>   $RANDOMIZE,obtctl randomizer;$me obox")
out1+=("<big></big>   $MONOCHROMATIC,^checkout(monoch)")
out2+=("^tag(monoch)")
out2+=("^sep(<i>$CHOOSE_AND_PICK</i>)")
out2+=("<big></big>   $LIGHTBG...,obtctl mono pick light stylemenu")
out2+=("<big></big>   $DARKBG...,obtctl mono pick dark stylemenu")
out1+=("^sep(<i>$GENERATEFROMWP</i>)" "^sep()")
out1+=("<big></big>   <span bgcolor='${w[-2]}' fgcolor='#222222'>   <span bgcolor='${w[-4]}'>    </span>   $LIGHTBG   <span bgcolor='${w[-4]}'>    </span>   </span>,w2theme ob light;$me obox" "^sep()")
out1+=("<big></big>   <span bgcolor='${w[2]}' fgcolor='#E5E5E5'>   <span bgcolor='${w[4]}'>    </span>   $DARKBG    <span bgcolor='${w[4]}'>    </span>   </span>,w2theme ob dark;$me obox")
out1+=("^sep()")

out1+=("^sep($_MORE_OPTIONS)")
out1+=("^sep($_COLOR_TUNING)" "^sep($_SAVE_OWN)")
out1+=("$_USE <b>Colorizer OpenBox</b>,colorizer-ob -s")
[[ "${2}" == "obox" ]] && out1+=("^sep()" "${arrow_string_left} ${arrow_string_left} ${arrow_string_left}   $_GOBACK,^back()")



## JGMENUS
MENU_SYSSCHEMES="/usr/share/mabox-colorizer/colorschemes/menus.csv"
MENU_USERSCHEMES="$HOME/.config/colorizer/menus/userschemes2.csv"
JG_SYS_AMOUNT=$(cat $MENU_SYSSCHEMES |wc -l)
JG_USR_AMOUNT=$(cat $MENU_USERSCHEMES |wc -l)
out1+=("^tag(jgmenus)")
out1+=("^sep($_MENUPANELS)")
[[ "${2}" == "jgmenus" ]] && out1+=("${arrow_string_left} ${arrow_string_left} ${arrow_string_left}   $_GOBACK,^back()")
out1+=("^sep($_CHANGE_THEME)")
#out1+=("<big></big>   $SYSTEM_THEMES ($((JG_SYS_AMOUNT-1))),^checkout(jg_sys)")
#out2+=("^tag(jg_sys)")
#out2+=("^sep($_CLICK_TO_APPLY)")

n=1
    while IFS="|" read -r mbg mbga mbgt mbgta mborder mbordera tbg tbga tfg tfga tborder tbordera normbg normbga nfg nfga sbg sbga sfg sfga sborder sbordera sepfg sepfga b r p ss ibor irad a al sephal grad scheme_name
    do
    ((n=n+1))
    case "$grad" in
        none)icon="${cboff}";;
        top)icon="";;
        right)icon="";;
        bottom)icon="";;
        left)icon="";;
        top_left)icon="";;
        top_right)icon="";;
        bottom_left)icon="";;
        bottom_right)icon="";;
    esac
    out1+=("<big><span bgcolor='${mbg}' fgcolor='${nfg}'> <tt><small>$(printf '%-18s' "${scheme_name}")</small></tt><span bgcolor='${tbg}' fgcolor='${tfg}'> <small><b>title</b></small> </span> <span bgcolor='${sbg}' fgcolor='${sfg}'> <small>[ sel ]</small> </span>  <span bgcolor='${mbgt}'> <small>${icon}</small> </span></span></big>,jgctl applyscheme sys $n;$me jgmenus" "^sep()")
    done < <(tail -n +2 "$MENU_SYSSCHEMES")
 
# Menu User schemes
if [ "$(grep -c ^ $MENU_USERSCHEMES)" -gt "1" ];then
out1+=("^sep()")
out1+=("<big></big>   $YOUR_THEMES ($((JG_USR_AMOUNT-1))),^checkout(jg_usr)")
out2+=("^tag(jg_usr)")
out2+=("^sep($_CLICK_TO_APPLY)")
    n=1
    while IFS="|" read -r mbg mbga mbgt mbgta mborder mbordera tbg tbga tfg tfga tborder tbordera normbg normbga nfg nfga sbg sbga sfg sfga sborder sbordera sepfg sepfga b r p ss ibor irad a al sephal grad scheme_name
    do
    ((n=n+1))
    case "$grad" in
        none)icon="${cboff}";;
        top)icon="";;
        right)icon="";;
        bottom)icon="";;
        left)icon="";;
        top_left)icon="";;
        top_right)icon="";;
        bottom_left)icon="";;
        bottom_right)icon="";;
    esac
    out2+=("<big><span bgcolor='${mbg}' fgcolor='${nfg}'> <small><tt>$(printf '%-18s' "${scheme_name}")</tt></small><span bgcolor='${tbg}' bgalpha='${tbga}%' fgcolor='${tfg}'> <small><b>title</b></small> </span> <span bgcolor='${sbg}' bgalpha='${sbga}%' fgcolor='${sfg}'> <small>[ sel ]</small> </span> <span bgcolor='${mbgt}'> <small>${icon}</small> </span></span></big>,jgctl applyscheme usr ${n};$me jgmenus" "^sep()")
    done < <(tail -n +2 "$MENU_USERSCHEMES")   
fi

    out1+=("^sep($_GENERATE)")
    out1+=("<big></big>   $RANDOMIZE,jgctl randomscheme;$me jgmenus")
    out1+=("<big></big>   $MONOCHROMATIC,^checkout(monoch_menu)")
    out2+=("^tag(monoch_menu)")
    out2+=("^sep(<i>$CHOOSE_AND_PICK</i>)")
    out2+=("<big></big>   $EXACT...,jgctl mono pick exact stylemenu")
    out2+=("^sep()")
    out2+=("<big></big>   $LIGHTBG...,jgctl mono pick light stylemenu")
    out2+=("<big></big>   $DARKBG...,jgctl mono pick dark stylemenu")
    out1+=("^sep($GENERATEFROMWP)")
    out1+=("<big></big>  <span bgcolor='${w[-3]}'>   <span bgcolor='${w[-5]}'>   <span bgcolor='${w[-1]}' fgcolor='${w[1]}'>          </span>   </span>   </span>   $LIGHTBG,w2theme menu light;$me jgmenus")
    out1+=("<big></big>  <span bgcolor='${w[1]}'>   <span bgcolor='${w[4]}'>   <span bgcolor='${w[2]}' fgcolor='${w[-2]}'>          </span>   </span>   </span>   $DARKBG,w2theme menu dark;$me jgmenus")
    
out1+=("^sep($_MORE_OPTIONS)")
out1+=("^sep($_COLOR_TUNING)" "^sep($_SAVE_OWN)")
out1+=("$_USE <b>Colorizer Menu</b> module,colorizer-menus -s")

[[ "${2}" == "jgmenus" ]] && out1+=("^sep()" "${arrow_string_left} ${arrow_string_left} ${arrow_string_left}   $_GOBACK,^back()")


## CONKIES
out+=("^sep()")
out+=("<big></big>   $_COLORIZER_CONKY,colorizer-conky -s")




#out+=("^sep()")
#out+=("<big></big>   $_COLORIZER_FONTS,colorizer-fonts -s")
#out+=("^sep()")
#out+=("<big></big>   $_COLORIZER_PICOM,jgpicom-pipe -s")
out+=("^sep()")
#out+=("$_COLORIZER_HELP,ycolorizer")
out+=("<big></big>   $_COLORIZER_ROOT,colorizer -s")

fi # profile basic check end


### RUN
if [[ $1 == "-s" || $1 == "-c" || $1 == "-u" || $1 == "ipc" || $1 == "-d" ]]; then



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(Mabox Colorizer)")
    while read -r pid cmd; do
            if [[ ${cmd%% *} = tint2 ]]; then
                TINT=${cmd##* }
            if grep mb-t2wall $TINT; then
             #notify-send.sh "AAA" "Found"
            t2execp=true
            fi
            fi    
    done < <(pgrep -u $USER -a tint2)
    
    out+=("^sep($_PANEL_ICON_ACTIONS)")
    if [[ "${t2execp}" == "true" ]];then
    [[ "${wp_icon}" == "wide" ]] && out+=("<big>${cbon}</big>   $_WIDE_ICON,mb-setvar wp_icon=square $CONF_FILE;tint2-send refresh-execp mb-t2wall;${me}") || out+=("<big>${cboff}</big>    $_WIDE_ICON,mb-setvar wp_icon=wide $CONF_FILE;tint2-send refresh-execp mb-t2wall;${me}")
    out+=("^sep()")
    fi
    
	# left-click
    case $t2_button_lclick_action in
    random) out+=("󰳽  $_B_LC_ACTION 	<b>[ $_RAND ]</b>,^checkout(laction)");;
    randfav) out+=("󰳽  $_B_LC_ACTION 	<b>[ randfav ]</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)");;
    esac

    out2+=("^tag(laction)")
    out2+=("^sep($_P_B_LC_ACTION)")
    [[ "$t2_button_lclick_action" == "random" ]] && out2+=("<big>${ron}</big>   $_RANDOM_DESC") || out2+=("<big>${roff}</big>   $_RANDOM_DESC,mb-setvar t2_button_lclick_action=random $CONF_FILE")
    [[ "$t2_button_lclick_action" == "randfav" ]] && out2+=("<big>${ron}</big>   $_RANDOMFAV_DESC") || out2+=("<big>${roff}</big>   $_RANDOMFAV_DESC,mb-setvar t2_button_lclick_action=randfav $CONF_FILE")
    [[ "$t2_button_lclick_action" == "choose" ]] && out2+=("<big>${ron}</big>   $_CHOOSE_DESC") || out2+=("<big>${roff}</big>   $_CHOOSE_DESC,mb-setvar t2_button_lclick_action=choose $CONF_FILE")
    [[ "$t2_button_lclick_action" == "preview" ]] && out2+=("<big>${ron}</big>   $_PREVIEW_DESC") || out2+=("<big>${roff}</big>   $_PREVIEW_DESC,mb-setvar t2_button_lclick_action=preview $CONF_FILE")
    [[ "$t2_button_lclick_action" == "menu" ]] && out2+=("<big>${ron}</big>   $_WALL_MENU_DESC") || out2+=("<big>${roff}</big>   $_WALL_MENU_DESC,mb-setvar t2_button_lclick_action=menu $CONF_FILE")
    [[ "$t2_button_lclick_action" == "slideshow" ]] && out2+=("<big>${ron}</big>   $_SLIDESHOW_DESC") || out2+=("<big>${roff}</big>   $_SLIDESHOW_DESC,mb-setvar t2_button_lclick_action=slideshow $CONF_FILE")
    out2+=("^sep()")
    [[ "$t2_button_lclick_action" == "window" ]] && out2+=("<big>${ron}</big>   $_COL_WINDOW_DESC") || out2+=("<big>${roff}</big>   $_COL_WINDOW_DESC,mb-setvar t2_button_lclick_action=window $CONF_FILE")
    [[ "$t2_button_lclick_action" == "colmenu" ]] && out2+=("<big>${ron}</big>   $_COL_MENU_DESC") || out2+=("<big>${roff}</big>   $_COL_MENU_DESC,mb-setvar t2_button_lclick_action=colmenu $CONF_FILE")
    
    
    if [[ "${t2execp}" == "true" ]];then
    #wheel-up
    t2_button_wheelup_action=${t2_button_wheelup_action:-show-desk}
    case $t2_button_wheelup_action in
    show-desk) out+=("󱕑 $_B_WU_ACTION 	<b>[ $_SHOW_DESK ]</b>,^checkout(wuaction)");;
    win-switch) out+=("󱕑 $_B_WU_ACTION 	<b>[ $_WIN_SWITCH ]</b>,^checkout(wuaction)");;
    desk-switch) out+=("󱕑 $_B_WU_ACTION 	<b>[ $_DESK_SWITCH ]</b>,^checkout(wuaction)");;
    win-next) out+=("󱕑 $_B_WU_ACTION 	<b>[ $_WIN_NEXT ]</b>,^checkout(wuaction)");;
    win-prev) out+=("󱕑 $_B_WU_ACTION 	<b>[ $_WIN_PREV ]</b>,^checkout(wuaction)");;
    random) out+=("󱕑 $_B_WU_ACTION 	<b>[ $_RAND ]</b>,^checkout(wuaction)");;
    esac
    out2+=("^tag(wuaction)")
    out2+=("^sep($_P_B_WU_ACTION)")
    [[ "$t2_button_wheelup_action" == "show-desk" ]] && out2+=("<big>${ron}</big>   $_SHOW_DESK_DESC") || out2+=("<big>${roff}</big>   $_SHOW_DESK_DESC,mb-setvar t2_button_wheelup_action=show-desk $CONF_FILE")
    [[ "$t2_button_wheelup_action" == "random" ]] && out2+=("<big>${ron}</big>   $_RANDOM_DESC") || out2+=("<big>${roff}</big>   $_RANDOM_DESC,mb-setvar t2_button_wheelup_action=random $CONF_FILE")
    [[ "$t2_button_wheelup_action" == "win-switch" ]] && out2+=("<big>${ron}</big>   $_WIN_SWITCH_DESC") || out2+=("<big>${roff}</big>   $_WIN_SWITCH_DESC,mb-setvar t2_button_wheelup_action=win-switch $CONF_FILE")
    [[ "$t2_button_wheelup_action" == "desk-switch" ]] && out2+=("<big>${ron}</big>   $_DESK_SWITCH_DESC") || out2+=("<big>${roff}</big>   $_DESK_SWITCH_DESC,mb-setvar t2_button_wheelup_action=desk-switch $CONF_FILE")
    # buggy skippy-xd or openbox bug
    #[[ "$t2_button_wheelup_action" == "win-next" ]] && out2+=("<big>${ron}</big>   $_WIN_NEXT_DESC") || out2+=("<big>${roff}</big>   $_WIN_NEXT_DESC,mb-setvar t2_button_wheelup_action=win-next $CONF_FILE")
    #[[ "$t2_button_wheelup_action" == "win-prev" ]] && out2+=("<big>${ron}</big>   $_WIN_PREV_DESC") || out2+=("<big>${roff}</big>   $_WIN_PREV_DESC,mb-setvar t2_button_wheelup_action=win-prev $CONF_FILE")
    
    #wheel-down
    t2_button_wheeldown_action=${t2_button_wheeldown_action:-show-desk}
    case $t2_button_wheeldown_action in
    show-desk) out+=("󱕐 $_B_WD_ACTION 	<b>[ $_SHOW_DESK ]</b>,^checkout(wdaction)");;
    win-switch) out+=("󱕐 $_B_WD_ACTION 	<b>[ $_WIN_SWITCH ]</b>,^checkout(wdaction)");;
    desk-switch) out+=("󱕐 $_B_WD_ACTION 	<b>[ $_DESK_SWITCH ]</b>,^checkout(wdaction)");;
    win-next) out+=("󱕑 $_B_WD_ACTION 	<b>[ $_WIN_NEXT ]</b>,^checkout(wdaction)");;
    win-prev) out+=("󱕑 $_B_WD_ACTION 	<b>[ $_WIN_PREV ]</b>,^checkout(wdaction)");;
    random) out+=("󱕐 $_B_WD_ACTION 	<b>[ $_RAND ]</b>,^checkout(wdaction)");;
    esac
    out2+=("^tag(wdaction)")
    out2+=("^sep($_P_B_WD_ACTION)")
    [[ "$t2_button_wheeldown_action" == "show-desk" ]] && out2+=("<big>${ron}</big>   $_SHOW_DESK_DESC") || out2+=("<big>${roff}</big>   $_SHOW_DESK_DESC,mb-setvar t2_button_wheeldown_action=show-desk $CONF_FILE")
    [[ "$t2_button_wheeldown_action" == "random" ]] && out2+=("<big>${ron}</big>   $_RANDOM_DESC") || out2+=("<big>${roff}</big>   $_RANDOM_DESC,mb-setvar t2_button_wheeldown_action=random $CONF_FILE")
    [[ "$t2_button_wheeldown_action" == "win-switch" ]] && out2+=("<big>${ron}</big>   $_WIN_SWITCH_DESC") || out2+=("<big>${roff}</big>   $_WIN_SWITCH_DESC,mb-setvar t2_button_wheeldown_action=win-switch $CONF_FILE")
    [[ "$t2_button_wheeldown_action" == "desk-switch" ]] && out2+=("<big>${ron}</big>   $_DESK_SWITCH_DESC") || out2+=("<big>${roff}</big>   $_DESK_SWITCH_DESC,mb-setvar t2_button_wheeldown_action=desk-switch $CONF_FILE")
    #[[ "$t2_button_wheeldown_action" == "win-next" ]] && out2+=("<big>${ron}</big>   $_WIN_NEXT_DESC") || out2+=("<big>${roff}</big>   $_WIN_NEXT_DESC,mb-setvar t2_button_wheeldown_action=win-next $CONF_FILE")
    #[[ "$t2_button_wheeldown_action" == "win-prev" ]] && out2+=("<big>${ron}</big>   $_WIN_PREV_DESC") || out2+=("<big>${roff}</big>   $_WIN_PREV_DESC,mb-setvar t2_button_wheeldown_action=win-prev $CONF_FILE")
    fi
    
    ;;
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))

    # colors on image
    n=0
    m=0
    X=$((jgtools_padding + 6))
    Y=$((jgtools_padding + 122))
    for i in "${w[@]}"
    do
    #if [[ "$n" -lt "13" ]];then
    #dots+=("@rect,,$((X + 20*n)),$((Y)),18,18,1,left,top,#FFFFFF 80,${i} 100,")
    #else
    #dots+=("@rect,,$((X + 20*m)),$((Y+20)),18,18,1,left,top,#FFFFFF 80,${i} 100,")
    if [[ "$n" -lt "13" ]];then
    dots+=("@rect,,$((X + 21*n)),$((Y)),22,22,0,left,top,#CCCCCC 100,${i} 100,")
    else
    :
    #dots+=("@rect,,$((X + 21*m)),$((Y+24)),22,22,0,left,top,#CCCCCC 100,${i} 100,")
    #((m=m+1))
    fi
    ((n=n+1))
    done
    
    
   #TEMP POSITION:
    MENU_VALIGN="top"
    MENU_MARGIN_Y="80"

mkconfigfile
echo menu_height_mode=dynamic >> ${CONFIG_FILE}

if [[ "$wall2themes" == "yes" ]]; then
AUTOTHEME_IND="
@rect,,$((jgtools_padding+4)),$((jgtools_padding + 6)),262,20,0,left,top,#222222 20,#222222 70,
@text,,$((jgtools_padding+8)),$((jgtools_padding + 6)),262,22,0,left,top,#FFFFFF,#222222 70, <span fgcolor='white'><big>${cbon}</big> </span> Auto theming <b><i>$_ENABLED</i></b> !
"
fi

cat <<EOF > ${MENU_ITEMS}
@icon,,$((jgtools_padding )),$((jgtools_padding)),270,150,4,left,top,,,${THUMB}
${AUTOTHEME_IND}
@rect,,$((jgtools_padding+4)),$((jgtools_padding + 94)),262,32,0,left,top,#222222 20,#222222 70,
#@text,,$((jgtools_padding + 196)),$((jgtools_padding + 22)),100,28,0,left,top,#222222 30,${WINCLR},<span size='41600' font_family='Ubuntu'><big></big></span>
#@text,,$((jgtools_padding + 194)),$((jgtools_padding + 20)),100,28,0,left,top,#FFFFFF 45,${WINCLR},<span size='41600' font_family='Ubuntu'><big></big></span>
@text,,$((jgtools_padding + 14)),$((jgtools_padding + 94)),180,28,0,left,top,#FFFFFF ,${WINCLR},<span size='10400' font_family='Ubuntu'>$_TITLE</span>
$(printf '%s\n' "${dots[@]}")
$(printf '%s\n' "${out[@]}")
$(printf '%s\n' "${out1[@]}")
$(printf '%s\n' "${out2[@]}")
$(printf '%s\n' "${out3[@]}")
EOF

jgmenu --config-file=${CONFIG_FILE} --csv-file=${MENU_ITEMS} ${option} 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[@]}"
printf '%s\n' "${out3[@]}"
}

icon(){
if [[ "${wp_icon}" == "square" ]];then
echo "$HOME/.config/mabox/wpicon.png"
else
echo "$HOME/.config/mabox/wpicon_wide.png"
fi
}
addfav(){
FAVWP="$HOME/.config/mabox/wp_fav.csv"
#notify-send.sh "WP" "$1"
case $LANG in
	pl*)
	TITLE="Dodaj do Ulubionych"
	TEXT="Nazwa dla tapety"
	LBL="Nazwa"
	;;
	*)
	TITLE="Add to favorites"
	TEXT="Set name/label for wallpaper"
	LBL="Name"
	;;
esac
wp="${1/$HOME/\~}"
LABEL=$(yad --window-icon=emote-love --title="$TITLE" --center --width=300 --text-align=center --text="$TEXT" --entry --entry-label="$LBL")
if [[ "${LABEL}" != "" ]];then
echo "${LABEL},${wp}">> "${FAVWP}"
fi
}
randomfav(){
favs="$(wc -l $FAVWP| awk '{print $1}')"
if [[ "$favs" -gt 3 ]];then
IFS=, read name randwp <<< "$(tail --lines=+3 ${FAVWP} |shuf -n 1)"
randwp="${randwp//\~/$HOME}"
#notify-send.sh "random" "$name $randwp"
nitrogen --set-scaled --save $randwp
else
mbwallpaper -o
fi
}
remfav(){
sd ".*$1\n" '' ${FAVWP}
sleep 1
randomfav
}

case "$1" in
    lclick) lclick;;
    wheelup) wheelup;;
    wheeldown) wheeldown;;
    icon) icon;;
    addfav)addfav "$2";;
    randomfav)randomfav "$2";;
    remfav)remfav "$2";;
    *) main "$@";;
esac
