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. 20
      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__":
"""Configure Pointers
Execution time: 200ms avg -> Tolarable
Execution time: 140ms avg -> Tolarable
"""
v_core, touch_master, e_galax, pointers = putil.get_pointers_categorized()
if e_galax:
xutil.reattach(e_galax.id, touch_master.id)
else:
# TODO: disable touch?
pass
for p in pointers:
xutil.reattach(p.id, v_core.id)

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

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

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

@ -1,5 +1,4 @@
import subprocess
from typing import List
from multipledispatch import dispatch
from pathlib import Path
@ -17,7 +16,7 @@ def get_list_short():
@dispatch(int)
def get_list_short(id):
def get_list_short_with(id):
"""Short List of the id
Args:
@ -53,7 +52,7 @@ def reattach(id, master):
return completed.returncode
def get_ids() -> List[int]:
def get_ids():
"""returns list of ids registered in xinput"""
completed = subprocess.run(
["xinput", "--list", "--id-only"], capture_output=True

Loading…
Cancel
Save