2019-03-23 14:11:21 +01:00
|
|
|
#! /usr/bin/env python3
|
|
|
|
"""Grabs the respective device to discard any input from it."""
|
|
|
|
|
|
|
|
from configparser import ConfigParser
|
2019-03-23 15:22:09 +01:00
|
|
|
from contextlib import suppress
|
2019-03-23 14:11:21 +01:00
|
|
|
from subprocess import run
|
2019-03-23 15:22:09 +01:00
|
|
|
from threading import Thread
|
2019-03-23 14:11:21 +01:00
|
|
|
|
|
|
|
|
|
|
|
CONFIG_FILE = '/etc/tablet-mode.conf'
|
|
|
|
EVTEST = '/usr/bin/evtest'
|
|
|
|
|
|
|
|
|
|
|
|
def grab_device(device):
|
|
|
|
"""Grabs the respective device via evtest."""
|
|
|
|
|
|
|
|
return run((EVTEST, '--grab', device))
|
|
|
|
|
|
|
|
|
2019-03-23 15:22:09 +01:00
|
|
|
def get_devices():
|
2019-03-23 14:11:21 +01:00
|
|
|
"""Reads the device from the config file."""
|
|
|
|
|
|
|
|
parser = ConfigParser()
|
|
|
|
parser.read(CONFIG_FILE)
|
2019-03-23 15:22:09 +01:00
|
|
|
|
|
|
|
with suppress(KeyError):
|
|
|
|
yield parser['Devices']['keyboard']
|
|
|
|
|
|
|
|
with suppress(KeyError):
|
|
|
|
yield parser['Devices']['touchpad']
|
|
|
|
|
|
|
|
|
|
|
|
def disable_devices(devices):
|
|
|
|
"""Disables the given devices."""
|
|
|
|
|
|
|
|
threads = []
|
|
|
|
|
|
|
|
for device in devices:
|
|
|
|
thread = Thread(target=grab_device, args=[device])
|
|
|
|
threads.append(thread)
|
|
|
|
thread.start()
|
|
|
|
|
|
|
|
for thread in threads:
|
|
|
|
thread.join()
|
2019-03-23 14:11:21 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2019-03-23 15:22:09 +01:00
|
|
|
disable_devices(get_devices())
|