YAD=yad
XDOTOOL=xdotool

name="wsudoku-solver"
class="wsudoku-solver"

yadicon="--window-icon=wsudoku-solver.png"
if command -v setwmc >/dev/null; then
   YAD="setwmc $name $class $YAD"
   XDOTOOL="setwmc $name $class $XDOTOOL"
   yadicon=""
fi

myyad() {
   local rc ans
   ans=$($YAD --on-top $yadicon "$@")
   rc=$?
   if [ $rc -ne 0 ]; then
      exit
   fi
   echo "$ans"
}

myxdotool() {
   $XDOTOOL "$@"
}

tell() {
   if [ "$1" = "-" ]; then
      cat | tee -a textinfo
      shift
   fi
   noisy=yes
   if [ "$1" = "-q" ]; then
      noisy=no
      shift
   fi
   echo "$@"
   echo "$@" >>textinfo
   if [ "$SPEAK" = yes -a "$noisy" = yes ]; then
      echo "$@" | espeak-ng -ven+f1
   fi
}

get_clicked_mouse_position()
{
    xdotool selectwindow getmouselocation | tr : ' ' | awk '{print $2, $4, $6, $8}'
    beep -l300 -f750 >/dev/null 2>&1
    play -q -n synth 0.1 sine 880 vol 0.5 >/dev/null 2>&1 
}

create_trans_window()
{
   #return
   yad --maximized --no-buttons --no-focus --undecorated --print-xid 2>xid_of_trans &
   echo $! > pid_of_trans
   sleep 1
   transset --id `cat xid_of_trans` 0.25
}

killtrans()
{
    echo "killtrans" $PWD 1>&2
    if [ -f pid_of_trans ] ; then
       echo "killing" `cat pid_of_trans` 1>&2
       kill -9 `cat pid_of_trans`
       rm -f pid_of_trans
    fi
}
