-
Notifications
You must be signed in to change notification settings - Fork 0
/
touchpad-activator
executable file
·122 lines (105 loc) · 2.5 KB
/
touchpad-activator
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/bin/bash
####################################################################################################
##
## touchpad-activator
##
## Utility script which uses xinput to extract information on the internal touchpad and allows
## to change its enabled status. Please note that this script will not work properly if the
## touchpad device of the XPS (2015-build) uses PS2 instead of the I2C bus. This is indeed
## the case if 'xinput --list' shows an entry like this 'DLL0665:01 06CB:76AD UNKNOWN' and
## an entry containing the text "PS2 touchpad". In this case, you have to blacklist the PS2 mode
## by adding the line 'blacklist psmouse' to /etc/modprobe.d/blacklist.conf and executing
## "sudo update-initramfs -u".
##
## This script logs its activity to $LOG_FILE.
##
####################################################################################################
LOG_DIRECTORY="/home/$USER/.touchpad-activator"
LOG_FILE="$LOG_DIRECTORY/touchpad-activator.log"
TOUCHPAD_DEVICE_PATTERN="DLL0665"
TOUCHPAD_DEVICE_ID=`xinput | grep $TOUCHPAD_DEVICE_PATTERN | cut -d'=' -f2 | cut -f2 --complement`
TOUCHPAD_IS_ENABLED=`xinput list-props $TOUCHPAD_DEVICE_ID | grep "Device Enabled" | cut -d':' -f2 | tr -d '[[:space:]]'`
function create_directory_if_nonexisting
{
if [ ! -d $1 ];
then
mkdir $1
chmod +rw $1
fi
}
function init_log_file
{
touch $LOG_FILE
}
function log
{
echo $1 >> $LOG_FILE
}
function set_enabled_status
{
xinput --set-prop $TOUCHPAD_DEVICE_ID "Device Enabled" $1
log "[INFO ] Enabled status for device $TOUCHPAD_DEVICE_ID has been set to $1."
}
function disable_touchpad
{
set_enabled_status 0
}
function enable_touchpad
{
set_enabled_status 1
}
function toggle_touchpad
{
if [ $TOUCHPAD_IS_ENABLED -eq 0 ]
then
enable_touchpad
else
disable_touchpad
fi
}
function status
{
echo "Touchpad Device ID: "$TOUCHPAD_DEVICE_ID
if [ $TOUCHPAD_IS_ENABLED -eq 0 ]
then
echo "Touchpad Status : Off"
else
echo "Touchpad Status : On"
fi
}
function validate
{
case $TOUCHPAD_DEVICE_ID in
''|*[!0-9]*)
log "[ERROR] Device ID '$TOUCHPAD_DEVICE_ID' is not a number."
exit -1
;;
esac
case $TOUCHPAD_IS_ENABLED in
''|*[!0-9]*)
log "[ERROR] Unable to read status for touchpad device with ID '$TOUCHPAD_DEVICE_ID'."
exit -1
;;
esac
}
create_directory_if_nonexisting $LOG_DIRECTORY
init_log_file
validate
if [ -z "$1" ]
then
toggle_touchpad
else
case $1 in
on)
enable_touchpad
;;
off)
disable_touchpad
;;
status)
status
;;
*)
status
esac
fi