Browse Source

Stage chenges of x module

fix-xinput-stdout
Ali Hatami Tajik 2 years ago
parent
commit
a14c9e5cb2
  1. 24
      src/scripts/python/util/x.py

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

@ -1,21 +1,27 @@
import subprocess
from multipledispatch import dispatch
from pathlib import Path
import os
ENCODING = "utf-8"
XINPUT = "/ust/bin/xinput"
def exec_xinput(args: list):
args.insert(0, XINPUT)
_read, _write = os.pipe()
write_fd = os.fdopen(_write, "w", 0)
os.read()
@dispatch()
def get_list_short():
"""Returns string output of the `xinput --list --short` command encoded as
UTF-8"""
completed = subprocess.run(
["xinput", "--list", "--short"], capture_output=True
[XINPUT, "--list", "--short"], capture_output=True
)
return completed.stdout.decode(ENCODING)
@dispatch(int)
def get_list_short_with(id):
"""Short List of the id
@ -26,7 +32,7 @@ def get_list_short_with(id):
ValueError: in case of id not found in devices
"""
completed = subprocess.run(
["xinput", "--list", "--short", str(id)], capture_output=True
[XINPUT, "--list", "--short", str(id)], capture_output=True
)
if completed.returncode == 0:
@ -46,7 +52,7 @@ def reattach(id, master):
id is not valid, xinput will not do anything and nothing bad will happen :)
"""
completed = subprocess.run(
["xinput", "--reattach", str(id), str(master)], capture_output=True
[XINPUT, "--reattach", str(id), str(master)], capture_output=True
)
return completed.returncode
@ -55,7 +61,7 @@ def reattach(id, master):
def get_ids():
"""returns list of ids registered in xinput"""
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()))
@ -66,7 +72,7 @@ def create_master(name: str = "touch"):
Args:
name (str, optional): name of the master. Defaults to 'touch'.
"""
completed = subprocess.run(["xinput", "create-master", name])
completed = subprocess.run([XINPUT, "create-master", name])
return completed.returncode
@ -78,7 +84,7 @@ def get_xi_id_by_name(name):
name (str): name of the device
"""
completed = subprocess.run(
["xinput", "list", "--id-only", name], capture_output=True
[XINPUT, "list", "--id-only", name], capture_output=True
)
if completed.returncode == 1:

Loading…
Cancel
Save