|
@ -1,8 +1,9 @@ |
|
|
import subprocess |
|
|
import subprocess |
|
|
from typing import List |
|
|
from typing import List |
|
|
from multipledispatch import dispatch |
|
|
from multipledispatch import dispatch |
|
|
|
|
|
from pathlib import Path |
|
|
|
|
|
|
|
|
ENCODING = 'utf-8' |
|
|
ENCODING = "utf-8" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@dispatch() |
|
|
@dispatch() |
|
@ -10,7 +11,8 @@ def get_list_short(): |
|
|
"""Returns string output of the `xinput --list --short` command encoded as |
|
|
"""Returns string output of the `xinput --list --short` command encoded as |
|
|
UTF-8""" |
|
|
UTF-8""" |
|
|
completed = subprocess.run( |
|
|
completed = subprocess.run( |
|
|
['xinput', '--list', '--short'], capture_output=True) |
|
|
["xinput", "--list", "--short"], capture_output=True |
|
|
|
|
|
) |
|
|
return completed.stdout.decode(ENCODING) |
|
|
return completed.stdout.decode(ENCODING) |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -25,12 +27,13 @@ def get_list_short(id): |
|
|
ValueError: in case of id not found in devices |
|
|
ValueError: in case of id not found in devices |
|
|
""" |
|
|
""" |
|
|
completed = subprocess.run( |
|
|
completed = subprocess.run( |
|
|
['xinput', '--list', '--short', str(id)], capture_output=True) |
|
|
["xinput", "--list", "--short", str(id)], capture_output=True |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
if completed.returncode == 0: |
|
|
if completed.returncode == 0: |
|
|
return completed.stdout.decode(ENCODING) |
|
|
return completed.stdout.decode(ENCODING) |
|
|
else: |
|
|
else: |
|
|
ValueError(f'id[{id}] is not registered') |
|
|
ValueError(f"id[{id}] is not registered") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def reattach(id, master): |
|
|
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 :) |
|
|
id is not valid, xinput will not do anything and nothing bad will happen :) |
|
|
""" |
|
|
""" |
|
|
completed = subprocess.run( |
|
|
completed = subprocess.run( |
|
|
['xinput', '--reattach', str(id), str(master)], capture_output=True) |
|
|
["xinput", "--reattach", str(id), str(master)], capture_output=True |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
return completed.returncode |
|
|
return completed.returncode |
|
|
|
|
|
|
|
@ -52,22 +56,22 @@ def reattach(id, master): |
|
|
def get_ids() -> List[int]: |
|
|
def get_ids() -> List[int]: |
|
|
"""returns list of ids registered in xinput""" |
|
|
"""returns list of ids registered in xinput""" |
|
|
completed = subprocess.run( |
|
|
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())) |
|
|
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 |
|
|
"""Creates master with specified name |
|
|
|
|
|
|
|
|
Args: |
|
|
Args: |
|
|
name (str, optional): name of the master. Defaults to 'touch'. |
|
|
name (str, optional): name of the master. Defaults to 'touch'. |
|
|
""" |
|
|
""" |
|
|
completed = subprocess.run( |
|
|
completed = subprocess.run(["xinput create-master", name]) |
|
|
['xinput create-master', name] |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
return completed.returncode |
|
|
return completed.returncode |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def map_to_output(output, device_id): |
|
|
def map_to_output(output, device_id): |
|
|
|
|
|
# TODO |
|
|
pass |
|
|
pass |