2018-08-22 03:18:25 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -o errexit
|
2023-01-23 15:48:07 +00:00
|
|
|
set -o pipefail
|
2018-08-22 03:18:25 +00:00
|
|
|
|
|
|
|
main() {
|
2023-01-23 15:48:07 +00:00
|
|
|
export RUNNING_AS="${RUNNING_AS:-dan}"
|
|
|
|
RUNNING_AS_ID="$(id -u "${RUNNING_AS}")"
|
|
|
|
export RUNNING_AS_ID
|
2018-08-22 04:16:46 +00:00
|
|
|
|
2023-01-23 15:48:07 +00:00
|
|
|
export XINPUT_EXE="${XINPUT_EXE:=xinput}"
|
|
|
|
export XAUTHORITY="/run/user/${RUNNING_AS_ID}/gdm/Xauthority"
|
2018-08-22 04:16:46 +00:00
|
|
|
export DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/${RUNNING_AS_ID}/bus"
|
2023-01-23 15:48:07 +00:00
|
|
|
: "${DISPLAY:=0}"
|
|
|
|
export DISPLAY
|
2018-08-22 04:16:46 +00:00
|
|
|
export HOME="/home/${RUNNING_AS}"
|
|
|
|
|
2018-10-11 14:47:25 +00:00
|
|
|
|
2018-08-22 04:16:46 +00:00
|
|
|
local device_id
|
|
|
|
device_id="$(__get_device_id)"
|
2018-08-22 03:18:25 +00:00
|
|
|
|
2018-10-11 14:47:25 +00:00
|
|
|
local natscroll_enabled
|
|
|
|
natscroll_enabled="$(
|
|
|
|
__get_prop_id "${device_id}" 'Natural Scrolling Enabled'
|
|
|
|
)"
|
|
|
|
|
|
|
|
local scrollmeth_enabled
|
|
|
|
scrollmeth_enabled="$(
|
|
|
|
__get_prop_id "${device_id}" 'Scroll Method Enabled'
|
|
|
|
)"
|
2018-08-22 03:18:25 +00:00
|
|
|
|
2023-01-23 15:48:07 +00:00
|
|
|
local scrollbutton
|
|
|
|
scrollbutton="$(
|
|
|
|
__get_prop_id "${device_id}" 'Button Scrolling Button'
|
|
|
|
)"
|
|
|
|
|
2018-10-11 14:47:25 +00:00
|
|
|
__run_xinput_as set-prop "${device_id}" "${natscroll_enabled}" 1
|
|
|
|
__run_xinput_as set-prop "${device_id}" "${scrollmeth_enabled}" 0 0 1
|
2023-01-23 15:48:07 +00:00
|
|
|
__run_xinput_as set-prop "${device_id}" "${scrollbutton}" 8
|
2018-08-22 04:16:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
__get_device_id() {
|
2018-10-11 14:47:25 +00:00
|
|
|
__run_xinput_as list |
|
2018-08-22 04:16:46 +00:00
|
|
|
awk '/Logitech USB Trackball/ { sub(/id=/, "", $6); print $6 }'
|
2018-08-22 03:18:25 +00:00
|
|
|
}
|
|
|
|
|
2018-10-11 14:47:25 +00:00
|
|
|
__get_prop_id() {
|
|
|
|
local device_id="${1}"
|
|
|
|
local propmatch="${2}"
|
|
|
|
__run_xinput_as list-props "${device_id}" |
|
|
|
|
awk -F: '/'"${propmatch}"' \([0-9]+\)/ {
|
|
|
|
sub(/.+\(/, "", $1);
|
|
|
|
sub(/\).*/, "", $1);
|
|
|
|
print $1;
|
|
|
|
}'
|
|
|
|
}
|
|
|
|
|
|
|
|
__run_xinput_as() {
|
|
|
|
sudo -E -u "${RUNNING_AS}" "${XINPUT_EXE}" "${@}"
|
|
|
|
}
|
|
|
|
|
2018-08-22 03:18:25 +00:00
|
|
|
main "${@}"
|