#!/bin/bash

# Dynamic menu - helper to configure tint2 panels

# Favorited fonts list
if [ -f "$HOME/.config/mabox/fonts.list" ];then
	mapfile -t favfonts < <( grep -vE "^($|#)" ~/.config/mabox/fonts.list)
else
	mapfile -t favfonts < <( grep -vE "^($|#)" /usr/share/mabox-colorizer/fonts.list)
	cp /usr/share/mabox-colorizer/fonts.list ~/.config/mabox/
fi

TINT2PATH="$HOME/.config/tint2"
TINT2RC="$TINT2PATH/tint2rc"
TZEN="mb-tint2-manager"

me="jgtint2-pipe -s"

. /usr/share/mb-jgtools/jgtools.inc

case $LANG in
    pl*)
    LNG="pl"
    TITLE="Konfiguracja Panelu"
    PANEL="Panel"
    _FLOATING_PANEL="Pływający panel"
    _LOGO="Kolorowalne Logo"
    POSITION="Pozycja"
    SIZE="Rozmiar"
    WIDTH="Szerokość"
    HEIGHT="Wysokość"
    MARGIN="Margines"
    PADDING="Odstęp"
    COMPACT="Kompaktowy ?"
    AUTOHIDE="Autoukrywanie ?"
    SIZEHIDDEN="Rozmiar gdy ukryty"
    _FONTS="Czcionki"
    _TASK_FONT="Zadania"
    _TASKBARNAME_FONT="Numer pulpitu"
    _EDIT_FAVFONTS="Edytuj ulubione czcionki"
    ICONS="Ikony"
    CLOCK="Zegar"
    CLOCK_LINE1="Zegar linia 1"
    CLOCK_LINE2="Zegar linia 2"
    NONE="brak"
    TASKBAR="Pasek zadań i przyciski"
    _TASKBAR_NAME="Pokaż nazwę pulpitu (numer)"
    _DISTR_SIZE="Podziel przestrzeń między paskami zadań"
    _TASKS_ALIGNMENT="Wyrównanie zadań do"
    MOUSE_EVENTS="Akcje myszy"
    RESETMOUSE="Przywróć domyślne"
    MOUSE_LEFT="Lewy klik"
    MOUSE_RIGHT="Prawy klik"
    MOUSE_MIDDLE="Środkowy klik"
    MOUSE_UP="Kółko Góra"
    MOUSE_DOWN="Kółko Dół"
    _DESKTOPS="<b>Pulpity</b> (obszary robocze)"
    _ADD_DESKTOP="<b>Dodaj</b> pulpit"
    _REMOVE_LAST="<b>Usuń ostatni</b> pulpit"
    APPEARANCE="Wygląd przycisków"
    SHOW_BOTH="Ikony i tekst"
    SHOW_ICON="Ikony"
    SHOW_TEXT="Tekst"
    CENTER_TEXT="Tekst wycentrowany"
    BUTTON_WIDTH="Wielkość przycisku"
    FILL="Wypełnij pasek zadań"
    FITICON="Jak ikony"
    TOOLTIPS="Podpowiedzi..."
    TOOLTIPS_NONE="Nie pokazuj"
    SHOW_TOOLTIPS="Podpowiedzi"
    THUMBNAILS="Podpowiedz i Miniaturki"
    RESET="Resetuj panel"
    TOP="Góra"
    BOTTOM="Dół"
    TOPLEFT="Góra po lewej"
    TOPRIGHT="Góra po prawej"
    LEFT="Lewa"
    RIGHT="Prawa"
    BOTTOMLEFT="Dół po lewej"
    BOTTOMRIGHT="Dół po prawej"
    HORIZONTAL="Poziomo"
    VERTICAL="Pionowo"
    SPACING="Odstęp"
    YES="Tak"
    NO="Nie"
    RUNNING_TINT2="Działające Tint2"
    DEFAULT_TINT2RC="Domyślny tint2rc"
    ADVANCED="Zaawansowane..."
    EDIT_TINT2="Edytuj plik konfiguracyjny"
    APPS="Programy (Launcher)"
    LAUNCHERS="Dodaj/usuń programy..."
    TINT2_EDITOR="Wybierz pliki Tint2 do edycji..."
    TINT2_CONFIGURE="Konfiguracja panelu tint2"
    _CHOOSE_TINT2="Wybierz konfigurację panelu..."
    _PANEL_CONFIGS="Dostępne panele"
    _OPEN_CFG_DIR="Otwórz katalog z konfiguracjami"
    RESTART_TINT2="Restartuj Panel"
    RELOAD_TINT2="Przeładuj Panel"
    CONFIGURE="Konfiguruj (GUI)"
    REMOVE="Usuń to menu z panelu"
    TRAY_HWMON="Monitor zasobów w trayu"
    START="Uruchom/Włącz"
    STOP="Zatrzymaj/Wyłącz"
    MEM="Pamięć"
    NET="Użycie sieci"
    DISC_IO="IO Dysku"
        ;;
    es*)
    LNG="en"
    TITLE="Panel Tint2"
    PANEL="Panel"
    _FLOATING_PANEL="Floating panel"
    _LOGO="Colorable Logo"
    POSITION="Position"
    SIZE="Size"
    WIDTH="Width"
    HEIGHT="Height"
    MARGIN="Margin"
    PADDING="Padding"
    COMPACT="Compact?"
    AUTOHIDE="Autohide?"
    SIZEHIDDEN="Size when hidden:"
    _FONTS="Fonts"
    _TASK_FONT="Task font"
    _TASKBARNAME_FONT="Taskbar name font"
    _EDIT_FAVFONTS="Edit favorite fonts list"
    ICONS="Icon theme"
    CLOCK="Clock"
    CLOCK_LINE1="Clock line 1"
    CLOCK_LINE2="Clock line 2"
    NONE="none"
    TASKBAR="Taskbar"
    _TASKBAR_NAME="Show taskbar name (number)"
    _DISTR_SIZE="Distribute size between taskbars"
    _TASKS_ALIGNMENT="Task alignment"
    MOUSE_EVENTS="Mouse events"
    MOUSE_EVENTS="Mouse events"
    RESETMOUSE="Reset to defaults"
    MOUSE_LEFT="Left click"
    MOUSE_RIGHT="Right click"
    MOUSE_MIDDLE="Middle click"
    MOUSE_UP="Wheel Up"
    MOUSE_DOWN="Wheel Down"
    _DESKTOPS="<b>Desktops</b> (workspaces)"
    _ADD_DESKTOP="<b>Add new</b> desktop"
    _REMOVE_LAST="<b>Remove last</b> desktop"
    APPEARANCE="Buttons Appearance"
    SHOW_BOTH="Icons and text"
    SHOW_ICON="Show icon"
    SHOW_TEXT="Show text"
    CENTER_TEXT="Center text"
    BUTTON_WIDTH="Button width"
    FILL="Fill taskbar"
    FITICON="Fit icon size"
    TOOLTIPS_NONE="None"
    TOOLTIPS="Tooltips..."
    SHOW_TOOLTIPS="Show tooltips"
    THUMBNAILS="Thumbnails"
    RESET="Reset panel to defaults"
    TOP="Top"
    BOTTOM="Bottom"
    TOPLEFT="TopLeft"
    TOPRIGHT="TopRight"
    LEFT="Left"
    RIGHT="Right"
    BOTTOMLEFT="BottomLeft"
    BOTTOMRIGHT="BottomRight"
    HORIZONTAL="Horizontal"
    VERTICAL="Vertical"
    SPACING="Spacing"
    YES="Yes"
    NO="No"
    RUNNING_TINT2="Panel(es) en ejecución"
    DEFAULT_TINT2RC="Panel tint2rc x defecto"
    ADVANCED="Advanced..."
    EDIT_TINT2="Edición manual panel"
    APPS="Launchers"
    LAUNCHERS="Add/Remove Launchers..."
    TINT2_EDITOR="Elegir panel Tint2 a editar"
    TINT2_CONFIGURE="Editor gráfico"
    _CHOOSE_TINT2="Elegir un panel..."
    _PANEL_CONFIGS="Available Configurations"
    _OPEN_CFG_DIR="Open config dir"
    RESTART_TINT2="Reiniciar panel"
    RELOAD_TINT2="Reload panel"
    CONFIGURE="Editor gráfico"
    REMOVE="Eliminar este menú del panel"
    TRAY_HWMON="Systray HW monitor"
    START="Start/Enable"
    STOP="Stop/Disable"
    MEM="Memory"
    NET="Network usage"
    DISC_IO="Disc IO"
    ;;
    *)
    LNG="en"
    TITLE="Configure Panel"
    PANEL="Panel"
    _FLOATING_PANEL="Floating panel"
    _LOGO="Colorable Logo"
    POSITION="Position"
    SIZE="Size"
    WIDTH="Width"
    HEIGHT="Height"
    MARGIN="Margin"
    PADDING="Padding"
    COMPACT="Compact?"
    AUTOHIDE="Autohide?"
    SIZEHIDDEN="Size when hidden:"
    _FONTS="Fonts"
    _TASK_FONT="Task"
    _TASKBARNAME_FONT="Taskbar name"
    _EDIT_FAVFONTS="Edit favorite fonts list"
    ICONS="Icon theme"
    CLOCK="Clock"
    CLOCK_LINE1="Clock line 1"
    CLOCK_LINE2="Clock line 2"
    NONE="none"
    TASKBAR="Taskbar"
    _TASKBAR_NAME="Show taskbar name (number)"
    _DISTR_SIZE="Distribute size between taskbars"
    _TASKS_ALIGNMENT="Task alignment"
    MOUSE_EVENTS="Mouse events"
    RESETMOUSE="Reset to defaults"
    MOUSE_LEFT="Left click"
    MOUSE_RIGHT="Right click"
    MOUSE_MIDDLE="Middle click"
    MOUSE_UP="Wheel Up"
    MOUSE_DOWN="Wheel Down"
    _DESKTOPS="<b>Desktops</b> (workspaces)"
    _ADD_DESKTOP="<b>Add new</b> desktop"
    _REMOVE_LAST="<b>Remove last</b> desktop"
    APPEARANCE="Buttons Appearance"
    SHOW_BOTH="Icons and text"
    SHOW_ICON="Icon only"
    SHOW_TEXT="Text only"
    CENTER_TEXT="Centered"
    BUTTON_WIDTH="Button width"
    FILL="Fill taskbar"
    FITICON="Fit icon size"
    TOOLTIPS="Tooltips..."
    TOOLTIPS_NONE="None"
    SHOW_TOOLTIPS="Only tooltips"
    THUMBNAILS="Tooltips and Thumbnails"
    RESET="Reset panel to defaults"
    TOP="Top"
    BOTTOM="Bottom"
    TOPLEFT="TopLeft"
    TOPRIGHT="TopRight"
    LEFT="Left"
    RIGHT="Right"
    BOTTOMLEFT="BottomLeft"
    BOTTOMRIGHT="BottomRight"
    HORIZONTAL="Horizontal"
    VERTICAL="Vertical"
    SPACING="Spacing"
    YES="Yes"
    NO="No"
    RUNNING_TINT2="Running Tint2"
    DEFAULT_TINT2RC="Default tint2rc"
    ADVANCED="Advanced..."
    EDIT_TINT2="Edit config file"
    APPS="Launchers"
    LAUNCHERS="Add/Remove Launchers..."
    TINT2_EDITOR="Choose Tint2 to edit"
    TINT2_CONFIGURE="Configure tint2 panel"
    _CHOOSE_TINT2="Choose Panel config..."
    RESTART_TINT2="Restart Panel"
    RELOAD_TINT2="Reload Panel"
    _PANEL_CONFIGS="Available Configurations"
    _OPEN_CFG_DIR="Open config dir"
    CONFIGURE="Configure (GUI)"
    REMOVE="Remove this menu from panel"
    TRAY_HWMON="Systray HW monitor"
    START="Start/Enable"
    STOP="Stop/Disable"
    MEM="Memory"
    NET="Network usage"
    DISC_IO="Disc IO"
    ;;
esac
getvalues () {
    read VE HO OR <<< "$(grep panel_position ${TINT} | cut -d'=' -f2)"
    read W H <<< "$(grep panel_size ${TINT} | cut -d'=' -f2)"
    read HOR VERT <<< "$(grep panel_margin ${TINT} | cut -d'=' -f2)"
    read PHOR PVERT SPACE <<< "$(grep panel_padding ${TINT} | cut -d'=' -f2)"
    read SHRINK <<< "$(grep panel_shrink ${TINT} | cut -d'=' -f2)"
    read HIDE <<< "$(grep "autohide " ${TINT} | cut -d'=' -f2)"
    read ICONTHEME <<< "$(grep "launcher_icon_theme" ${TINT} | cut -d'=' -f2)"
    read PANELITEMS <<< "$(grep "panel_items" ${TINT} | cut -d'=' -f2)"
    [[ "$OR" == "horizontal" ]] && WIDTH=${HEIGHT}
}

qactions () {
				if grep -q "icons/mabox-logo-" ${TINT} 2>/dev/null;then
                read LOGO <<< "$(grep icons/mabox-logo- ${TINT} | cut -d'/' -f3)"
                [[ "${LOGO}" == "mabox-logo-square.svg" ]] && out+=("<big>${cbon}</big>   $_LOGO,t2ctl logo default ${TINT};$me") || out+=("<big>${cboff}</big>   $_LOGO,t2ctl logo color ${TINT};$me")
                fi
                [[ "$HOR" -gt 1 ]] && out+=("<big>${cbon}</big>   $_FLOATING_PANEL,t2ctl postype edge ${TINT};$me") || out+=("<big>${cboff}</big>   $_FLOATING_PANEL,t2ctl postype float ${TINT};$me")
                #out+=("<tt>$(printf "%-20s %20s" "$POSITION" "[ <b>$VE $HO</b> ]")</tt>,^checkout(ppos$i)")
                #out+=("<tt>$(printf "%-20s %20s" "$SIZE" "[ <b>$W</b> ]")</tt>,^checkout(pwidth$i)")
                #out+=("<tt>$(printf "%-20s %20s" "$WIDTH" "[ <b>$H</b> ]")</tt>,^checkout(pheight$i)")
                #out+=("<tt>$(printf "%-20s %20s" "$MARGIN" "[ <b>$HOR $VERT</b> ]")</tt>,^checkout(pmargin$i)")
                #out+=("<tt>$(printf "%-20s %20s" "$PADDING" "[ <b>$PHOR $PVERT $SPACE</b> ]")</tt>,^checkout(ppadding$i)")
                #[[ "$HIDE" == 0 ]] && out+=("<big>${cboff}</big>  <tt>$(printf "%-20s %20s" "$AUTOHIDE" "")</tt>,^checkout(phide$i)") || out+=("<big>${cbon}</big>  <tt>$(printf "%-20s %20s" "$AUTOHIDE" "")</tt>,^checkout(phide$i)")
                #out+=("^sep()")
                out+=("$POSITION	[ <b>$VE $HO</b> ],^checkout(ppos$i)")
                out+=("$SIZE	[ <b>$W</b> ],^checkout(pwidth$i)")
                out+=("$WIDTH	[ <b>$H</b> ],^checkout(pheight$i)")
                out+=("$MARGIN	[ <b>$HOR $VERT</b> ],^checkout(pmargin$i)")
                out+=("$PADDING	[ <b>$PHOR $PVERT $SPACE</b> ],^checkout(ppadding$i)")
                [[ "$HIDE" == 0 ]] && out+=("<big>${cboff}</big>  $AUTOHIDE,^checkout(phide$i)") || out+=("<big>${cbon}</big>  $AUTOHIDE,^checkout(phide$i)")
                out+=("^sep()")             
                
                out+=("$ICONS 	[ <b>$ICONTHEME</b> ],^checkout(iconthemes$i)")
                # Clock
                #if [[ "$PANELITEMS" == *C* ]]; then
                #read TF1 <<< "$(grep "time1_format" ${TINT} | cut -d'=' -f2)"
                #read TF2 <<< "$(grep "time2_format" ${TINT} | cut -d'=' -f2)"
                
                #out+=("^sep($CLOCK)")
                #out+=("$CLOCK_LINE1 [ <b> $(date "+${TF1}") </b> ],^checkout(cl1$i)")
                #out+=("$CLOCK_LINE2 [ <b> $(date "+${TF2}") </b> ],^checkout(cl2$i)")
                #out2+=("^tag(cl1$i)")
                #out2+=("^sep($CLOCK_LINE1)")
                #out2+=("<b>$(date +"%H:%M")</b> <small>(%H:%M)</small>,t2ctl clockline1 '%H:%M' ${TINT};$me")
                #out2+=("<b>$(date +"%I:%M %p")</b> <small>(%I:%M %p)</small>,t2ctl clockline1 '%I:%M %p' ${TINT};$me")
                #out2+=("<b>$(date +"%-I:%M %p")</b> <small>(%I-:%M %p)</small>,t2ctl clockline1 '%-I:%M %p' ${TINT};$me")
                #out2+=("<b>$(date +"%H:%M:%S")</b> <small>(%H:%M:%S)</small>,t2ctl clockline1 '%H:%M:%S' ${TINT};$me")
                #out2+=("<b>$(date +"%H:%M (%a)")</b> <small>(%H:%M (%a))</small>,t2ctl clockline1 '%H:%M (%a)' ${TINT};$me")
                
                #out2+=("^tag(cl2$i)")
                #out2+=("^sep($CLOCK_LINE2)")
                #out2+=("$NONE,t2ctl clockline2 none ${TINT};$me")
                #out2+=("^sep()")
                #out2+=("<b>$(date +"%A %d %B")</b> <small>(%A %d %B)</small>,t2ctl clockline2 '%A %d %B' ${TINT};$me")
                #out2+=("<b>$(date +"%a %d %b")</b> <small>(%a %d %b)</small>,t2ctl clockline2 '%a %d %b' ${TINT};$me")
                #out2+=("<b>$(date +"%x")</b> <small>(%x)</small>,t2ctl clockline2 '%x' ${TINT};$me")
                #out2+=("<b>$(date +"%m-%d-%Y")</b> <small>(%m-%d-%Y)</small>,t2ctl clockline2 '%m-%d-%Y' ${TINT};$me")
                #out2+=("<b>$(date +"%F")</b> <small>(%F)</small>,t2ctl clockline2 '%F' ${TINT};$me")
                #out2+=("<b>$(date +"%e.%m.%y")</b> <small>(%e.%m.%y)</small>,t2ctl clockline2 '%e.%m.%y' ${TINT};$me")
                #fi
                # END Clock
                # Taskbar
                if [[ "$PANELITEMS" == *T* ]]; then
                read TEXT <<< "$(grep task_text ${TINT} | cut -d'=' -f2)"
                read ICON <<< "$(grep 'task_icon ' ${TINT} | cut -d'=' -f2)"
                read CENTERED <<< "$(grep 'task_centered' ${TINT} | cut -d'=' -f2)"
                read TOOLTIP <<< "$(grep 'task_tooltip' ${TINT} | cut -d'=' -f2)"
                read THUMBNAIL <<< "$(grep 'task_thumbnail' ${TINT} | cut -d'=' -f2)"
                read TB_WIDTH TB_HEIGHT <<< "$(grep 'task_maximum_size' ${TINT} | cut -d'=' -f2)"
                read MLEFT <<< "$(grep 'mouse_left' ${TINT} | cut -d'=' -f2)"
                read MMIDDLE <<< "$(grep 'mouse_middle' ${TINT} | cut -d'=' -f2)"
                read MRIGHT <<< "$(grep 'mouse_right' ${TINT} | cut -d'=' -f2)"
                read MUP <<< "$(grep 'mouse_scroll_up' ${TINT} | cut -d'=' -f2)"
                read MDOWN <<< "$(grep 'mouse_scroll_down' ${TINT} | cut -d'=' -f2)"
                read TASK_ALIGN <<< "$(grep 'task_align' ${TINT} | cut -d'=' -f2)"
                read TASKBAR_NAME <<< "$(grep 'taskbar_name' ${TINT} | cut -d'=' -f2)"
                read DISTR_SIZE <<< "$(grep 'taskbar_distribute_size' ${TINT} | cut -d'=' -f2)"
                IFS=' ' read -r -a TASK_FONT <<< "$(grep '.*task_font ' ${TINT} | cut -d"=" -f2)"
                ## TASK FONT FAMILY and SIZE
				TASK_FSIZE="${TASK_FONT[-1]}"
				TASK_FFAMILY="${TASK_FONT[@]::${#TASK_FONT[@]}-1}"
				IFS=' ' read -r -a TNAME_FONT <<< "$(grep '.*taskbar_name_font ' ${TINT} | cut -d"=" -f2)"
				## TASKBAR NAME FONT FAMILY and SIZE
				TNAME_FSIZE="${TNAME_FONT[-1]}"
				TNAME_FFAMILY="${TNAME_FONT[@]::${#TNAME_FONT[@]}-1}"
                
                out+=("^sep($TASKBAR)")

                
                out+=("$APPEARANCE,^checkout(taskappearance$i)")
                
                out+=("$_TASKS_ALIGNMENT 	[ <b>$TASK_ALIGN</b> ],^checkout(talign)")
                out2+=("^tag(talign)")
                out2+=("^sep($_TASKS_ALIGNMENT)")
                for al in left center right;do
                [[ "$TASK_ALIGN" == "$al" ]] && out2+=("<big>${ron}</big>   <b>$al</b>,$me") || out2+=("<big>${roff}</big>   $al,t2ctl tasks_align $al ${TINT};$me")
                done
                [[ "$TASKBAR_NAME" == 1 ]] && out+=("<big>${cbon}</big>  $_TASKBAR_NAME,t2ctl taskbar_name 0 ${TINT};$me") || out+=("<big>${cboff}</big>  $_TASKBAR_NAME,t2ctl taskbar_name 1 ${TINT};$me")
                [[ "$DISTR_SIZE" == 1 ]] && out+=("<big>${cbon}</big>  $_DISTR_SIZE,t2ctl taskbar_distribute_size 0 ${TINT};$me") || out+=("<big>${cboff}</big>  $_DISTR_SIZE,t2ctl taskbar_distribute_size 1 ${TINT};$me")
                
                ### FONTS
                [[ "$TEXT" == 1 ]] && out+=("<big></big>   $_TASK_FONT:	[ <b>${TASK_FFAMILY} ${TASK_FSIZE}</b> ],^checkout(taskfont$i)")
                [[ "$TASKBAR_NAME" == 1 ]] && out+=("<big></big>   $_TASKBARNAME_FONT:	[ <b>${TNAME_FFAMILY} ${TNAME_FSIZE}</b> ],^checkout(tnamefont$i)")
                
                out2+=("^tag(taskfont$i)")
                out2+=("^sep($_TASK_FONT)")
                out2+=("^sep(size)")
                sizes=(12 11 10 9 8)
				for n in "${sizes[@]}"
				do
				[[ "$TASK_FSIZE" == "$n" ]] && out2+=("<big>${ron}</big>  <b>$n px</b>,$me") || out2+=("<big>${roff}</big>  $n px,t2ctl task_fontsize $n ${TINT};$me")
				done
                if [ "${#favfonts[@]}" -gt 0 ];then
                out2+=("^sep(family)")
				for fon in "${favfonts[@]}";do
				[[ "$TASK_FFAMILY" == "$fon" ]] && out2+=("<big>${ron}</big>  <span font_family=\"${fon}\">${fon}</span>,$me") || out2+=("<big>${roff}</big>  <span font_family=\"${fon}\">${fon}</span>,t2ctl task_fontfamily \"${fon}\" ${TINT};$me")
				done
				out2+=("^sep()")
				out2+=("<small>   $_EDIT_FAVFONTS </small>,geany ~/.config/mabox/fonts.list")
				fi
                
                out2+=("^tag(tnamefont$i)")
                out2+=("^sep($_TASKBARNAME_FONT)")
                out2+=("^sep(size)")
                for n in "${sizes[@]}"
				do
				[[ "$TNAME_FSIZE" == "$n" ]] && out2+=("<big>${ron}</big>  <b>$n px</b>,$me") || out2+=("<big>${roff}</big>  $n px,t2ctl taskbar_name_fontsize $n ${TINT};$me")
				done
				if [ "${#favfonts[@]}" -gt 0 ];then
                out2+=("^sep(family)")
                for fon in "${favfonts[@]}";do
				[[ "$TNAME_FFAMILY" == "$fon" ]] && out2+=("<big>${ron}</big>  <span font_family=\"${fon}\">${fon}</span>,$me") || out2+=("<big>${roff}</big>  <span font_family=\"${fon}\">${fon}</span>,t2ctl taskbar_name_fontfamily \"${fon}\" ${TINT};$me")
				done
				out2+=("^sep()")
				out2+=("<small>   $_EDIT_FAVFONTS </small>,geany ~/.config/mabox/fonts.list")
				fi
                ### END FONTS
                
                out+=("<big>󱕒</big>  $MOUSE_EVENTS,^checkout(mouseevents$i)")
                mouseactions=(none close toggle iconify shade toggle_iconify maximize_restore desktop_left desktop_right next_task prev_task)
                
                out2+=("^tag(mouseevents$i)")
                out2+=("^sep($MOUSE_EVENTS)")
                out2+=("$RESETMOUSE,t2ctl mousereset ${TINT};$me")
                out2+=("^sep()")
                out2+=("<tt>$(printf "%-16s %1s" "$MOUSE_LEFT" "[ <b>$MLEFT</b> ]")</tt>,^checkout(mleft$i)")
                out2+=("<tt>$(printf "%-16s %1s" "$MOUSE_RIGHT" "[ <b>$MRIGHT</b> ]")</tt>,^checkout(mright$i)")
                out2+=("<tt>$(printf "%-16s %1s" "$MOUSE_MIDDLE" "[ <b>$MMIDDLE</b> ]")</tt>,^checkout(mmiddle$i)")
                out2+=("<tt>$(printf "%-16s %1s" "$MOUSE_UP" "[ <b>$MUP</b> ]")</tt>,^checkout(mup$i)")
                out2+=("<tt>$(printf "%-16s %1s" "$MOUSE_DOWN" "[ <b>$MDOWN</b> ]")</tt>,^checkout(mdown$i)")
                
                out3+=("^tag(mleft$i)" "^sep($MOUSE_LEFT)")
                for n in "${mouseactions[@]}";do out3+=("$n,t2ctl mleft $n ${TINT};$me"); done
                
                out3+=("^tag(mright$i)"  "^sep($MOUSE_RIGHT)")
                for n in "${mouseactions[@]}";do out3+=("$n,t2ctl mright $n ${TINT};$me"); done
                
                out3+=("^tag(mmiddle$i)"  "^sep($MOUSE_MIDDLE)")
                for n in "${mouseactions[@]}";do out3+=("$n,t2ctl mmiddle $n ${TINT};$me"); done
                
                out3+=("^tag(mup$i)"  "^sep($MOUSE_UP)")
                for n in "${mouseactions[@]}";do out3+=("$n,t2ctl mup $n ${TINT};$me"); done
                
                out3+=("^tag(mdown$i)"  "^sep($MOUSE_DOWN)")
                for n in "${mouseactions[@]}";do out3+=("$n,t2ctl mdown $n ${TINT};$me"); done
                
                
                out2+=("^tag(taskappearance$i)")
                out2+=("^sep($APPEARANCE)")
                [[ "$ICON" = 1 && "$TEXT" = 1 ]] && out2+=("<big>${ron}</big>  <b>$SHOW_BOTH</b>,$me")||out2+=("<big>${roff}</big>  $SHOW_BOTH,t2ctl tb_both 1 ${TINT};$me")
                [[ "$TEXT" = 1 && "$ICON" = 0  ]] && out2+=("<big>${ron}</big>  <b>$SHOW_TEXT</b>,$me")||out2+=("<big>${roff}</big>  $SHOW_TEXT,t2ctl tb_text 1 ${TINT};$me")
                [[ "$ICON" = 1 && "$TEXT" = 0 ]] && out2+=("<big>${ron}</big>  <b>$SHOW_ICON</b>,$me")||out2+=("<big>${roff}</big>  $SHOW_ICON,t2ctl tb_icon 1 ${TINT};$me")
                out2+=("^sep()")
                [[ "$CENTERED" = 1 ]] && out2+=("<big>${cbon}</big>  $CENTER_TEXT,t2ctl tb_centered 0 ${TINT};$me")||out2+=("<big>${cboff}</big>  $CENTER_TEXT,t2ctl tb_centered 1 ${TINT};$me")
                #out2+=("^sep()")
                #out2+=("$BUTTON_WIDTH [ <b>$TB_WIDTH</b> ],^checkout(tbwidth$i)")
                #out3+=("^tag(tbwidth$i)")
                out2+=("^sep($BUTTON_WIDTH)")
                #out3+=("^sep()")
                #out3+=("$FITICON,t2ctl tb_width icon ${TINT};$me")
                tsizes=(100 120 150 180 200)
                for ts in "${tsizes[@]}"
                do
                [[ "$TB_WIDTH" == "$ts" ]] && out2+=("<big>${ron}</big>  <b>$ts px</b>") || out2+=("<big>${roff}</big>  $ts px,t2ctl tb_width $ts ${TINT};$me")
                done
                out2+=("^sep()")
                [[ "$TB_WIDTH" == "0" ]] && out2+=("<big>${ron}</big>  <b>$FILL</b>,t2ctl tb_width 0 ${TINT};$me") || out2+=("<big>${roff}</big>  $FILL,t2ctl tb_width 0 ${TINT};$me")
                
                out2+=("^sep($TOOLTIPS)")
                [[ "$TOOLTIP" = 0 && "$THUMBNAIL" = 0 ]] && out2+=("<big>${ron}</big>  <b>$TOOLTIPS_NONE</b>,t2ctl tb_tooltip_none 0 ${TINT};$me")||out2+=("<big>${roff}</big>  $TOOLTIPS_NONE,t2ctl tb_tooltip_none 1 ${TINT};$me")
                [[ "$TOOLTIP" = 1 && "$THUMBNAIL" = 0 ]] && out2+=("<big>${ron}</big>  <b>$SHOW_TOOLTIPS</b>,t2ctl tb_tooltip 0 ${TINT};$me")||out2+=("<big>${roff}</big>  $SHOW_TOOLTIPS,t2ctl tb_tooltip 1 ${TINT};$me")
                [[ "$TOOLTIP" = 1 && "$THUMBNAIL" = 1 ]] && out2+=("<big>${ron}</big>  <b>$THUMBNAILS</b>,t2ctl tb_thumbnail 0 ${TINT};$me")||out2+=("<big>${roff}</big>  $THUMBNAILS,t2ctl tb_thumbnail 1 ${TINT};$me")
                out2+=("")
                
                desktops=$(wmctrl -d |wc -l) 
                out+=("$_DESKTOPS	[ <b>$desktops</b> ],^checkout(desktops)")
                out2+=("^tag(desktops)")
                out2+=("^sep($_DESKTOPS)")
				out2+=("    $_ADD_DESKTOP,obxml desktops $((desktops+1));$me")
				[[ "$desktops" -gt "1" ]] && out2+=("    $_REMOVE_LAST,obxml desktops $((desktops-1));$me")
                
                fi ### END TASKBAR
                
                        
                out2+=("^tag(iconthemes$i)")
                for item in "/usr/share/icons"/*; do
                if [[ -d $item ]]; then
                out2+=("${item##*/},t2ctl icontheme ${item##*/} ${TINT};$me")
                fi
                done

                out2+=("^tag(ppos$i)")
                out2+=("^sep($POSITION)")
                out2+=("^sep($HORIZONTAL)")
                out2+=("  $TOP,t2ctl position tch ${TINT};$me")
                out2+=("  $BOTTOM,t2ctl position bch ${TINT};$me")
                out2+=("^sep()")
                out2+=("  $TOPLEFT,t2ctl position tlh ${TINT};$me")
                out2+=("  $TOPRIGHT,t2ctl position trh ${TINT};$me")
                out2+=("  $BOTTOMLEFT,t2ctl position blh ${TINT};$me")
                out2+=("  $BOTTOMRIGHT,t2ctl position brh ${TINT};$me")
                out2+=("^sep($VERTICAL)")
                out2+=("  $LEFT,t2ctl position clv ${TINT};$me")
                out2+=("  $RIGHT,t2ctl position crv ${TINT};$me")
                out2+=("^sep()")
                out2+=("  $TOPLEFT,t2ctl position tlv ${TINT};$me")
                out2+=("  $TOPRIGHT,t2ctl position trv ${TINT};$me")
                out2+=("  $BOTTOMLEFT,t2ctl position blv ${TINT};$me")
                out2+=("  $BOTTOMRIGHT,t2ctl position brv ${TINT};$me")
                out2+=("^tag(pwidth$i)")
                out2+=("^sep($SIZE)")
                for si in 100% 95% 90% 80% 75% 60% 50%;do
                [[ "${W}" == "$si" ]] && out2+=("<big>${ron}</big>  <b>${si}</b>,$me") || out2+=("<big>${roff}</big>  ${si},t2ctl width ${si} ${TINT};$me")
                done
                #out2+=("100%,t2ctl width 100% ${TINT};$me")
                #out2+=("95%,t2ctl width 95% ${TINT};$me")
                #out2+=("90%,t2ctl width 90% ${TINT};$me")
                #out2+=("80%,t2ctl width 80% ${TINT};$me")
                #out2+=("75%,t2ctl width 75% ${TINT};$me")
                #out2+=("60%,t2ctl width 60% ${TINT};$me")
                out2+=("^sep()")
                [[ "$SHRINK" == 0 ]] && out2+=("<big>${cboff}</big>   $COMPACT,t2ctl shrink 1 ${TINT};$me ") ||  out2+=("<big>${cbon}</big>   $COMPACT,t2ctl shrink 0 ${TINT};$me")
             
                
                
                out2+=("")
                out2+=("^tag(pheight$i)")
                out2+=("^sep($WIDTH)")
                heights=(24 28 32 36 40 44 48)
                for hi in "${heights[@]}"
                do
                [[ "$H" == "$hi" ]] && out2+=("<big>${ron}</big>  <b>$hi px</b>,t2ctl height $hi ${TINT};$me") || out2+=("<big>${roff}</big>  $hi px,t2ctl height $hi ${TINT};$me")
                done
                out2+=("^tag(pmargin$i)")
                out2+=("^sep($MARGIN)")
                margins=(0 1 2 4)
                #$HOR $VERT
                out2+=("^sep($HORIZONTAL)")
                for hor in "${margins[@]}"
                do
                [[ "$HOR" == "$hor" ]] && out2+=("<big>${ron}</big>  <b>$hor px</b>,t2ctl marginh $hor ${TINT};$me") || out2+=("<big>${roff}</big>  $hor px,t2ctl marginh $hor ${TINT};$me")
                done
                out2+=("^sep($VERTICAL)")
                for vert in "${margins[@]}"
                do
                [[ "$VERT" == "$vert" ]] && out2+=("<big>${ron}</big>  <b>$vert px</b>,t2ctl marginv $vert ${TINT};$me") || out2+=("<big>${roff}</big>  $vert px,t2ctl marginv $vert ${TINT};$me")
                done
                
                #$PHOR $PVERT $SPACE
                out2+=("^tag(ppadding$i)")
                out2+=("^sep($PADDING)")
                out2+=("^sep($HORIZONTAL)")
                for phor in "${margins[@]}"
                do
                [[ "$PHOR" == "$phor" ]] && out2+=("<big>${ron}</big>  <b>$phor px</b>,t2ctl paddingh $phor ${TINT};$me") || out2+=("<big>${roff}</big>  $phor px,t2ctl paddingh $phor ${TINT};$me")
                done
                out2+=("")
                out2+=("^sep($VERTICAL)")
				for pvert in "${margins[@]}"
                do
                [[ "$PVERT" == "$pvert" ]] && out2+=("<big>${ron}</big>  <b>$pvert px</b>,t2ctl paddingv $pvert ${TINT};$me") || out2+=("<big>${roff}</big>  $pvert px,t2ctl paddingv $pvert ${TINT};$me")
                done
                
                out2+=("^sep($SPACING)")
                for space in "${margins[@]}"
                do
                [[ "$SPACE" == "$space" ]] && out2+=("<big>${ron}</big>  <b>$space px</b>,t2ctl spacing $space ${TINT};$me") || out2+=("<big>${roff}</big>  $space px,t2ctl spacing $space ${TINT};$me")
                done
                                               
                out2+=("^tag(phide$i)")
                out2+=("^sep($AUTOHIDE)")
                [[ "$HIDE" == 0 ]] && out2+=("<big>${ron}</big>   $NO,t2ctl autohide 0 ${TINT}") || out2+=("<big>${roff}</big>   $NO,t2ctl autohide 0 ${TINT}")
                [[ "$HIDE" == 0 ]] && out2+=("<big>${roff}</big>   $YES,t2ctl autohide 1 ${TINT}") || out2+=("<big>${ron}</big>   $YES,t2ctl autohide 1 ${TINT}") 
                out2+=("^sep($SIZEHIDDEN)")
                out2+=("1,t2ctl hideheight 1 ${TINT}")
                out2+=("2,t2ctl hideheight 2 ${TINT}")
                out2+=("3,t2ctl hideheight 3 ${TINT}")
                out2+=("4,t2ctl hideheight 4 ${TINT}")
                out2+=("5,t2ctl hideheight 5 ${TINT}")
}

selector(){
    out2+=("^tag(configs)")
    #out2+=("^sep(COLREADY_TINTS)")
    #copy colready tints if not exist
    #for confpath in ~/.config/tint2/Jaskier*.tint2rc;do
    #confname="${confpath##*/}"
    #name="${confname%.*}"
    # [[ "$TINT2" == "$confname" ]] && out2+=("<big>${ron}</big>   <b>${name}</b>,t2ctl switchto ${confpath};${me}") || out2+=("<big>${roff}</big>   ${name},t2ctl switchto ${confpath};${me}")
    #done
    #out2+=("^sep(presets here)")

    out2+=("^sep($_PANEL_CONFIGS)")
    for confpath in ~/.config/tint2/*.tint2rc;do
    confname="${confpath##*/}"
    name="${confname%.*}"
    if [[ "${name}" =~ "launcher" ]] || [[ "${name}" =~ "dock" ]] || [[ "${name}" =~ "switch" ]] || [[ "${name}" =~ "Jaskier" ]];then
    :
    else
    [[ "$TINT2" == "$confname" ]] && out2+=("<big>${ron}</big>   <b>${name}</b>,t2ctl switchto ${confpath};${me}") || out2+=("<big>${roff}</big>   ${name},t2ctl switchto ${confpath};${me}")
    fi
    done
    out2+=("^sep()")
    out2+=("<big></big>   $_OPEN_CFG_DIR,exo-open ~/.config/tint2/")
}

# START HERE
if [ $1 == "-s" ]; then
out0+=("^sep($TITLE)")
else
out0+=("^sep(<tt>............$TITLE............</tt>)")
fi

# Select tint conf

out0+=("$_CHOOSE_TINT2,^checkout(configs)")


# Add LAUNCHERS
out+=("^sep($APPS)")
out+=("    $LAUNCHERS,jgtint2launcher")
if [ "$(pgrep -u $USER -f tint2)" ];then
i=0
#out+=("^sep($TINT2_CONFIGURE)")
       while read -r pid cmd; do
            if [[ ${cmd%% *} = tint2 ]]; then
                TINT=${cmd##* }
                TINT2=${TINT#$HOME/.config/tint2/}
                if [[ $TINT = tint2 ]];then
                    TINT="$TINT2RC"
                    TINT2="$DEFAULT_TINT2RC"
                fi
                out+=("^sep($PANEL: <i>$TINT2</i>)")
                ((i=i+1))
                getvalues
                qactions
                selector
                outA+=("^sep($ADVANCED)")
                outA+=("  $EDIT_TINT2 <i>$TINT2</i>,geany $TINT")
                outA+=("  $CONFIGURE <i>$TINT2</i>,tint2conf $TINT")
                if [ -f "/usr/share/mabox/lang/${LNG}/.config/tint2/${TINT2}" ];then
                outA+=("^sep()")
                outA+=("$RESET <i>$TINT2</i>,t2ctl reset ${TINT2};me")
                fi  

            fi
        done < <(pgrep -u $USER -a tint2)
fi

# Link to colorizer module if tint config is colorizer ready
if [[ "$TINT2" =~ ^Jaskier* ]];then
out0+=(" New! Colorize Panel (beta),colorizer-tint2 -s")
fi


if command -v phwmon.py &>/dev/null; then
PHWRUN="mabox-obstart phwmon"

. $HOME/.config/mabox/mabox.conf

    outM+=("^sep($TRAY_HWMON)")
    if [ "$(pgrep -u $USER -f phwmon.py)" ];then
    outM+=("$STOP,mb-setvar phwmon_monitor=false;sleep 2;$PHWRUN;$me")
    outM+=("^sep()")
[[ $phwmon_cpu = false ]] && outM+=("<big>${cboff}</big>  <i><s>CPU</s></i>,mb-setvar phwmon_cpu=true;$PHWRUN;$me") || outM+=("<big>${cbon}</big>  CPU,mb-setvar phwmon_cpu=false;$PHWRUN;$me")
[[ $phwmon_mem = false ]] && outM+=("<big>${cboff}</big>  <i><s>$MEM</s></i>,mb-setvar phwmon_mem=true;$PHWRUN;$me") || outM+=("<big>${cbon}</big>  $MEM,mb-setvar phwmon_mem=false;$PHWRUN;$me")
SW=$(swapon -s|wc -l)
if [[ "$SW" > 0 ]];then
[[ $phwmon_swap = false ]] && outM+=("<big>${cboff}</big>  <i><s>Swap</s></i>,mb-setvar phwmon_swap=true;$PHWRUN;$me") || outM+=("<big>${cbon}</big>  Swap,mb-setvar phwmon_swap=false;$PHWRUN;$me")
fi
[[ $phwmon_net = false ]] && outM+=("<big>${cboff}</big>  <i><s>$NET</s></i>,mb-setvar phwmon_net=true;$PHWRUN;$me") || outM+=("<big>${cbon}</big>  $NET,mb-setvar phwmon_net=false;$PHWRUN;$me")
[[ $phwmon_io = false ]] && outM+=("<big>${cboff}</big>  <i><s>$DISC_IO</s></i>,mb-setvar phwmon_io=true;$PHWRUN;$me") || outM+=("<big>${cbon}</big>  $DISC_IO,mb-setvar phwmon_io=false;$PHWRUN;$me")
    else
    outM+=("$START,mb-setvar phwmon_monitor=true;$PHWRUN;$me")
    fi

fi

#out+=("^sep($EDIT_TINT2)")

#    out+=("^sep()")

outA+=("^sep()")
#out+=("$CHOOSE_TINT2,$TZEN")
outA+=("<big></big>   $RESTART_TINT2,mb-tint2restart")
outA+=("<big>󰑤</big>   $RELOAD_TINT2,killall -SIGUSR1 tint2")

if [ $1 == "-s" ]; then

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"
MENU_MARGIN_Y=40
jgmenu_icon_size=0
menu_margin_x=${submenu_spacing:-0}
[ $(pidof picom) ] && MENU_RADIUS=$jgtools_radius
[ -z $jgmenu_use_borders ] && menu_border=0
POSITION_MODE=${2:-center}
JGWIDTH=340
TABS=170
mkconfigfile

cat <<EOF > ${MENU_ITEMS}

$(printf '%s\n' "${out0[@]}")
$(printf '%s\n' "${out[@]}")
$(printf '%s\n' "${outM[@]}")
$(printf '%s\n' "${outA[@]}")
$(printf '%s\n' "${out2[@]}")
$(printf '%s\n' "${out3[@]}")
EOF

jgmenu --config-file=${CONFIG_FILE} --csv-file=${MENU_ITEMS} 2>/dev/null

exit 0

fi

printf '%s\n' "${out[@]}"
printf '%s\n' "${out2[@]}"
printf '%s\n' "${out3[@]}"

if [ "$1" == "-r" ]; then
printf '%s\n' "^sep()"
printf '%s\n' "<i>$REMOVE</i>,mb-setvar places_tint2pipe=false;mb-jgtools places"
fi
