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
73 lines
1.8 KiB
2 years ago
|
import subprocess
|
||
2 years ago
|
from typing import List
|
||
|
from multipledispatch import dispatch
|
||
2 years ago
|
|
||
|
ENCODING = 'utf-8'
|
||
|
|
||
2 years ago
|
|
||
2 years ago
|
@dispatch()
|
||
2 years ago
|
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)
|
||
2 years ago
|
|
||
|
|
||
|
@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)
|
||
2 years ago
|
|
||
2 years ago
|
if completed.returncode == 0:
|
||
|
return completed.stdout.decode(ENCODING)
|
||
|
else:
|
||
|
ValueError(f'id[{id}] is not registered')
|
||
|
|
||
|
|
||
2 years ago
|
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
|
||
|
|
||
|
|
||
2 years ago
|
def get_ids() -> List[int]:
|
||
|
"""returns list of ids registered in xinput"""
|
||
|
completed = subprocess.run(
|
||
|
['xinput', '--list', '--id-only'], capture_output=True)
|
||
2 years ago
|
return list(map(int, completed.stdout.decode(ENCODING).split()))
|
||
2 years ago
|
|
||
|
|
||
|
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
|