Skip to content

Instantly share code, notes, and snippets.

@nudomarinero
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nudomarinero/c0ee5f6cab5202fc47d9 to your computer and use it in GitHub Desktop.
Save nudomarinero/c0ee5f6cab5202fc47d9 to your computer and use it in GitHub Desktop.
Toggle on and off the touch screen in a Dell XPS 13 with Linux
#!/usr/bin/env python
from __future__ import print_function
from subprocess import check_output, check_call
device_name = "Synaptics Large Touch Screen"
def get_device_number():
"""
Get the device number of the device using xinput.
If the device is not found the returned device number
is 0.
"""
device_number = 0
out = check_output("xinput list", shell=True)
for line in out.split("\n"):
if device_name in line:
i = line.index("id=")
device_number = int(line[i+3:].split("\t")[0])
break
return device_number
def get_ts_state(device_number):
"""
Get the state of the device defined by device_number.
If the device is enabled the output is 1, if it is
disabled the output is 0.
"""
enabled = 1
out = check_output("xinput list-props %i"%device_number, shell=True)
#print(out)
for line in out.split("\n"):
if "Device Enabled" in line:
i = line.index(":")
enabled = int(line[i+1:])
return enabled
def toggle_state(device_number):
"""
Toggle the state of the device given by device_number
using xinput.
"""
enabled = get_ts_state(dn)
new_state = (enabled+1) % 2
#print(new_state)
out = check_call('xinput set-prop %i "Device Enabled" %1i'
%(device_number, new_state),
shell=True)
# Check if there was any error
if __name__ == "__main__":
dn = get_device_number()
toggle_state(dn)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment