From 4fcfc4c57f8ed2b7cc12ab7d890f82dd11f78b00 Mon Sep 17 00:00:00 2001 From: Richard Neumann Date: Sat, 23 Mar 2019 15:22:09 +0100 Subject: [PATCH] Added touchpad option. --- README.md | 5 +++-- tablet-mode | 27 ++++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index af717df..de5a07e 100644 --- a/README.md +++ b/README.md @@ -6,10 +6,11 @@ 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 -You must be a member of the group `tablet` to toggle between tablet and laptop mode. +You must be a member of the group `tablet` to toggle between tablet and laptop mode. You can toggle between tablet and laptop mode by running `toggle-tablet-mode` or use the desktop icon provided with this package. diff --git a/tablet-mode b/tablet-mode index 5895387..d4b5c82 100755 --- a/tablet-mode +++ b/tablet-mode @@ -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())