6c78b9e9a29df2d8f99ebbe8e90d06f55baf41a8
[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
24
25 set -e; . /usr/local/lib/bash-bear; set +e
26
27 script_name="${0##*/}"
28
29
30 m() { printf "$script_name: %s\n" "$*"; "$@"; }
31
32 ## disabed because unused
33 # ms() {
34 # xinput --set-ptr-feedback "$1" $2 ${3%/*} ${3#*/}
35 # # running newer system that uses libinput and has far less
36 # # customizability. I havent yet determined the best settings here.
37 # if xinput --list-props "$1" | grep "libinput Accel Speed" &>/dev/null; then
38 # m xinput --set-prop "$1" "libinput Accel Speed" 1
39 # else
40 # m xinput --set-prop "$1" 'Device Accel Profile' $4
41 # m xinput --set-prop "$1" 'Device Accel Constant Deceleration' $5
42 # m xinput --set-prop "$1" 'Device Accel Velocity Scaling' $6
43 # fi
44 # xinput --get-feedbacks "$1" | grep "threshold"
45 # xinput --get-feedbacks "$1" | grep "accelNum\|accelDenom"
46 # xinput --list-props "$1"
47 # }
48 # set_device_id() {
49 # if [[ $2 ]] && $2; then
50 # cmd="tail -n1"
51 # else
52 # cmd="head -n1"
53 # fi
54 # if device_id=$(xinput --list | grep "$1" | $cmd); then
55 # device_id=${device_id##*id=}
56 # device_id=${device_id%%[[:space:]]*}
57 # echo "2:$2 device_id=$device_id"
58 # else
59 # return 1
60 # fi
61 # }
62
63 case $1 in
64 l) type=laptop ;;
65 m) type=keyboardio ;;
66 esac
67
68 if [[ ! $type ]]; then
69 if xinput | grep -i keyboardio; then
70 type=keyboardio
71 else
72 type=laptop
73 fi
74 fi
75
76 # start auto-repeat faster, but go slower.
77 #
78 # default via xset q is 660 25. (delay for autorepeat, repeat rate). At
79 # one point I used 200 13, but while learning to use keyboardio, i found
80 # it a bit too fast.
81 m xset r rate 400 13 # decrease rate delay
82
83 # # disabled because i'm not using it atm 2024
84 # if set_device_id "SteelSeries World of Warcraft MMO Gaming Mouse"; then
85 # ms "$device_id" 100 1000/1 7 4 1
86 # # under the new "improved" libinput, the mouse speed/accel has
87 # # changed all around and is much more limited.
88 # # Other xinput commands will fail and this will succeed.
89 # xinput --set-prop "$device_id" "libinput Accel Speed" '.8'
90 # fi
91
92 # todo, differentiate for work pc
93 #/a/bin/radl
94
95 case $type in
96 keyboardio)
97 # at some point, I found the international variant useful:
98 # setxkbmap -layout us -variant intl
99 # xkbcomp $DISPLAY xkbcomp-t9-intl.xkb
100 #
101 # I create these for a new os by comparing the diff with the default
102 # of previous os, then recreating the diff manually on the new
103 # default. the x2 version has changes on top of keyboardio, so
104 # create the keyboardio one first.
105 #
106 # xkbcomp $DISPLAY xkbcomp-t12.xkb
107 # cp xkbcomp-t12.xkb keyboardio-t12.xkb
108 # diff xkbcomp-t9.xkb keyboardio-t9.xkb
109 # g keyboardio-t12.xkb
110 # # finish editing
111 # cp keyboardio-t12.xkb x2-t12.xkb
112 # diff xkbcomp-t9.xkb x2-t9.xkb
113 # g x2-t12.xkb
114 m xkbcomp /a/c/keyboardio-t12.xkb $DISPLAY
115 ;;
116 laptop)
117 m xkbcomp /a/c/x2-t12.xkb $DISPLAY
118 ;;
119 esac
120
121 ## disabled because i'm not using it atm.
122 # for desktop and htpc
123 # if set_device_id "Logitech Unifying Device"; then
124 # xinput --set-prop "$device_id" 'Evdev Middle Button Emulation' 1
125 # fi
126
127 ## slow down ploopy trackball, until we recompile firmware
128 id=$(xinput list | grep -F 'Ploopy Corporation Trackball Mouse' | sed -rn 's/.*[[:space:]]id=([^[:space:]]*).*/\1/p' ||:)
129 if [[ $id ]]; then
130 m xinput --set-prop $id 'libinput Accel Speed' -0.7
131 fi
132
133 exit 0