Added touchpad option.

This commit is contained in:
Richard Neumann 2019-03-23 15:22:09 +01:00
parent 5842c737cb
commit 4fcfc4c57f
2 changed files with 27 additions and 5 deletions

View file

@ -6,8 +6,9 @@ Allow users to toggle a convertible laptop between laptop and tablet mode.
The keyboard device to be deactivated in tablet mode must be specified in `/etc/tablet-mode.conf`:
[Device]
[Devices]
keyboard = /dev/input/by-path/platform-i8042-serio-0-event-kbd
touchpad = /dev/input/by-path/platform-i8042-serio-1-event-mouse
## Usage

View file

@ -2,7 +2,9 @@
"""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'
@ -15,13 +17,32 @@ def grab_device(device):
return run((EVTEST, '--grab', device))
def get_device():
def get_devices():
"""Reads the device from the config file."""
parser = ConfigParser()
parser.read(CONFIG_FILE)
return parser['Device']['keyboard']
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__':
grab_device(get_device())
disable_devices(get_devices())