#!/bin/bash
# mouse-settings
# Applies libinput touchpad tweaks via xinput. Safe to re-run any time
# (e.g. from a keybind) - only touches properties that exist on the
# matched device. Natural scrolling is only set on the touchpad - a
# physical scroll-wheel mouse keeps the traditional (non-natural)
# direction, since reversing that feels backwards on a wheel.
set_prop() {
local device="$1" prop="$2"; shift 2
xinput list-props "$device" 2>/dev/null | grep -qF "$prop" && \
xinput set-prop "$device" "$prop" "$@"
}
xinput list --name-only 2>/dev/null | while IFS= read -r name; do
case "$name" in
*[Tt]ouchpad*)
set_prop "$name" "libinput Natural Scrolling Enabled" 1
set_prop "$name" "libinput Tapping Enabled" 1
set_prop "$name" "libinput Disable While Typing Enabled" 1
;;
esac
done