Essential files and manual for OS configuration on sonography
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
1.8 KiB

import subprocess
from typing import List
from multipledispatch import dispatch
ENCODING = 'utf-8'
@dispatch()
def get_list_short():
"""Returns string output of the `xinput --list --short` command encoded as
UTF-8"""
completed = subprocess.run(
['xinput', '--list', '--short'], capture_output=True)
return completed.stdout.decode(ENCODING)
@dispatch(int)
def get_list_short(id):
"""Short List of the id
Args:
id (int): id registered in xinput
Rises:
ValueError: in case of id not found in devices
"""
completed = subprocess.run(
['xinput', '--list', '--short', str(id)], capture_output=True)
if completed.returncode == 0:
return completed.stdout.decode(ENCODING)
else:
ValueError(f'id[{id}] is not registered')
def reattach(id, master):
"""Reattach a device to a master
Args:
id (str|int): name of the slave or id
master (_type_): _description_
TODO: Error handling should be done. BUT, if the master is not a master or
id is not valid, xinput will not do anything and nothing bad will happen :)
"""
completed = subprocess.run(
['xinput', '--reattach', str(id), str(master)], capture_output=True)
return completed.returncode
def get_ids() -> List[int]:
"""returns list of ids registered in xinput"""
completed = subprocess.run(
['xinput', '--list', '--id-only'], capture_output=True)
return list(map(int, completed.stdout.decode(ENCODING).split()))
def create_master(name: str = 'touch'):
"""Creates master with specified name
Args:
name (str, optional): name of the master. Defaults to 'touch'.
"""
completed = subprocess.run(
['xinput create-master', name]
)
return completed.returncode
def map_to_output(output, device_id):
pass