diff --git a/src/rules/90-hid-mouse.rules b/src/rules/90-hid-mouse.rules index b392d93..37e0e3e 100644 --- a/src/rules/90-hid-mouse.rules +++ b/src/rules/90-hid-mouse.rules @@ -3,7 +3,9 @@ # insertion, removal. Actually, usb events are triggered when usb and # usb interface are binding but hid is more specific and happen once for each # action. change action is not used because -SUBSYSTEM=="hid", ACTION=="bind", RUN+="/usr/local/bin/changemouse.py" +# XAUTHORUTY and DISPLAY must be set and related to the current session. It may +# vary with different graphic drivers. +SUBSYSTEM=="hid", ENV{DISPLAY}=":0", ENV{XAUTHORITY}="/run/user/1000/gdm/Xauthority", ACTION=="bind", RUN+="/usr/local/bin/changemouse.py" # the following line may not be needed as when we unplug a mouse it would # automatically remove devices from the list and they need no furthur diff --git a/src/scripts/python/util/x.py b/src/scripts/python/util/x.py index 8fd0c6f..8457433 100644 --- a/src/scripts/python/util/x.py +++ b/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: