Added touchpad option.
This commit is contained in:
parent
5842c737cb
commit
4fcfc4c57f
2 changed files with 27 additions and 5 deletions
|
@ -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`:
|
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
|
keyboard = /dev/input/by-path/platform-i8042-serio-0-event-kbd
|
||||||
|
touchpad = /dev/input/by-path/platform-i8042-serio-1-event-mouse
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
|
27
tablet-mode
27
tablet-mode
|
@ -2,7 +2,9 @@
|
||||||
"""Grabs the respective device to discard any input from it."""
|
"""Grabs the respective device to discard any input from it."""
|
||||||
|
|
||||||
from configparser import ConfigParser
|
from configparser import ConfigParser
|
||||||
|
from contextlib import suppress
|
||||||
from subprocess import run
|
from subprocess import run
|
||||||
|
from threading import Thread
|
||||||
|
|
||||||
|
|
||||||
CONFIG_FILE = '/etc/tablet-mode.conf'
|
CONFIG_FILE = '/etc/tablet-mode.conf'
|
||||||
|
@ -15,13 +17,32 @@ def grab_device(device):
|
||||||
return run((EVTEST, '--grab', device))
|
return run((EVTEST, '--grab', device))
|
||||||
|
|
||||||
|
|
||||||
def get_device():
|
def get_devices():
|
||||||
"""Reads the device from the config file."""
|
"""Reads the device from the config file."""
|
||||||
|
|
||||||
parser = ConfigParser()
|
parser = ConfigParser()
|
||||||
parser.read(CONFIG_FILE)
|
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__':
|
if __name__ == '__main__':
|
||||||
grab_device(get_device())
|
disable_devices(get_devices())
|
||||||
|
|
Loading…
Reference in a new issue