summaryrefslogtreecommitdiff
path: root/calibrate.sh
blob: e400304448403473fd0d675f92dc8d3fd814ad2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/bin/bash
XINIT=`which xinit`
XSERVER=`which X`
EVCALIBRATE=`which ev_calibrate || echo ./ev_calibrate`
UDI=$(hal-find-by-property --key input.x11_driver --string evtouch)
MYDPY=":1.0"
ZENITY=`which zenity`
KDIALOG=`which kdialog`
XDIALOG=`which Xdialog`

INFO="You have selected to (re)calibrate your touchscreen.\n\n\
Move your pen around all edges on the following screen.\n\n\
If you are done and touched all edges, hit the enter key and wait until \
the top left crosshair turns red.\nOnce you tap the red crosshair, \
the next one will turn red going from the top left to the \
bottom right.\nIf you miss a tap, the right mouse button will \
take you back one step.\n\n\
If you tapped the last (bottom right) crosshair, the program will \
return to your session. Note that changes only take effect after \
restarting the session."

RESTARTINFO="Touchscreen calibration done\nPlease restart your \
session to \nmake the changes take effect"

FAILINFO="No evtouch capable device found, if you are sure you have \n\
an evtouch capable touchscreen, please mail the \
resulting file of the command \"lshal > evtouch_hal.out\" to the\n\
ubuntu-mobile@lists.ubuntu.com mailing list, so support for your \
device can be added."

if [ -z "$UDI" ];then
    if [ -x "${ZENITY}" ]; then
        $ZENITY --info --text="${FAILINFO}"
    elif [ -x "${XDIALOG}" ]; then
        $XDIALOG --fill --msgbox "${FAILINFO}" 20 40
    elif [ -x "${KDIALOG}" ]; then
        $KDIALOG --msgbox "${FAILINFO}"
    fi
    exit 0
fi

if [ -x "${ZENITY}" ]; then
    $ZENITY --info --text="${INFO}"
elif [ -x "${XDIALOG}" ]; then
    $XDIALOG --fill --msgbox "${INFO}" 30 40
elif [ -x "${KDIALOG}" ]; then
    $KDIALOG --msgbox "${INFO}"
fi

echo $EVCALIBRATE

if [ -n "$DISPLAY" ]; then
    DPY=$(echo $DISPLAY|sed -e 's/[a-z:]*//g'|cut -d'.' -f1)
    MYDPY=":$(($DPY+1)).0"
fi

if ! [ -x "$EVCALIBRATE" ] ; then
	echo "ev_calibrate not found exiting ..."
	exit 1;
fi
echo "evalibrate located at $EVCALIBRATE"

if [ -z "$XINIT" ]; then
    echo "xinit not found exiting ..."
    exit 1;
fi
echo "xinit located at $XINIT"
if [ -z "$XSERVER" ]; then
    echo "X not found exiting ..."
    exit 1;
fi
echo "xserver located at $XSERVER"
if [ -e /tmp/ev_calibrate ]; then
	rm /tmp/ev_calibrate;
fi
echo "Creating FIFO..."
mknod /tmp/ev_calibrate p

#for development only :)
#cp evtouch_drv.o /usr/X11R6/lib/modules/input
#xinit /usr/bin/ddd ev_calibrate -- /usr/X11R6/bin/X
echo "Starting calibration program..."
sleep 2
hal-set-property --udi $UDI --key input.x11_options.calibrate --string "1"

$XINIT $EVCALIBRATE -- $XSERVER $MYDPY -auth /dev/null

hal-set-property --remove --udi $UDI --key input.x11_options.calibrate

invoke-rc.d --quiet xserver-xorg-input-evtouch start

rm /tmp/ev_calibrate

if [ -x "${ZENITY}" ]; then
    $ZENITY --info --text="${RESTARTINFO}"
elif [ -x "${XDIALOG}" ]; then
    $XDIALOG --fill --msgbox "${RESTARTINFO}" 10 40
elif [ -x "${KDIALOG}" ]; then
    $KDIALOG --msgbox "${RESTARTINFO}"
fi

exit 0