chuwi-minibook-tablet-mode/tablet-mode
2019-03-23 15:22:09 +01:00

48 lines
1,022 B
Python
Executable file

#! /usr/bin/env python3
"""Grabs the respective device to discard any input from it."""
from configparser import ConfigParser
from contextlib import suppress
from subprocess import run
from threading import Thread
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))
def get_devices():
"""Reads the device from the config file."""
parser = ConfigParser()
parser.read(CONFIG_FILE)
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()
if __name__ == '__main__':
disable_devices(get_devices())