#!/usr/bin/env bash

#mx-idesktool v2, released March 2020. 
#A script by the MX Linux Dev Team, user Misko_2083 and others to configure the idesk app. Based on idesktool v1.36 released August 2004 by John Murray john@jmurray.id.au

TEXTDOMAINDIR=/usr/share/locale
export TEXTDOMAIN="mx-idesktool"

# Some have to be exported to be used in exported functions
TEXT1=$"ERROR: Yad not installed or not in path."
TEXT2=$"Yad found. So far so good.."
TEXT3=$"ERROR: idesk not installed or not in path. Try http://sourceforge.net/projects/idesk/"
TEXT4=$"idesk found - we're on a roll :)"
export TEXT5=$"Icon Management Tool"
export TEXT6=$"Caption:\n(Leave blank for no caption)"
TEXT7=$"Back"
TEXT8=$"Cancel"
TEXT9=$"Next"
export TEXT10=$"Caption"
TEXT11=$"NOTE: The default middle-click command \n
   runs this configuration tool (recommended)."
TEXT12=$"Left-Click Command:"
TEXT13=$"Middle-Click Command:"
TEXT14=$"Current icon" 
TEXT15=$"Oops!"
TEXT16=$"Error: Icon Image File Not Found."
TEXT17=$"Quit"
TEXT18=$"Error: Unknown Filetype. The icon should be a png image."
export TEXT19=$"Please choose a file"
TEXT20=$"Error: You need to select a valid file"
export TEXT21=$"Finished!" 
export TEXT22=$"All done. Restarting idesk now..."
TEXT23=$"Choose a .png icon image"
TEXT24=$"View or Edit an Icon"
export TEXT25=$"Remove an Icon"
TEXT26=$"Add a New Icon"
TEXT27=$"Reload the Desktop"
TEXT28=$"Edit iDesk's config file"
TEXT29=$"MX-idesktool Help"
TEXT30=$"USE: double-click entry to select a management action"
TEXT31=$"iDesk Configuration"
TEXT32=$"Config. file  found - excellent!"
TEXT33=$"WARNING: No ideskrc file was found.\nWould you like to have this file\nadded now?"
TEXT34=$"No!"
TEXT35=$"Yes!"
TEXT36=$"\tThe configuration file has been written. \n
                Drag any icons you create to the
                desired locations and they will
                be remembered between sessions \n\n 
                Would you like to run the icon wizard now?"
#TEXT37=$"Open"
#TEXT38=$"Delete"
#TEXT39=$"Open"
#TEXT40=$"Refresh"
#TEXT41=$"Configure"
#CAS=$"Help"
export OPEN=$"Open"
DELETE=$"Delete"
CREATE=$"Create"
POSITION=$"Locate"
REFRESH=$"Refresh"
CONFIGURE=$"Configure"
WRITE=$"Write"
HELP=$"Help"
TEXT43=$"ACTION"
TEXT44=$"DESCRIPTION"
TEXT45=$"Choose a .png icon image"
TEXT46=$"Left-Click Command:"
TEXT47=$"Middle-Click Command"
TEXT48=$"Set a precise position for an icon"
TEXT49=$"Directly edit an icon file"
LOCK=$"Lock"
LOCK_TEXT=$"Permit/prevent icon movement"

# export handles for the first tab
export getvalues='bash -c "getlnkfile"'
export savevalues='bash -c "savefile %3 %4 %5 %6 %7 %8 %9"'
export saveas='bash -c "savefileas %3 %4 %5 %6 %7 %8 %9"'
export newlnkfile='bash -c "newfile"'
export deleteicon='bash -c "deleteandrefresh %3"'
export openlnk='bash -c "editlnk %3"'
export tmpipe="/tmp/mxidesk.${RANDOM}"

# export handles for the second tab
export getsettings='bash -c "get_settings"'
export idesksettings='bash -c "idesk_settings %1"'
export openconfig='bash -c "editconfig"'
export tmpipetwo="/tmp/mxidesktwo.$(($RANDOM * $$))"

# make fifo
mkfifo "$tmpipe"
mkfifo "$tmpipetwo"

# function for the trap
function on_exit(){
  rm -f "${tmpipe}"
  rm -f "${tmpipetwo}"
}
trap "on_exit" EXIT

# Ensure only one instance of this script is running
me="$(basename "$0")"
running=$(ps h -C "${me}" | grep -wv $$ | wc -l)
[[ $running > 1 ]] && exit

#First make sure yad is available
if ! hash yad > /dev/null ; then
    echo "$TEXT1"
    exit
else
    echo "$TEXT2"
fi


#make sure idesk is available
if ! hash idesk > /dev/null ; then
    echo "$TEXT3"
    exit
else
	echo "$TEXT4" "$TEXT45"
fi

#make sure the .idesktop folder exists and if not make it now, so idesk can start
mkdir -p ~/.idesktop

#find out whether an argument was used

if [ "$#" -ne 1 ]; then
        argy=nope
else
        argy=yup
fi

argu="$*"

#set this icon directory because it has most available
icondir=/usr/share/icons/Moka/48x48/apps/

export DIALOG="yad"

writeconf()
{
echo -e "table Config
  FontName: gothic
  FontSize: 11
  FontColor: #37CFA6
  ToolTip.FontSize: 11
  ToolTip.FontName: gothic
  ToolTip.ForeColor: #0000FF
  ToolTip.BackColor: #000000
  ToolTip.CaptionOnHover: true
  ToolTip.CaptionPlacement: 
  Locked: false
  Transparency: 100
  Shadow: true
  ShadowColor: #000000
  ShadowX: 1
  ShadowY: 1 
  Bold: true
  ClickDelay: 200
  IconSnap: false
  SnapWidth: 0
  SnapHeight: 10
  SnapOrigin: BottomRight
  SnapShadow: false
  SnapShadowTrans: 200
  CaptionOnHover: true
  CaptionPlacement: bottom
  FillStyle: fillinvert
  Background.Delay: 0
  Background.Source: None
  Background.File: None 
  Background.Mode: Center 
  Background.Color: #C2CCFF
end
table Actions
  Lock: control right doubleClk
  Reload: control left singleClk
  Drag: right hold
  EndDrag: right singleClk
  Execute[0]: left singleClk
  Execute[1]: middle singleClk
end" > "${HOME}/.ideskrc"
}

function refresh()
{
killall idesk
exec idesk & disown
}
export -f refresh

function deleteandrefresh()
{
local 
yad --center  --window-icon=/usr/share/icons/mxflux.png \
    --width 500 --height 100 --center \
    --button="Yes!gtk-yes":0 --button="No!gtk-no":1 \
    --title="$TEXT19" --text="Are you sure you want to remove this icon ${1}?"
if [ $? -eq 0 ]
then
    rm -f "${HOME}/.idesktop/${1}"
    echo -e '\f' > "$tmpipe"
    echo "@disabled@" > "$tmpipe"  # delete
    echo "${getvalues}" > "$tmpipe"   # select
    echo "None" > "$tmpipe"        # currentlnkfile
    echo "@disabled@" > "$tmpipe"  # currentcaption
    echo "@disabled@" > "$tmpipe"  # command
    echo "@disabled@" > "$tmpipe"  # middle-click
    echo "@disabled@" > "$tmpipe"
    echo "@disabled@" > "$tmpipe"
    echo "@disabled@" > "$tmpipe"
    echo "@disabled@" > "$tmpipe"
    echo "@disabled@" > "$tmpipe"
    echo "${newlnkfile}" > "$tmpipe"
    echo "@disabled@" > "$tmpipe"
    
    # new cycle
    echo "@disabled@" > "$tmpipe"
    echo "${getvalues}" > "$tmpipe"
    echo "@disabled@" > "$tmpipe"  # disables third field
    killall idesk
    exec idesk & disown
fi
}
export -f deleteandrefresh

function getcurrentvalues()
{
#get the caption
	currentcaption=`sed -n '/^[ \t]\+Caption\:/s/^[ \t]\+Caption\:[ \t]\+//p' "${currentlnkfile}"`
#get the icon
	currenticon=`sed -n '/^[ \t]\+Icon\:/s/^[ \t]\+Icon\:[ \t]\+//p' "${currentlnkfile}"`
#get the left click command
    command=`sed -n  '/^[ \t]\+Command\(\[0\]\|\)\:/s/^[ \t]\+Command\(\[0\]\|\)\:[ \t]\+//p' "${currentlnkfile}"`
#get the middle click command
    mclick=`sed -n '/^[ \t]\+Command\[1\]\:/s/^[ \t]\+Command\[1\]\:[ \t]\+//p' "${currentlnkfile}"`
#get the X value
	currentxvalue=`sed -n '/^[ \t]\+X\:/s/^[ \t]\+X\:[ \t]\+//p' "${currentlnkfile}"`
#get the Y value
	currentyvalue=`sed -n '/^[ \t]\+Y\:/s/^[ \t]\+Y\:[ \t]\+//p' "${currentlnkfile}"`
# Regular expression explained
# sed -n '/^[ \t]\+Command\(\[0\]\|\)\:/s/^[ \t]\+Command\(\[0\]\|\)\:[ \t]\+//p'
# sed -n includes only matching lines
# Search for the pattern /^[ \t]\+Command\(\[0\]\|\)\:/
#        ^[ \t]\+ begins with multiple spaces or tabs
#         \(\[0\]\|\)\: search for matching string '[0]:' or 'empty:' aka (first|second) ([0]|):
# Replace and print s/^[ \t]\+Command\(\[0\]\|\)\:[ \t]\+//p

# max screen dimensions
Xaxis=$(xrandr --current | grep '*' | uniq | awk '{print $1}' | cut -d 'x' -f1 | grep "[0-9]\+")

Yaxis=$(xrandr --current | grep '*' | uniq | awk '{print $1}' | cut -d 'x' -f2 | grep "[0-9]\+")

}
export -f getcurrentvalues

function savefileas()
{

cd "${HOME}/.idesktop"
linkname="$($DIALOG --window-icon=/usr/share/icons/mxflux.png \
                    --width 500 --height 500 --center \
                    --button="Cancel":1 --button="Save":0 \
                    --title="$TEXT19"  \
                    --file-selection --save --file-filter="lnk | *.lnk" --filename="${1}")"
retval=$?
if [ $retval -eq 0 ]
then
      linkname="$(echo ${linkname##*/} | sed "s/[\ \$\/\*\&\|\?\^\"\']/_/g")"
      linkname="${linkname%%'.lnk'*}"
      if [ "${linkname}" = "" ]; then
        linkname="NoLinknameProvided$$"
      fi
      # save values
      touch "${HOME}/.idesktop/${linkname}.lnk"
      echo "table Icon" > "${HOME}/.idesktop/${linkname}.lnk"
      echo "  Caption: ${2}" | sed 's/.\$/\$/g' >> "${HOME}/.idesktop/${linkname}.lnk"
      echo "  Icon: ${5}" >> "${HOME}/.idesktop/${linkname}.lnk"
      echo "  X: ${6}" >> "${HOME}/.idesktop/${linkname}.lnk"
      echo "  Y: ${7}" >> "${HOME}/.idesktop/${linkname}.lnk"
      echo "  Command[0]: ${3}" >> "${HOME}/.idesktop/${linkname}.lnk"
      echo "  Command[1]: ${4}" >> "${HOME}/.idesktop/${linkname}.lnk"
      echo "end" >> "${HOME}/.idesktop/${linkname}.lnk"
      
      echo -e '\f' > "$tmpipe" # clear field values
      # start cycle - write saved values
      echo "${deleteicon}" > "$tmpipe"
      echo "${getvalues}" > "$tmpipe"
      echo "${linkname}" > "$tmpipe"
      echo "${2}" > "$tmpipe"
      echo "${3}" > "$tmpipe"
      echo "${4:-mx-idesktool ${linkname}.lnk}" > "$tmpipe"
      echo "${5:-${icondir}}" > "$tmpipe"
      echo "${6:-400}!0..${Xaxis:-5500}!10!0" > "$tmpipe"
      echo "${7:-500}!0..${Yaxis:-3500}!10!0" > "$tmpipe"
      echo "${savevalues}" > "$tmpipe"
      echo "${saveas}" > "$tmpipe"
      echo "${newlnkfile}" > "$tmpipe"
      echo "${openlnk}" > "$tmpipe"
      # end cycle
      
      # new cycle
      echo "${deleteicon}" > "$tmpipe"
      echo "${getvalues}" > "$tmpipe"
      echo "@disabled@" > "$tmpipe" # disables field
      
      
      $DIALOG --window-icon=/usr/share/icons/mxflux.png \
              --no-buttons --width 500 --title="$TEXT21" \
              --text="$TEXT22"  --timeout=3 --center
      refresh
fi
}
export -f savefileas


function savefile()
{

linkname="$(echo ${1} | sed "s/[\ \$\/\*\&\|\?\^\"\']/_/g")"

touch "${HOME}/.idesktop/${linkname}"
echo "table Icon" > "${HOME}/.idesktop/${linkname}"
echo "  Caption: ${2}" | sed 's/.\$/\$/g' >> "${HOME}/.idesktop/${linkname}"
echo "  Icon: ${5}" >> "${HOME}/.idesktop/${linkname}"
echo "  X: ${6}" >> "${HOME}/.idesktop/${linkname}"
echo "  Y: ${7}" >> "${HOME}/.idesktop/${linkname}"
echo "  Command[0]: ${3}" >> "${HOME}/.idesktop/${linkname}"
echo "  Command[1]: ${4}" >> "${HOME}/.idesktop/${linkname}"
echo "end" >> "${HOME}/.idesktop/${linkname}"

$DIALOG --window-icon=/usr/share/icons/mxflux.png \
        --no-buttons --width 500 --title="$TEXT21" \
        --text="$TEXT22"  --timeout=3 --center
refresh
}
export -f savefile

function getlnkfile()
{

cd "${HOME}/.idesktop"
currentlnkfile="$($DIALOG --window-icon=/usr/share/icons/mxflux.png \
                          --width 500 --height 500 --center \
                          --button="$OPEN":0 \
                          --title="$TEXT19"  \
                          --file-selection --file-filter="lnk | *.lnk")"
retval=$?

case $retval in
        0) filecheck="$(echo "${currentlnkfile}" | grep -i "\.lnk")"
           if [ "${filecheck}" = "${currentlnkfile}" ] && [ -e "${currentlnkfile}" ]; then
                  getcurrentvalues
                  echo -e '\f' > "$tmpipe"
                  echo "${deleteicon}" > "$tmpipe"
                  echo "${getvalues}" > "$tmpipe"
                  echo "${currentlnkfile##*/}" > "$tmpipe"
                  echo "${currentcaption}" > "$tmpipe"
                  echo "${command}" > "$tmpipe"
                  echo "${mclick:-mx-idesktool ${linkname}.lnk}" > "$tmpipe"
                  echo "${currenticon:-${icondir}}" > "$tmpipe"
                  echo "${currentxvalue:-400}!0..${Xaxis:-5500}!10!0" > "$tmpipe"
                  echo "${currentyvalue:-500}!0..${Yaxis:-3500}!10!0" > "$tmpipe"
                  echo "${savevalues}" > "$tmpipe"
                  echo "${saveas}" > "$tmpipe"
                  echo "${newlnkfile}" > "$tmpipe"
                  echo "${openlnk}" > "$tmpipe"
                  
                  # new cycle
                  echo "${deleteicon}" > "$tmpipe"
                  echo "${getvalues}" > "$tmpipe"
                  echo "@disabled@" > "$tmpipe" # disables field
                  
           else
                  $DIALOG --window-icon=/usr/share/icons/mxflux.png \
                          --title=$TEXT15 \
                          --icon ./warning.xpm \
                          --text=$TEXT20 \
                          --center
                  case $? in
                       0) getlnkfile
                          ;;
                  esac
           fi
           ;;
esac
}
export -f getlnkfile

function newfile()
{
local new_caption
local new_link
new_caption="$($DIALOG --title "$TEXT5" \
                       --form --center --text="$TEXT6" \
                       --separator="" \
                       --button="Cancel":1 \
                       --button="OK":0 \
		       --field="$TEXT10" "$cap" 2>/dev/null)"
retval=$?

case $retval in
        0) new_caption="$(echo "${new_caption}" | sed 's/\$/\\$/g')"


           if [ "$new_caption" == "" ]
           then
               new_link="NewLink$$"
           else
               new_link="$(echo ${new_caption} | sed "s/[\ \$\/\*\&\|\?\^\"\']/_/g")"
           fi

           echo -e '\f' > "$tmpipe"
           echo "@disabled@" > "$tmpipe"  # delete
           echo "@disabled@" > "$tmpipe"   # select
           echo "${new_link}" > "$tmpipe"  # currentlnkfile
           echo "${new_caption}" > "$tmpipe"  # currentcaption
           echo "${new_link}" > "$tmpipe"  # command
           echo "mx-idesktool ${new_link}" > "$tmpipe"  # middle-click
           echo "/usr/share/icons/Moka/48x48/apps/terminal.png" > "$tmpipe"
           echo "${currentxvalue:-400}!0..${Xaxis:-5500}!10!0" > "$tmpipe"
           echo "${currentyvalue:-500}!0..${Yaxis:-3500}!10!0" > "$tmpipe"
           echo "@disabled@" > "$tmpipe"
           echo "${saveas}" > "$tmpipe"
           echo "@disabled@" > "$tmpipe"
           echo "@disabled@" > "$tmpipe"
           ;;
esac
}
export -f newfile


function editlnk()
{
yad --title="$TEXT31" --width 500 --height 600 --center \
    --window-icon=/usr/share/icons/mxflux.png \
    --title="Edit Idesk Configuration" --center \
    --button="Close":1 --button="Save":0 \
	--text-info --editable <"${HOME}/.idesktop/${1}" 2>/dev/null > /tmp/editlnk.txt.$$

case $? in
      0) cat "/tmp/editlnk.txt.$$" > "${HOME}/.idesktop/${1}"
         rm -f "/tmp/editlnk.txt.$$"
        echo -e "\f" >"$tmpipe"
        echo "@disabled@" >"$tmpipe"
        echo "${getvalues}" >"$tmpipe"
        echo "None" >"$tmpipe"
        echo "@disabled@" >"$tmpipe"
        echo "@disabled@" >"$tmpipe"
        echo "@disabled@" >"$tmpipe"
        echo "@disabled@" >"$tmpipe"
        echo "@disabled@" >"$tmpipe"
        echo "@disabled@" >"$tmpipe"
        echo "@disabled@" >"$tmpipe"
        echo "@disabled@" >"$tmpipe"
        echo "${newlnkfile}" >"$tmpipe"
        echo "@disabled@" >"$tmpipe"
        
        # new cycle
        echo "@disabled@" >"$tmpipe"
        echo "${getvalues}" >"$tmpipe"
        echo "@disabled@" >"$tmpipe"  # disables third field
         refresh
         ;;
      *) rm -f "/tmp/editlnk.txt.$$"
         ;;
esac
}
export -f editlnk

###########################
#    second tab functions #
###########################

function get_settings(){
# grep for Locked: true and if present change to Locked: false

local toggle

toggle="$(grep "Locked:" "${HOME}/.ideskrc" | grep true)"

echo -e '\f' > "$tmpipetwo"

if [ -n "$toggle" ]; then
    echo "TRUE" > "$tmpipetwo"
else
    echo "FALSE" > "$tmpipetwo"
fi
echo "${idesksettings}" >  "$tmpipetwo"
echo "${openconfig}" >  "$tmpipetwo"

}
export -f get_settings

function idesk_settings(){

local _check="${1}"

if [ $_check == "TRUE" ]; then
   sed -i s/Locked.*/'Locked: true'/ "${HOME}/.ideskrc"
else
   sed -i s/Locked.*/'Locked: false'/ "${HOME}/.ideskrc"
fi

$DIALOG  --title "$TEXT5" --width 250 --height 30 --center \
		 --text="$TEXT22"	\
		 --no-buttons \
		 --timeout=2


refresh
}
export -f idesk_settings

function editconfig()
{
yad --title="$TEXT31" --width 500 --height 600 --center \
    --window-icon=/usr/share/icons/mxflux.png \
    --title="Edit Idesk Configuration" --center \
    --button="Close":1 --button="Save":0 \
	--text-info --editable <"${HOME}/.ideskrc" 2>/dev/null > /tmp/editbox.txt.$$

case $? in
      0) cat "/tmp/editbox.txt.$$" > "${HOME}/.ideskrc"
         rm -f "/tmp/editbox.txt.$$"
         refresh
         ;;
      *) rm -f "/tmp/editbox.txt.$$"
         ;;
esac
}
export -f editconfig


###########################
#       Jerry's stuff     #
###########################

function mxidesktool_help()
{
local browser url

url="https://mxlinux.org/wiki/help-files/help-mx-idesktool"

##If an mx-viewer is present, use mx-viewer, otherwise use generic xdg-open 
if [ -e "/usr/bin/mx-viewer" ]; then
    browser="mx-viewer"
else
    browser="xdg-open"
fi
$browser $url &
}
export -f mxidesktool_help

##########################
#     End Functions      #
##########################

#now let's see whether the configuration files are present
if [ -e "${HOME}/.ideskrc" ]; then
        echo "$TEXT32"
else
        $DIALOG --window-icon=/usr/share/icons/mxflux.png \
                --center --title $TEXT31 \
                --text $TEXT33 \
                --button="$TEXT34!gtk-no":1 --button="$TEXT35!gtk-yes":0
case $? in
        0) writeconf
           $DIALOG --window-icon=/usr/share/icons/mxflux.png \
                   --center --title $TEXT31 \
                   --button=$TEXT34:1 --button=$TEXT35:0 \
                   --text="$TEXT36" 2>/dev/null
           case $? in
                   0) :
                      ;;
                   *) exit
                      ;;
           esac
           ;;
        *) exit
           ;;
esac
fi


exec 3<>"$tmpipe"
exec 5<>"$tmpipetwo"

# plugkey for notebook
yadkey="$((${RANDOM} * $$))"

$DIALOG --plug=${yadkey} --tabnum=1  \
        --form --separator=$'\n' --align=right \
                    --text="" \
                    --field="Remove icon":BTN  \
                    --field="Select a link file":FBTN  \
                    --field="Link File" \
                    --field="$TEXT6" \
                    --field="$TEXT12" \
	                --field="$TEXT13" \
                    --field="$TEXT14":FL  \
                    --field="X":NUM  \
                    --field="Y":NUM  \
                    --field="Save":BTN  \
                    --field="Save As":BTN  \
                    --field="New":BTN \
                    --field="Edit":BTN \
                    --file-filter="png | *.PNG *.png" --file-filter="lnk | *.lnk" \
                    --cycle-read >/dev/null 2>&1 <&3 &
           
$DIALOG --plug=${yadkey} --tabnum=2  --form  \
        --separator=$'\n' --align=right --text="second tab" \
        --field="Lock Desktop Icons":CHK \
        --field="Apply":BTN  \
        --field="Open Config File":BTN \
        --cycle-read >/dev/null 2>&1 <&5 &

# get
get_settings

currentlnkfile="${HOME}/.idesktop/${argu}"
filecheck="$(echo "${currentlnkfile}" | grep -i "\.lnk")"
if [ "${filecheck}" = "${currentlnkfile}" ] && [ -e "${currentlnkfile}" ]; then
        # get field values
        getcurrentvalues
else
        argy=nope
fi

if [ "${argy}" = "nope" ]; then
        #set field values
        echo "@disabled@" >&3
        echo "${getvalues}" >&3
        echo "None" >&3
        echo "@disabled@" >&3
        echo "@disabled@" >&3
        echo "@disabled@" >&3
        echo "@disabled@" >&3
        echo "@disabled@" >&3
        echo "@disabled@" >&3
        echo "@disabled@" >&3
        echo "@disabled@" >&3
        echo "${newlnkfile}" >&3
        echo "@disabled@" >&3
        
        # new cycle
        echo "@disabled@" >&3
        echo "${getvalues}" >&3
        echo "@disabled@" >&3  # disables third field
else
        currentlnkfile="${HOME}/.idesktop/${argu}"

        # set field values
        echo "${deleteicon}" >&3
        echo "${getvalues}" >&3
        echo "${currentlnkfile##*/}" >&3
        echo "${currentcaption}" >&3
        echo "${command}" >&3
        echo "${mclick:-mx-idesktool ${linkname}.lnk}" >&3
        echo "${currenticon:-${icondir}}" >&3
        echo "${currentxvalue:-400}!0..${Xaxis:-5500}!10!0" >&3
        echo "${currentyvalue:-500}!0..${Yaxis:-3500}!10!0" >&3
        echo "${savevalues}" >&3
        echo "${saveas}" >&3
        echo "${newlnkfile}" >&3
        echo "${openlnk}" >&3
        
        # new cycle
        echo "${deleteicon}" >&3
        echo "${getvalues}" >&3
        echo "@disabled@" >&3 # disables third field
fi


$DIALOG --window-icon=/usr/share/icons/mxflux.png \
        --title="mxidesktool 2" --center \
        --button="Refresh":'bash -c "refresh >/dev/null 2>&1"' \
        --button="Help":'bash -c "mxidesktool_help >/dev/null 2>&1" ' \
        --button="Close":0 \
        --buttons-layout=spread \
        --notebook --key="${yadkey}" --tab="Icon" \
        --tab="Settings" --center # & mxidesk_pid=$!

retval=$?

exec 3>&-
exec 5>&-

exit "${retval}"
