Browse Source

Add get_pointers_categorized

This function will filtered pointers for EZ useage in changemouse script
pull/2/head
Ali Hatami Tajik 2 years ago
parent
commit
61c1f6aa7e
  1. 67
      src/scripts/python/util/pointer.py

67
src/scripts/python/util/pointer.py

@ -42,6 +42,9 @@ class Pointer(XInput):
def __init__(self, name, id, state) -> None:
super().__init__(name, id, state)
def __repr__(self) -> str:
return f"<Pointer: {self.name}-{self.id}-{self.state}"
@property
def slave(self):
return self.state == XInputState.SLAVE
@ -132,3 +135,67 @@ def get_pointers(is_short=True):
for pointer in get_pointer_iter(is_short):
pointers.append(pointer)
return pointers
def create_touch_master():
"""_summary_
Raises:
SystemError: If creation of touch pointer failed
Returns:
Pointer: pointer object corresponding to `touch` master
"""
touch = None
xutil.create_master("touch")
id = xutil.get_xi_id_by_name("touch pointer")
if id:
try:
touch = get_short_pointer(id)
except:
raise SystemError(
"touch pointer is not available. cannot create touch pointer"
)
else:
raise SystemError(
"touch pointer is not available. cannot create touch pointer"
)
# TODO configure cursor bitmap
return touch
def get_pointers_categorized():
"""Categorized Pointers
Categories:
1. VCore: Pointer
2. Touch Master: Pointer
3. eGalax: Pointer | None
4. Other non-masters: List[Pinter]
Raises:
SystemError: If creation of touch pointer failed
Returns:
"""
v_core = None
touch = None
e_galax = None
pointers = []
# filter pointers
for pointer in get_pointer_iter():
if pointer.name == "Virtual core pointer":
v_core = pointer
elif "eGalax" in pointer.name:
e_galax = pointer
elif pointer.name == "touch pointer":
touch = pointer
elif not pointer.master:
pointers.append(pointer)
if not touch:
touch = create_touch_master()
return v_core, touch, e_galax, pointers

Loading…
Cancel
Save