Harden live touchpad guard for XInput/libinput (Sam & Codex)
This commit is contained in:
parent
38226a7264
commit
6d010a5a8c
1 changed files with 32 additions and 6 deletions
|
|
@ -17,6 +17,28 @@ prop_id() {
|
|||
awk -F '[()]' -v needle="$_needle" 'index($0, needle) { print $2; exit }'
|
||||
}
|
||||
|
||||
set_prop_values() {
|
||||
_id="$1"
|
||||
_prop="$2"
|
||||
shift 2
|
||||
[ -n "$_prop" ] || return 0
|
||||
xinput set-prop "$_id" "$_prop" "$@" >/dev/null 2>&1 || true
|
||||
}
|
||||
|
||||
set_send_events_enabled() {
|
||||
_id="$1"
|
||||
_props="$2"
|
||||
_prop="$(printf '%s\n' "$_props" | prop_id 'libinput Send Events Mode Enabled (')"
|
||||
[ -n "$_prop" ] || return 0
|
||||
|
||||
# libinput exposes "disabled" modes here; all-zero means "send events".
|
||||
# The tuple width varies, so try the common shapes in descending order.
|
||||
xinput set-prop "$_id" "$_prop" 0 0 0 >/dev/null 2>&1 \
|
||||
|| xinput set-prop "$_id" "$_prop" 0 0 >/dev/null 2>&1 \
|
||||
|| xinput set-prop "$_id" "$_prop" 0 >/dev/null 2>&1 \
|
||||
|| true
|
||||
}
|
||||
|
||||
enable_touchpads_once() {
|
||||
if ! command -v xinput >/dev/null 2>&1; then
|
||||
log "xinput missing; cannot check touchpads"
|
||||
|
|
@ -34,12 +56,16 @@ enable_touchpads_once() {
|
|||
|
||||
xinput enable "$_id" >/dev/null 2>&1 || true
|
||||
_tap_prop="$(printf '%s\n' "$_props" | prop_id 'libinput Tapping Enabled (')"
|
||||
if [ -n "$_tap_prop" ]; then
|
||||
xinput set-prop "$_id" "$_tap_prop" 1 >/dev/null 2>&1 || true
|
||||
fi
|
||||
set_prop_values "$_id" "$_tap_prop" 1
|
||||
_dwt_prop="$(printf '%s\n' "$_props" | prop_id 'libinput Disable While Typing Enabled (')"
|
||||
set_prop_values "$_id" "$_dwt_prop" 0
|
||||
set_send_events_enabled "$_id" "$_props"
|
||||
|
||||
_enabled="$(xinput list-props "$_id" 2>/dev/null | awk -F: '/Device Enabled/ { gsub(/^[[:space:]]+|[[:space:]]+$/, "", $2); print $2; exit }')"
|
||||
log "touchpad ${_name}: Device Enabled=${_enabled:-unknown} tapping_prop=${_tap_prop:-none}"
|
||||
_updated_props="$(xinput list-props "$_id" 2>/dev/null || true)"
|
||||
_enabled="$(printf '%s\n' "$_updated_props" | awk -F: '/Device Enabled/ { gsub(/^[[:space:]]+|[[:space:]]+$/, "", $2); print $2; exit }')"
|
||||
_send_events="$(printf '%s\n' "$_updated_props" | awk -F: '/libinput Send Events Mode Enabled/ { gsub(/^[[:space:]]+|[[:space:]]+$/, "", $2); print $2; exit }')"
|
||||
_dwt_state="$(printf '%s\n' "$_updated_props" | awk -F: '/libinput Disable While Typing Enabled/ { gsub(/^[[:space:]]+|[[:space:]]+$/, "", $2); print $2; exit }')"
|
||||
log "touchpad ${_name}: Device Enabled=${_enabled:-unknown} SendEvents=${_send_events:-unknown} DWT=${_dwt_state:-unknown} tapping_prop=${_tap_prop:-none}"
|
||||
done
|
||||
|
||||
if [ "$_found" -eq 0 ]; then
|
||||
|
|
@ -49,7 +75,7 @@ enable_touchpads_once() {
|
|||
|
||||
# Run multiple times because xfsettingsd and saved-session restoration can
|
||||
# apply pointer settings after the session wrapper starts.
|
||||
for _delay in 1 5 15; do
|
||||
for _delay in 1 5 15 30; do
|
||||
sleep "$_delay"
|
||||
enable_touchpads_once
|
||||
done
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue