|
@ -36,3 +36,56 @@ class Pointer(XInput): |
|
|
def __init__(self, name, id, is_master: bool) -> None: |
|
|
def __init__(self, name, id, is_master: bool) -> None: |
|
|
super().__init__(name, id, is_master) |
|
|
super().__init__(name, id, is_master) |
|
|
|
|
|
|
|
|
|
|
|
def get_short_pointer(id) -> Pointer: |
|
|
|
|
|
"""Generates Pointer object corresponding to id (short attrs) |
|
|
|
|
|
|
|
|
|
|
|
Args: |
|
|
|
|
|
id (int): pointer id |
|
|
|
|
|
|
|
|
|
|
|
Returns: |
|
|
|
|
|
Pointer: pointer object with name, id and is_master props |
|
|
|
|
|
|
|
|
|
|
|
Rises: |
|
|
|
|
|
ValueError: if id is not reistered with xinput |
|
|
|
|
|
ValueError: if id is not a pointer id |
|
|
|
|
|
""" |
|
|
|
|
|
desc = com.get_list_short(id) |
|
|
|
|
|
name, props = desc.rsplit('id=', 1) |
|
|
|
|
|
if "pointer" in props: |
|
|
|
|
|
is_master = "master" in props |
|
|
|
|
|
return Pointer( |
|
|
|
|
|
name.strip(), |
|
|
|
|
|
props.split(maxsplit=1), |
|
|
|
|
|
is_master) |
|
|
|
|
|
else: |
|
|
|
|
|
raise TypeError(f'id[{id}] is not a pointer id') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_pointers(is_short=True): |
|
|
|
|
|
"""Wraps pointers in `xinput --list` in Pointer class |
|
|
|
|
|
|
|
|
|
|
|
Creation of the pointer is done by getting the list description of |
|
|
|
|
|
each id. if the is_short arg is True, then short list description will be |
|
|
|
|
|
used which will provide the class `name`, `is_master` and `id` values. |
|
|
|
|
|
|
|
|
|
|
|
Getting this pointers is done by first calling `xinput --list --id-only` to |
|
|
|
|
|
get ids and then execute `xinput --list {id}` to get the description with |
|
|
|
|
|
less-complicated output compare to iterating over `xinput --list --short` |
|
|
|
|
|
line by line (--short option has some special characters that cause overhead |
|
|
|
|
|
to the system for processing them individually and per-case). |
|
|
|
|
|
""" |
|
|
|
|
|
pointers = [] |
|
|
|
|
|
ids = com.get_ids() |
|
|
|
|
|
for id in ids: |
|
|
|
|
|
if is_short: |
|
|
|
|
|
try: |
|
|
|
|
|
pointers.append(get_short_pointer(id)) |
|
|
|
|
|
except TypeError as e: |
|
|
|
|
|
# ignore if the id is not pointer |
|
|
|
|
|
pass |
|
|
|
|
|
except e: |
|
|
|
|
|
# TODO: logging |
|
|
|
|
|
pass |
|
|
|
|
|
else: |
|
|
|
|
|
pass |
|
|
|
|
|
return pointers |
|
|