Browse Source

Merge branch 'input' into monitor-support

monitor-support
Ali Hatami Tajik 2 years ago
parent
commit
caa38b4a86
  1. 4
      src/rules/90-hid-mouse.rules
  2. 21
      src/scripts/python/util/x.py

4
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

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

@ -1,14 +1,23 @@
import subprocess
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()
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)
@ -23,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:
@ -43,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
@ -52,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()))
@ -63,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
@ -75,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