84 lines · 2.4 KB · executable
#!/usr/bin/env bash
set -euo pipefail

# Install a local udev hwdb override that marks the ASUS GZ302EA detachable
# touchpad as internal so libinput enables disable-while-typing.
#
# Idempotent: exits early if the hwdb file is already installed with the
# expected contents and every detected touchpad is tagged as internal.

DEST="/etc/udev/hwdb.d/71-touchpad-local.hwdb"

read -r -d '' HWDB <<'EOF' || true
# Local touchpad integration overrides. Managed by
# scripts/install-touchpad-quirk in the dotfiles repo; edits here will be
# overwritten the next time the script runs.

# ASUS ROG Flow Z13 2025 (GZ302EA) detachable keyboard/touchpad.
# Lives on USB but is the laptop's only touchpad, so tag it as internal so
# libinput pairs it with the keyboard and enables disable-while-typing.
touchpad:usb:v0b05p1a30:*
 ID_INPUT_TOUCHPAD_INTEGRATION=internal
EOF

# Check whether the setup is already in the desired state.
already_set_up() {
	[[ -f "$DEST" ]] || return 1
	[[ "$(cat "$DEST")" == "$HWDB" ]] || return 1

	local found=0
	for ev in /dev/input/event*; do
		udevadm info "$ev" 2>/dev/null | grep -q "ID_INPUT_TOUCHPAD=1" || continue
		found=1
		udevadm info "$ev" 2>/dev/null |
			grep -q "ID_INPUT_TOUCHPAD_INTEGRATION=internal" || return 1
	done
	[[ $found -eq 1 ]]
}

if already_set_up; then
	echo "Touchpad quirk already installed and active. Nothing to do."