#!/bin/sh
#Barry Kauler 2009
#Called from Xorg Wizard, via xinit, testing a video mode.
#091124 bug fixes, vert and horiz freqs did not display for vesa driver.
#101213 adding gettext rodin.s

export TEXTDOMAIN=xorgwizard
export TEXTDOMAINDIR=/usr/share/locale
export OUTPUT_CHARSET=UTF-8
. gettext.sh
export LANGORG=$LANG

LANG=C # i18n

set -- `xvidtune -show` #'-display :0' not needed.
CLOCKHZ=`dc $2 1000000 \* p`
CLOCKHZINT=`echo -n "$CLOCKHZ" | cut -f 1 -d '.'`
if [ $CLOCKHZINT -ne 0 ];then
 XTEST=$3
 YTEST=$7
 VRTEST=`dc $CLOCKHZ $6 \/ ${10} \/ p`
 HSTEST=`dc $CLOCKHZ $6 \/ 1000 \/ p`
else
 #some video chips do not work with xvidtune.
 XRANDRINFO="`xrandr -q | grep '\*' | tr -s ' ' | grep '^ [0-9]' | head -n 1`"
 XTEST=`echo -n "$XRANDRINFO" | cut -f 2 -d ' ' | cut -f 1 -d 'x'`
 YTEST=`echo -n "$XRANDRINFO" | cut -f 2 -d ' ' | cut -f 2 -d 'x'`
 VRTEST=`echo -n "$XRANDRINFO" | cut -f 3 -d ' ' | cut -f 1 -d '*'`
 VRTESTINT=`echo -n "$VRTEST" | cut -f 1 -d '.'`
  
 #xrandr does not always return the vertical frequency...
 if [ $VRTESTINT -eq 0 -o ! $VRTEST ];then
  if [ "$MONCHOICES" = "" ];then #091124 exported from xorgwizard.
   mcPATTERN=" ${XTEST}x${YTEST}"'@'
   [ -f /tmp/ddcprobe.txt ] && VRTEST=`grep "$mcPATTERN" /tmp/ddcprobe.txt | tail -n 1 | cut -f 2 -d '@'` #091124
  else
   mcPATTERN='^'"${XTEST}x${YTEST}"'@'
   VRTEST=`echo "$MONCHOICES" | grep -m1 "$mcPATTERN" | cut -f 2 -d '@'`
  fi
  [ ! $VRTEST ] && VRTEST=60 #desparate last resort.
 fi
 # so we calc horiz freq theoretically...
 HSTEST=`gtf $XTEST $YTEST $VRTEST | head -n 2 | tail -n 1 | cut -f 1 -d ';' | cut -f 2 -d ':' | cut -f 2 -d ' '`
fi

#round off to two decimal places...
HSTEST=`printf "%.2f" $HSTEST`
VRTEST=`printf "%.2f" $VRTEST`

echo "XTEST=$XTEST
YTEST=$YTEST
VRTEST=$VRTEST
HSTEST=$HSTEST" > /tmp/xorgwizard_initrc_test_results #read by xorgwizard.
LANG=$LANGORG # i18n
xmessage -font "8x16" -center -timeout 60 -buttons "OK:10" -default OK " 
`eval_gettext \"Puppy Xorg Video Wizard: testing X


If you can see this, then X is working!

Current resolution:         \\\${XTEST}x\\\${YTEST} pixels
Horizontal sync frequency:  \\\$HSTEST KHz
Vertical refresh frequency: \\\$VRTEST Hz (times per second)

Please click the 'OK' button, or if your mouse isn't working,
just hit the ENTER key, or the combination CTRL-ALT-BACKSPACE.

If you don't do anything, this test will timeout in 60 seconds.\"`"

#when xmessage terminates, xinit should kill Xorg.
###END###
