#! /bin/bash

# created by user PPC September 2020
# modified by MX Linux Devs November 2020 for use with MX-Fluxbox
# GPLv3

######################

TEXTDOMAINDIR=/usr/share/locale
export TEXTDOMAIN="flux-toolbar"

TITLE=$"Basic Toolbar Configuration"
LABEL1=$"Position"
LABEL2=$"Auto-hide"
LABEL3=$"Layer (screen priority)"
LABEL4=$"Width"
LABEL5=$"Height"
LABEL6=$"Show/Hide"
LABEL7=$"Transparency"

show_toolbar()
{
#Gui to use or not the Toolbar toggle (different from auto-hide):
toogle=$(yad --title "Toogle on/off" --center --width=310 --form --field="Use Fluxbox Toolbar? :CB" true\!false )
# remove pipe symbol at the end of variable
toggle=${toogle%?}
## Check if something was selected##
if [ -z "$toggle" ]; then
echo "Nothing was selected"
#if something was selected, change the init file
else echo "not empty:" & sed -i "s/^session.screen0.toolbar.visible:.*/session.screen0.toolbar.visible: $toggle/" ~/.fluxbox/init
fluxbox-remote restart
fi
}
######################

position()
{
#Gui to change the Toolbar position:
slit_position=$(yad --title "Position" --width=310 --center --form --field="Choose:CB" BottomCenter\!BottomLeft\!BottomRight\!LeftCenter\!RightCenter\!TopCenter\!TopLeft\!TopRight )
# remove pipe symbol at the end of variable
slit_position=${slit_position%?}
## Check if something was selected##
if [ -z "$slit_position" ]; then
echo "Nothing was selected"
#if something was selected, change the init file
else echo "not empty:" & sed -i "s/^session.screen0.toolbar.placement:.*/session.screen0.toolbar.placement: $slit_position/" ~/.fluxbox/init
echo "not empty:" & sed -i "s/^session.screen0.toolbar.visible:.*/session.screen0.toolbar.visible: true/" ~/.fluxbox/init
fluxbox-remote restart
fi
}

########################
layer()
{
#Gui to change the Toolbar layer:
slit_layer=$(yad --title "Layer" --center --width=310 --form --field="Choose:CB" Above_dock\!Dock\!Top\!Normal\!Bottom\!Destop )
# remove pipe symbol at the end of variable
slit_layer=${slit_layer%?}
## Check if something was selected##
if [ -z "$slit_layer" ]; then
echo "Nothing was selected"
#if something was selected, change the init file
else echo "not empty:" & sed -i "s/^session.screen0.toolbar.layer:.*/session.screen0.toolbar.layer: $slit_layer/" ~/.fluxbox/init
fluxbox-remote restart
fi
}

########################

autohide()
{
#Gui to change the Toolbar auto-hide:
slit_autohide=$(yad --title "Auto-hide" --center --width=310 --form --field="Choose:CB" false\!true )
# remove pipe symbol at the end of variable
slit_autohide=${slit_autohide%?}
## Check if something was selected##
if [ -z "$slit_autohide" ]; then
echo "Nothing was selected"
#if something was selected, change the init file
else echo "not empty:" & sed -i "s/^session.screen0.toolbar.autoHide:.*/session.screen0.toolbar.autoHide: $slit_autohide/" ~/.fluxbox/init
fluxbox-remote restart
fi
}
######################

width()
{
#Gui to change the Toolbar Width:
slit_size=$(yad --title "Width" --center --width=310 --form --field=" Width (%) :NUM" 75\!10..100\!2)
# remove pipe symbol at the end of variable
slit_size=${slit_size%?}
## Check if something was selected##
if [ -z "$slit_size" ]; then
echo "Nothing was selected"
#if something was selected, change the init file
else echo "not empty:" & sed -i "s/^session.screen0.toolbar.widthPercent:.*/session.screen0.toolbar.widthPercent: $slit_size/" ~/.fluxbox/init
fluxbox-remote restart
fi
}

######################

height()
{
#Gui to change the Toolbar Height:
height=$(yad --title "Height" --center --width=310 --form --field=" Height :NUM" 30\!10..100\!2)
# remove pipe symbol at the end of variable
height=${height%?}
## Check if something was selected##
if [ -z "$height" ]; then
echo "Nothing was selected"
#if something was selected, change the init file
else echo "not empty:" & sed -i "s/^session.screen0.toolbar.height:.*/session.screen0.toolbar.height: $height/" ~/.fluxbox/init
fluxbox-remote restart
fi
}


######################

transparency()
{
#Gui to change the Toolbar Transparency:
transparency=$(yad --title "Transparency" --center --width=310 --form --field=" Transparency (1-255) :NUM" 255\!1..255\!5)
# remove pipe symbol at the end of variable
transparency=${transparency%?}
## Check if something was selected##
if [ -z "$transparency" ]; then
echo "Nothing was selected"
#if something was selected, change the init file
else echo "not empty:" & sed -i "s/^session.screen0.toolbar.alpha:.*/session.screen0.toolbar.alpha: $transparency/" ~/.fluxbox/init
fluxbox-remote restart
fi
}
######################

export -f show_toolbar autohide layer position width height transparency

function button1 () 
{ 
   echo "button 1 is pressed" 
} 
export -f button1

yad --title "$TITLE" --width=300  --center --text-align=center --text=" \n  <b><i>Click to change a toolbar setting</i></b> \n" \
--form --field " <b>$LABEL1</b>:btn" --field "<b>$LABEL2</b>:btn" --field "<b>$LABEL3</b>:btn" --field "<b>$LABEL4</b>:btn" --field " <b>$LABEL5</b>:btn" --field "<b>$LABEL6</b>:btn" --field "<b>$LABEL7</b>:btn" \
    "bash -c position" "bash -c autohide" "bash -c layer" "bash -c width" "bash -c height" "bash -c show_toolbar" "bash -c transparency" --window-icon=/usr/share/icons/mxflux.png
