lots: shellcheck, streaming stuff, fixes
[distro-setup] / input-setup
1 #!/bin/bash
2 # shellcheck source=/a/bin/ds/.bashrc
3 if [[ -s ~/.bashrc ]];then . ~/.bashrc;fi
4 set -x
5 # Copyright (C) 2016 Ian Kelling
6
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
10
11 # http://www.apache.org/licenses/LICENSE-2.0
12
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18
19 type=model01
20
21 case $1 in
22 l) type=laptop ;;
23 m) type=model01 ;;
24 esac
25
26 #set -x
27 mi() {
28 xinput --get-feedbacks "$1" | grep "threshold"
29 xinput --get-feedbacks "$1" | grep "accelNum\|accelDenom"
30 xinput --list-props "$1"
31 }
32 ms() {
33 xinput --set-ptr-feedback "$1" $2 ${3%/*} ${3#*/}
34 # running newer system that uses libinput and has far less
35 # customizability. I havent yet determined the best settings here.
36 if xinput --list-props "$1" | grep "libinput Accel Speed" &>/dev/null; then
37 xinput --set-prop "$1" "libinput Accel Speed" 1
38 else
39 xinput --set-prop "$1" 'Device Accel Profile' $4
40 xinput --set-prop "$1" 'Device Accel Constant Deceleration' $5
41 xinput --set-prop "$1" 'Device Accel Velocity Scaling' $6
42 fi
43 mi "$1"
44 }
45 set_device_id() {
46 if [[ $2 ]] && $2; then
47 cmd="tail -n1"
48 else
49 cmd="head -n1"
50 fi
51 if device_id=$(xinput --list | grep "$1" | $cmd); then
52 device_id=${device_id##*id=}
53 device_id=${device_id%%[[:space:]]*}
54 echo "2:$2 device_id=$device_id"
55 else
56 return 1
57 fi
58 }
59
60 # default via xset q is 660 25. (delay for autorepeat, repeat rate)
61 # was at 200 13, but while learning to use keyboardio, i hold keys a bit longer sometimes.
62 xset r rate 400 13 # decrease rate delay
63
64 if set_device_id "SteelSeries World of Warcraft MMO Gaming Mouse"; then
65 ms "$device_id" 100 1000/1 7 4 1
66
67 # under the new "improved" libinput, the mouse speed/accel has
68 # changed all around and is much more limited.
69 # Other xinput commands will fail and this will succeed.
70 xinput --set-prop "$device_id" "libinput Accel Speed" '.8'
71 fi
72
73 # todo, differentiate for work pc
74 #/a/bin/radl
75
76 case $type in
77 model01)
78 # original saved with:
79 # setxkbmap -layout us -variant intl
80 # xkbcomp $DISPLAY /a/c/etiona-2021-intl.xkb
81 xkbcomp /a/c/model01.xkb $DISPLAY
82 ;;
83 laptop)
84 xkbcomp /a/c/x2.xkb $DISPLAY
85
86 ;;
87 esac
88
89 # for desktop and htpc
90 if set_device_id "Logitech Unifying Device"; then
91 xinput --set-prop "$device_id" 'Evdev Middle Button Emulation' 1
92 fi
93
94 ## slow down ploopy trackball, until we recompile firmware
95 # id=$(xinput list | grep -F 'Ploopy Corporation Trackball Mouse' | sed -rn 's/.*[[:space:]]id=([^[:space:]]*).*/\1/p' ||:)
96 # if [[ $id ]]; then
97 # xinput --set-prop $id 'libinput Accel Speed' -0.9
98 # fi
99
100 set +x
101 exit 0