|
|
@ -1,8 +1,9 @@ |
|
|
|
import subprocess |
|
|
|
from typing import List |
|
|
|
from multipledispatch import dispatch |
|
|
|
from pathlib import Path |
|
|
|
|
|
|
|
ENCODING = 'utf-8' |
|
|
|
ENCODING = "utf-8" |
|
|
|
|
|
|
|
|
|
|
|
@dispatch() |
|
|
@ -10,7 +11,8 @@ 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) |
|
|
|
["xinput", "--list", "--short"], capture_output=True |
|
|
|
) |
|
|
|
return completed.stdout.decode(ENCODING) |
|
|
|
|
|
|
|
|
|
|
@ -25,12 +27,13 @@ def get_list_short(id): |
|
|
|
ValueError: in case of id not found in devices |
|
|
|
""" |
|
|
|
completed = subprocess.run( |
|
|
|
['xinput', '--list', '--short', str(id)], capture_output=True) |
|
|
|
["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') |
|
|
|
ValueError(f"id[{id}] is not registered") |
|
|
|
|
|
|
|
|
|
|
|
def reattach(id, master): |
|
|
@ -44,7 +47,8 @@ def reattach(id, master): |
|
|
|
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) |
|
|
|
["xinput", "--reattach", str(id), str(master)], capture_output=True |
|
|
|
) |
|
|
|
|
|
|
|
return completed.returncode |
|
|
|
|
|
|
@ -52,22 +56,22 @@ def reattach(id, master): |
|
|
|
def get_ids() -> List[int]: |
|
|
|
"""returns list of ids registered in xinput""" |
|
|
|
completed = subprocess.run( |
|
|
|
['xinput', '--list', '--id-only'], capture_output=True) |
|
|
|
["xinput", "--list", "--id-only"], capture_output=True |
|
|
|
) |
|
|
|
return list(map(int, completed.stdout.decode(ENCODING).split())) |
|
|
|
|
|
|
|
|
|
|
|
def create_master(name: str = 'touch'): |
|
|
|
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] |
|
|
|
) |
|
|
|
|
|
|
|
completed = subprocess.run(["xinput create-master", name]) |
|
|
|
|
|
|
|
return completed.returncode |
|
|
|
|
|
|
|
|
|
|
|
def map_to_output(output, device_id): |
|
|
|
pass |
|
|
|
# TODO |
|
|
|
pass |
|
|
|