Ensure that the touchscreen is also turned on/off together with the screen
This commit is contained in:
parent
2acb672e97
commit
4c6f021439
1 changed files with 14 additions and 0 deletions
|
@ -9,6 +9,7 @@ from dbus import SessionBus
|
||||||
from dbus.mainloop.glib import DBusGMainLoop
|
from dbus.mainloop.glib import DBusGMainLoop
|
||||||
|
|
||||||
previous_xrandr = 'xrandr --output DSI-1 --auto'
|
previous_xrandr = 'xrandr --output DSI-1 --auto'
|
||||||
|
xinput_regex = re.compile(r'.*Capacitive TouchScreen\s+id=(\d+).*')
|
||||||
|
|
||||||
|
|
||||||
def get_current_xrandr() -> str:
|
def get_current_xrandr() -> str:
|
||||||
|
@ -16,6 +17,15 @@ def get_current_xrandr() -> str:
|
||||||
return proc.communicate()[0].decode().strip()
|
return proc.communicate()[0].decode().strip()
|
||||||
|
|
||||||
|
|
||||||
|
def get_touchscreen_id() -> int:
|
||||||
|
proc = subprocess.Popen(['xinput'], stdout=subprocess.PIPE)
|
||||||
|
for line in proc.communicate()[0].decode().split('\n'):
|
||||||
|
if m := xinput_regex.match(line):
|
||||||
|
return int(m.group(1))
|
||||||
|
|
||||||
|
assert 'Touchscreen device not found'
|
||||||
|
|
||||||
|
|
||||||
def is_display_on() -> bool:
|
def is_display_on() -> bool:
|
||||||
proc = subprocess.Popen(['xrandr', '-q'], stdout=subprocess.PIPE)
|
proc = subprocess.Popen(['xrandr', '-q'], stdout=subprocess.PIPE)
|
||||||
out = proc.communicate()[0].decode().strip()
|
out = proc.communicate()[0].decode().strip()
|
||||||
|
@ -35,11 +45,15 @@ def signal_handler(name, _):
|
||||||
return
|
return
|
||||||
|
|
||||||
is_on = is_display_on()
|
is_on = is_display_on()
|
||||||
|
touchscreen_id = get_touchscreen_id()
|
||||||
|
|
||||||
if is_on:
|
if is_on:
|
||||||
previous_xrandr = get_current_xrandr()
|
previous_xrandr = get_current_xrandr()
|
||||||
os.system('xrandr --output DSI-1 --off')
|
os.system('xrandr --output DSI-1 --off')
|
||||||
|
os.system(f'xinput disable {touchscreen_id}')
|
||||||
else:
|
else:
|
||||||
os.system(previous_xrandr)
|
os.system(previous_xrandr)
|
||||||
|
os.system(f'xinput enable {touchscreen_id}')
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
Loading…
Reference in a new issue