2025-04-22 10:25:55 +10:00
|
|
|
-- SPDX-License-Identifier: MIT
|
|
|
|
|
--
|
|
|
|
|
-- This plugin implements a very simple version of disable-while-typing.
|
|
|
|
|
-- It monitors all keyboard devices and if any of them send an event,
|
|
|
|
|
-- any touchpad device is disabled for 2 seconds.
|
|
|
|
|
-- And "disabled" means any event from that touchpad is simply
|
|
|
|
|
-- discarded.
|
|
|
|
|
--
|
|
|
|
|
-- Install this file in /etc/libinput/plugins and
|
|
|
|
|
--
|
|
|
|
|
-- UNCOMMENT THIS LINE TO ACTIVATE THE PLUGIN
|
|
|
|
|
-- libinput:register({1})
|
|
|
|
|
|
|
|
|
|
tp_enabled = true
|
|
|
|
|
|
2025-10-23 09:59:56 +10:00
|
|
|
libinput:connect("timer-expired", function(now)
|
2025-10-27 15:29:37 +10:00
|
|
|
libinput:log_debug("touchpad enabled")
|
2025-04-22 10:25:55 +10:00
|
|
|
tp_enabled = true
|
|
|
|
|
end)
|
|
|
|
|
|
2025-10-23 09:59:56 +10:00
|
|
|
libinput:connect("new-evdev-device", function (device)
|
2025-04-22 10:25:55 +10:00
|
|
|
local props = device:udev_properties()
|
|
|
|
|
if props.ID_INPUT_KEYBOARD then
|
2025-10-23 09:59:56 +10:00
|
|
|
device:connect("evdev-frame", function (device, frame, timestamp)
|
2025-04-22 10:25:55 +10:00
|
|
|
libinput:timer_set_relative(2000000)
|
|
|
|
|
if tp_enabled then
|
2025-10-27 15:29:37 +10:00
|
|
|
libinput:log_debug("touchpad disabled")
|
2025-04-22 10:25:55 +10:00
|
|
|
tp_enabled = false
|
|
|
|
|
end
|
|
|
|
|
end)
|
|
|
|
|
elseif props.ID_INPUT_TOUCHPAD then
|
2025-10-27 15:29:37 +10:00
|
|
|
libinput:log_debug("Touchpad detected: " .. device:name())
|
2025-10-23 09:59:56 +10:00
|
|
|
device:connect("evdev-frame", function (device, frame, timestamp)
|
2025-04-22 10:25:55 +10:00
|
|
|
if not tp_enabled then
|
|
|
|
|
-- Returning an empty table discards the event.
|
|
|
|
|
return {}
|
|
|
|
|
end
|
|
|
|
|
end)
|
|
|
|
|
end
|
|
|
|
|
end)
|