Browse Source

Remove unneccessary imports

This reduces the overhead of running the script.
pull/2/head
Ali Hatami Tajik 2 years ago
parent
commit
e94fca8ab4
  1. 5
      src/scripts/python/changemouse.py
  2. 18
      src/scripts/python/util/pointer.py
  3. 5
      src/scripts/python/util/x.py

5
src/scripts/python/changemouse.py

@ -34,10 +34,13 @@ import util.x as xutil
if __name__ == "__main__": if __name__ == "__main__":
"""Configure Pointers """Configure Pointers
Execution time: 200ms avg -> Tolarable Execution time: 140ms avg -> Tolarable
""" """
v_core, touch_master, e_galax, pointers = putil.get_pointers_categorized() v_core, touch_master, e_galax, pointers = putil.get_pointers_categorized()
if e_galax: if e_galax:
xutil.reattach(e_galax.id, touch_master.id) xutil.reattach(e_galax.id, touch_master.id)
else:
# TODO: disable touch?
pass
for p in pointers: for p in pointers:
xutil.reattach(p.id, v_core.id) xutil.reattach(p.id, v_core.id)

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

@ -1,8 +1,6 @@
import util.x as xutil import util.x as xutil
from enum import Enum
# Pointer states
class XInputState(Enum):
SLAVE, MASTER, FLOATING = range(3) SLAVE, MASTER, FLOATING = range(3)
@ -46,14 +44,14 @@ class Pointer(XInput):
@property @property
def slave(self): def slave(self):
return self.state == XInputState.SLAVE return self.state == SLAVE
@property @property
def master(self): def master(self):
return self.state == XInputState.MASTER return self.state == MASTER
def floating(self): def floating(self):
return self.state == XInputState.FLOATING return self.state == FLOATING
def get_short_pointer(id) -> Pointer: def get_short_pointer(id) -> Pointer:
@ -69,14 +67,14 @@ def get_short_pointer(id) -> Pointer:
ValueError: if id is not reistered with xinput ValueError: if id is not reistered with xinput
ValueError: if id is not a pointer id ValueError: if id is not a pointer id
""" """
desc = xutil.get_list_short(id) desc = xutil.get_list_short_with(id)
name, props = desc.rsplit("id=", 1) name, props = desc.rsplit("id=", 1)
if "pointer" in props: if "pointer" in props:
state = XInputState.FLOATING state = FLOATING
if "master" in props: if "master" in props:
state = XInputState.MASTER state = MASTER
elif "slave" in props: elif "slave" in props:
state = XInputState.SLAVE state = SLAVE
return Pointer(name.strip(), props.split(maxsplit=1)[0], state) return Pointer(name.strip(), props.split(maxsplit=1)[0], state)
else: else:
raise TypeError(f"id[{id}] is not a pointer id") raise TypeError(f"id[{id}] is not a pointer id")

5
src/scripts/python/util/x.py

@ -1,5 +1,4 @@
import subprocess import subprocess
from typing import List
from multipledispatch import dispatch from multipledispatch import dispatch
from pathlib import Path from pathlib import Path
@ -17,7 +16,7 @@ def get_list_short():
@dispatch(int) @dispatch(int)
def get_list_short(id): def get_list_short_with(id):
"""Short List of the id """Short List of the id
Args: Args:
@ -53,7 +52,7 @@ def reattach(id, master):
return completed.returncode return completed.returncode
def get_ids() -> List[int]: def get_ids():
"""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

Loading…
Cancel
Save