From f1237d72e1966212e2d832f160babf6e81cfa09c Mon Sep 17 00:00:00 2001 From: Ali Hatami Tajik Date: Sat, 11 Mar 2023 16:19:23 +0330 Subject: [PATCH] Add get_xi_id_by_name --- src/scripts/python/util/x.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/scripts/python/util/x.py b/src/scripts/python/util/x.py index d07f72c..358e0e2 100644 --- a/src/scripts/python/util/x.py +++ b/src/scripts/python/util/x.py @@ -72,6 +72,22 @@ def create_master(name: str = "touch"): return completed.returncode +def get_xi_id_by_name(name): + """find device id from name + + Args: + name (str): name of the device + """ + completed = subprocess.run( + ["xinput list --id-only", name], capture_output=True + ) + + if completed.returncode == 1: + return -1 + else: + int(completed.stdout.decode(ENCODING)) + + def map_to_output(output, device_id): # TODO pass