From b78c0e3ed24a2a5a4f700e50f623b3ccaec3fcad Mon Sep 17 00:00:00 2001 From: Riyyi Date: Fri, 24 May 2019 16:41:43 +0200 Subject: [PATCH] Add and implement inputctl.sh, remove touchpad i2c_hid module blacklist --- .config/sxhkd/sxhkdrc | 7 +- .config/xorg/xinitrc | 12 ++-- .config/zsh/.zshrc | 4 -- .scripts/inputctl.sh | 130 ++++++++++++++++++++++++++++++++++ .scripts/touchscreen.sh | 11 --- etc/modprobe.d/blacklist.conf | 3 - 6 files changed, 139 insertions(+), 28 deletions(-) create mode 100755 .scripts/inputctl.sh delete mode 100755 .scripts/touchscreen.sh diff --git a/.config/sxhkd/sxhkdrc b/.config/sxhkd/sxhkdrc index b8b3a39..10af66b 100644 --- a/.config/sxhkd/sxhkdrc +++ b/.config/sxhkd/sxhkdrc @@ -45,8 +45,9 @@ XF86Audio{LowerVolume,RaiseVolume,Mute} mediacontrol.sh {down 5,up 5,toggle} # Touchpad toggle -# XF86iTouch +XF86HomePage + inputctl.sh -d toggle # Touchscreen toggle -XF86HomePage - touchscreen.sh +XF86Search + inputctl.sh -s toggle diff --git a/.config/xorg/xinitrc b/.config/xorg/xinitrc index 2b2924e..7d126f8 100644 --- a/.config/xorg/xinitrc +++ b/.config/xorg/xinitrc @@ -11,14 +11,12 @@ xrandr --output eDP-1 --mode 3000x2000_48.00 --primary xset s off xset -dpms -# Clear all key mappings -setxkbmap -option '' +# Customize keyboard layout +inputctl.sh -k off +inputctl.sh -k on -# Swap capslock with escape -setxkbmap -option caps:swapescape - -# Set touchpad toggle key symbol -xmodmap -e "keycode 93 = XF86iTouch" +# Turn off touchscreen +inputctl.sh -s off # Daemon starting dunst & diff --git a/.config/zsh/.zshrc b/.config/zsh/.zshrc index 04383df..15e0a70 100644 --- a/.config/zsh/.zshrc +++ b/.config/zsh/.zshrc @@ -129,10 +129,6 @@ alias nw="$HOME/.scripts/network.sh" alias vp="$HOME/.scripts/vimplugin.sh" alias mpvshuffle="$HOME/.scripts/mpv.sh shuffle" -# Laptop -alias offtouchpad='sudo rmmod i2c_hid' -alias ontouchpad="sudo modprobe i2c_hid && $HOME/.scripts/touchscreen.sh 0" - # Other alias mysql-workbench="GDK_SCALE=1 GDK_DPI_SCALE=1 mysql-workbench 1>/dev/null 2>&1 &; disown" alias weather="curl -s 'http://wttr.in/dordrecht?q&n&p' | head -n -3" diff --git a/.scripts/inputctl.sh b/.scripts/inputctl.sh new file mode 100755 index 0000000..769847f --- /dev/null +++ b/.scripts/inputctl.sh @@ -0,0 +1,130 @@ +#!/bin/sh + +help() { + B=$(tput bold) + U=$(tput smul) + N=$(tput sgr0) + + cat << EOF +${B}NAME${N} + inputctl.sh - input manager + +${B}SYNOPSIS${N} + ${B}inputctl.sh${N} [${U}OPTION${N}] [${U}ARG${N}] + +${B}OPTIONS${N} + ${B}-h${N} + Display usage message and exit. + + ${B}-d${N} [${U}ARG${N}] + Perform action on touchpad. + + ${B}-k${N} [${U}ARG${N}] + Perform action on keyboard. + + ${B}-s${N} [${U}ARG${N}] + Perform action on touchscreen. + +${B}ARGS${N} + toggle + Toggle input device / keyboard customizations. + + on + Enable input device / keyboard customizations. + + off + Disable input device / keyboard customizations. +EOF +} + +# If no option is provided +[ "$#" -eq 0 ] && help && exit + +SCRIPT="$(basename "$0")" +# Option handling +while getopts ':h?d:k:s:' opt; do + case $opt in + h) + help + exit + ;; + d) + dev="SYNA3602:00 0911:5288 Touchpad" + ;; + k) + dev="Keyboard" + ;; + s) + dev="pointer:04F3200A:00 04F3:2373" + ;; + :) + 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() { + STATUS=$(xinput --list-props "$dev" | awk '/Device Enabled/ { print $4 }') + [ "$STATUS" -eq 1 ] && xinput --disable "$dev" || xinput --enable "$dev" +} + +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 +} + +shift $((OPTIND - 2)) +# Command handling +if [ "$dev" = "Keyboard" ]; then + keyboard "$1" +else + case "$1" in + toggle) + toggle_device + ;; + on) + xinput --enable "$dev" + ;; + off) + xinput --disable "$dev" + ;; + esac +fi + +# Useful input diagnostics packages: +# - xinput +# - xev +# - evtest +# +# - setxkbmap -query +# - xmodmap -pke +# +# Kernel 5.1.4 works properly on my hardware with the i2c_hid module diff --git a/.scripts/touchscreen.sh b/.scripts/touchscreen.sh deleted file mode 100755 index 97e4247..0000000 --- a/.scripts/touchscreen.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh - -device="04F3200A:00 04F3:2373" -state=$(xinput --list-props "$device" | grep "Device Enabled" | sed -nr 's/.*:\t([0-9])/\1/p') - -if [ "$state" = "0" ] && [ -z "$1" ]; then - xinput --enable "$device" -else - xinput --disable "$device" -fi - diff --git a/etc/modprobe.d/blacklist.conf b/etc/modprobe.d/blacklist.conf index f94fc56..d403887 100644 --- a/etc/modprobe.d/blacklist.conf +++ b/etc/modprobe.d/blacklist.conf @@ -1,5 +1,2 @@ -# Do not load the touchpad module on boot -blacklist i2c_hid - # Disable speck cipher blacklist speck