From 9237d7e38532698d71bd614134570621e9e48ca4 Mon Sep 17 00:00:00 2001 From: vincent Date: Sun, 13 Sep 2020 16:19:25 +0200 Subject: [PATCH] add script xinput --- script/script/xinput.py | 44 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100755 script/script/xinput.py diff --git a/script/script/xinput.py b/script/script/xinput.py new file mode 100755 index 0000000..3b2bdb5 --- /dev/null +++ b/script/script/xinput.py @@ -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) +