File: 10-dwt.lua

package info (click to toggle)
libinput 1.30.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,404 kB
  • sloc: ansic: 104,881; python: 3,570; sh: 183; makefile: 37; cpp: 7
file content (40 lines) | stat: -rw-r--r-- 1,328 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
-- 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

libinput:connect("timer-expired", function(now)
    libinput:log_debug("touchpad enabled")
    tp_enabled = true
end)

libinput:connect("new-evdev-device", function (device)
    local props = device:udev_properties()
    if props.ID_INPUT_KEYBOARD then
        device:connect("evdev-frame", function (device, frame, timestamp)
            libinput:timer_set_relative(2000000)
            if tp_enabled then
                libinput:log_debug("touchpad disabled")
                tp_enabled = false
            end
        end)
    elseif props.ID_INPUT_TOUCHPAD then
        libinput:log_debug("Touchpad detected: " .. device:name())
        device:connect("evdev-frame", function (device, frame, timestamp)
            if not tp_enabled then
                -- Returning an empty table discards the event.
                return {}
            end
        end)
    end
end)