You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
149 lines
2.7 KiB
149 lines
2.7 KiB
6 years ago
|
#!/bin/sh
|
||
|
|
||
4 years ago
|
# Control the input devices
|
||
|
# Depends: xinput, setxkbmap
|
||
|
|
||
6 years ago
|
help() {
|
||
|
B=$(tput bold)
|
||
|
U=$(tput smul)
|
||
|
N=$(tput sgr0)
|
||
|
|
||
|
cat << EOF
|
||
|
${B}NAME${N}
|
||
4 years ago
|
inputctl - control the input devices
|
||
6 years ago
|
|
||
|
${B}SYNOPSIS${N}
|
||
4 years ago
|
${B}inputctl${N} ${U}OPTION${N} [${U}ARG${N}]
|
||
6 years ago
|
|
||
|
${B}OPTIONS${N}
|
||
4 years ago
|
${B}-h${N} Display usage message and exit.
|
||
6 years ago
|
|
||
4 years ago
|
${B}-d${N} ${U}STATE${N}
|
||
|
Set touchpad state, possible values: toggle, on/off, 1/0.
|
||
6 years ago
|
|
||
4 years ago
|
${B}-k${N} ${U}STATE${N}
|
||
|
Set keyboard state, possible values: toggle, on/off, 1/0.
|
||
6 years ago
|
|
||
4 years ago
|
${B}-s${N} ${U}STATE${N}
|
||
|
Set touchscreen state, possible values: toggle, on/off, 1/0.
|
||
6 years ago
|
EOF
|
||
|
}
|
||
|
|
||
4 years ago
|
setxkbmap -option caps:swapescape
|
||
|
|
||
5 years ago
|
# Exit if no option is provided
|
||
|
[ "$#" -eq 0 ] && help && exit 1
|
||
6 years ago
|
|
||
5 years ago
|
# Set required X variables
|
||
|
export DISPLAY=:0
|
||
|
export XAUTHORITY="$XDG_DATA_HOME/xorg/Xauthority"
|
||
|
|
||
6 years ago
|
# Option handling
|
||
5 years ago
|
SCRIPT="$(basename "$0")"
|
||
6 years ago
|
while getopts ':h?d:k:s:' opt; do
|
||
|
case $opt in
|
||
|
h)
|
||
|
help
|
||
4 years ago
|
exit 0
|
||
6 years ago
|
;;
|
||
|
d)
|
||
4 years ago
|
OPTION="d"
|
||
|
ARG="$OPTARG"
|
||
|
DEV="SYNA3602:00 0911:5288 Touchpad"
|
||
6 years ago
|
;;
|
||
|
k)
|
||
4 years ago
|
OPTION="k"
|
||
|
ARG="$OPTARG"
|
||
6 years ago
|
;;
|
||
|
s)
|
||
4 years ago
|
OPTION="s"
|
||
|
ARG="$OPTARG"
|
||
|
DEV="pointer:04F3200A:00 04F3:2373"
|
||
6 years ago
|
;;
|
||
|
:)
|
||
|
echo "$SCRIPT: option requires an argument '$OPTARG'"
|
||
|
echo "Try '$SCRIPT -h' for more information."
|
||
|
exit 1
|
||
|
;;
|
||
|
\?)
|
||
|
echo "$SCRIPT: invalid option '$OPTARG'"
|
||
|
echo "Try '$SCRIPT -h' for more information."
|
||
|
exit 1
|
||
|
;;
|
||
|
esac
|
||
|
done
|
||
|
|
||
|
toggle_device() {
|
||
4 years ago
|
STATUS=$(xinput --list-props "$2" | awk '/Device Enabled/ { print $4 }')
|
||
|
[ "$STATUS" -eq 1 ] && xinput --disable "$2" || xinput --enable "$2"
|
||
|
}
|
||
|
|
||
|
device() {
|
||
|
case "$1" in
|
||
|
1 | on)
|
||
|
xinput --enable "$2"
|
||
|
;;
|
||
|
0 | off)
|
||
|
xinput --disable "$2"
|
||
|
;;
|
||
|
t*)
|
||
|
toggle_device "$2"
|
||
|
;;
|
||
|
*)
|
||
|
echo "$SCRIPT: invalid argument '$1'"
|
||
|
echo "Try '$SCRIPT -h' for more information."
|
||
|
exit 1
|
||
|
;;
|
||
|
esac
|
||
6 years ago
|
}
|
||
|
|
||
|
keyboard() {
|
||
|
[ -z "$1" ] && return 1
|
||
|
|
||
|
if [ "$1" = "toggle" ]; then
|
||
|
if setxkbmap -query | grep -q options; then
|
||
|
keyboard "off"
|
||
|
else
|
||
|
keyboard "on"
|
||
|
fi
|
||
|
|
||
|
elif [ "$1" = "on" ]; then
|
||
|
# Swap caps lock with escape
|
||
|
setxkbmap -option caps:swapescape
|
||
|
|
||
|
# Swap left crtl with left alt
|
||
|
# setxkbmap -option ctrl:swap_lalt_lctl
|
||
|
|
||
|
# Set touchpad toggle keyboard symbol
|
||
|
# xmodmap -e "keycode 93 = XF86iTouch"
|
||
|
|
||
|
elif [ "$1" = "off" ]; then
|
||
|
# Clear all key mappings
|
||
|
setxkbmap -option ''
|
||
|
fi
|
||
|
}
|
||
|
|
||
4 years ago
|
# Option execution
|
||
|
# if [ "$DEV" = "Keyboard" ]; then
|
||
|
# keyboard "$ARG"
|
||
|
# else
|
||
|
case "$OPTION" in
|
||
|
d | s)
|
||
|
device "$ARG" "$DEV"
|
||
|
;;
|
||
|
k)
|
||
|
keyboard "$ARG"
|
||
|
;;
|
||
|
esac
|
||
6 years ago
|
|
||
|
# Useful input diagnostics packages:
|
||
|
# - xinput
|
||
|
# - xev
|
||
|
# - evtest
|
||
|
#
|
||
|
# - setxkbmap -query
|
||
|
# - xmodmap -pke
|
||
4 years ago
|
|
||
|
# https://superuser.com/questions/437053/firefox-doesnt-recognize-my-alt-keys-anymore
|
||
|
# https://www.x.org/releases/X11R7.7/doc/xorg-docs/input/XKB-Config.html
|