add script xinput

This commit is contained in:
vincent 2020-09-13 16:19:25 +02:00
parent 179f1af674
commit 9237d7e385

44
script/script/xinput.py Executable file
View File

@ -0,0 +1,44 @@
import re
import subprocess
ENABLE_OPTIONS = [
"libinput Tapping Enabled",
"libinput Natural Scrolling Enabled"
]
DEVICE=14
class XinputDevice (object):
xinputList=b""
def __init__(self,deviceNumber):
deviceNumber=str(deviceNumber)
self.deviceNumber=deviceNumber
self._refresh()
def enable(self,name):
regex="{0} \(([0-9]*)\)".format(name)
bregex=regex.encode('utf-8')
try:
optionNumber=re.findall(bregex,self.xinputList)[0]
except IndexError:
print("option not found")
return
proc=subprocess.Popen(['/usr/bin/xinput','set-prop',self.deviceNumber,optionNumber,'1'])
self._refresh()
def disable(self,name):
regex="{0} \(([0-9]*)\)".format(name)
bregex=regex.encode('utf-8')
try:
optionNumber=re.findall(bregex,self.xinputList)[0]
except IndexError:
print("option not found")
return
proc=subprocess.Popen(['/usr/bin/xinput','set-prop',self.deviceNumber,optionNumber,'0'])
self._refresh()
def _refresh (self):
self.xinputList=subprocess.check_output(['/usr/bin/xinput','list-props',self.deviceNumber])
xinput=XinputDevice(DEVICE)
for option in ENABLE_OPTIONS :
xinput.enable(option)