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