1
0

10-dwt.lua 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. -- SPDX-License-Identifier: MIT
  2. --
  3. -- This plugin implements a very simple version of disable-while-typing.
  4. -- It monitors all keyboard devices and if any of them send an event,
  5. -- any touchpad device is disabled for 2 seconds.
  6. -- And "disabled" means any event from that touchpad is simply
  7. -- discarded.
  8. --
  9. -- Install this file in /etc/libinput/plugins and
  10. --
  11. -- UNCOMMENT THIS LINE TO ACTIVATE THE PLUGIN
  12. -- libinput:register({1})
  13. tp_enabled = true
  14. libinput:connect("timer-expired", function(now)
  15. libinput:log_debug("touchpad enabled")
  16. tp_enabled = true
  17. end)
  18. libinput:connect("new-evdev-device", function (device)
  19. local props = device:udev_properties()
  20. if props.ID_INPUT_KEYBOARD then
  21. device:connect("evdev-frame", function (device, frame, timestamp)
  22. libinput:timer_set_relative(2000000)
  23. if tp_enabled then
  24. libinput:log_debug("touchpad disabled")
  25. tp_enabled = false
  26. end
  27. end)
  28. elseif props.ID_INPUT_TOUCHPAD then
  29. libinput:log_debug("Touchpad detected: " .. device:name())
  30. device:connect("evdev-frame", function (device, frame, timestamp)
  31. if not tp_enabled then
  32. -- Returning an empty table discards the event.
  33. return {}
  34. end
  35. end)
  36. end
  37. end)