various tools I have been using throughout the years
README.md

tpswitch #

Turns the touchpad off and back on. It works in any session because it does not ask X11 or a compositor to do it. It grabs the evdev device instead, so the kernel stops delivering touchpad events to everything else.

Requirements #

Your user needs read access to /dev/input/event*. Either add the user to the input group or grant access with a udev rule:

SUBSYSTEM=="input", ENV{ID_INPUT_TOUCHPAD}=="1", TAG+="uaccess"

Without one of those, disable works only as root.

Usage #

tpswitch          # toggle
tpswitch status   # prints "touchpad enabled" or "touchpad disabled"
tpswitch enable
tpswitch disable

How it works #

disable starts one holder process. The holder grabs every device that reports BTN_TOUCH and INPUT_PROP_POINTER, writes its pid to $XDG_RUNTIME_DIR/tpswitch.pid, confirms the grab with a byte on a pipe, then sleeps in poll().

enable sends the holder SIGTERM. The kernel releases a grab when the descriptors close, so there is no state to reset. If the holder dies for any reason, the touchpad comes back on its own.

Nothing runs while the touchpad is on, and there is no service unit.

Limits #

  • The compositor sees no events while the touchpad is disabled. A drag in progress at that moment is dropped.
  • The state file is per user. A holder started with sudo and one started as your own user are separate, and neither can switch the other off.
  • External touchpads are grabbed too, not only the built-in one.
  • Touchscreens are left alone because they report INPUT_PROP_DIRECT rather than INPUT_PROP_POINTER.

Building #

knit bin/tpswitch   # build into bin/tpswitch
knit deploy/tpswitch # build and install into ~/.local/bin

treefmt formats the C in this directory with clang-format, using the repository .clang-format.