Last active
December 24, 2015 14:09
-
-
Save prehensilecode/6810487 to your computer and use it in GitHub Desktop.
Python script to disable built-in Synaptics trackpad, and set up Apple Magic Trackpad the way I like it
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# vim: set fileencoding=utf-8 : | |
import sys | |
import os | |
import re | |
import subprocess | |
def turn_off_tp(tp_id): | |
subprocess.check_call(["xinput", "--disable", tp_id]) | |
def set_midbutton(): | |
subprocess.check_call(["synclient", "EmulateMidButtonTime=100"]) | |
def set_speed(): | |
subprocess.check_call(["synclient", "MinSpeed=1.65"]) | |
subprocess.check_call(["synclient", "MaxSpeed=6.95"]) | |
subprocess.check_call(["synclient", "AccelFactor=0.04"]) | |
def set_coasting(): | |
subprocess.check_call(["synclient", "CoastingSpeed=3"]) | |
subprocess.check_call(["synclient", "CoastingFriction=12"]) | |
def set_tap(): | |
subprocess.check_call(["synclient", "TapButton1=1"]) | |
subprocess.check_call(["synclient", "TapButton2=3"]) | |
subprocess.check_call(["synclient", "TapButton3=0"]) | |
def set_hysteresis(): | |
subprocess.check_call(["synclient", "HorizHysteresis=125"]) | |
subprocess.check_call(["synclient", "VertHysteresis=125"]) | |
def main(): | |
xinput_out = subprocess.check_output("xinput").split("\n") | |
master_pointer_pat = re.compile(r"XTEST\ pointer") | |
builtin_nipple_pat = re.compile(r"↳\ TPPS") | |
builtin_tp_pat = re.compile(r"↳\ SynPS") | |
#magic_tp_pat = re.compile(r"Apple.*Trackpad") | |
### Ubuntu 14.04 doesn't identify this as an Apple, the name is just blank | |
slave_pointer_pat = re.compile(r"slave\ \ pointer") | |
dev_id_pat = re.compile(r"id=(\d+)") | |
master_pointer = False | |
synps = False | |
nipple = False | |
magictp = False | |
master_pointer_dev_id = None | |
synps_dev_id = None | |
nipple_dev_id = None | |
magictp_dev_id = None | |
for l in xinput_out: | |
if master_pointer_pat.search(l): | |
master_pointer = True | |
master_pointer_dev_id = dev_id_pat.search(l).group(1) | |
continue | |
if builtin_nipple_pat.search(l): | |
nipple = True | |
nipple_dev_id = dev_id_pat.search(l).group(1) | |
continue | |
if builtin_tp_pat.search(l): | |
synps = True | |
synps_dev_id = dev_id_pat.search(l).group(1) | |
continue | |
if slave_pointer_pat.search(l): | |
foo_dev_id = dev_id_pat.search(l).group(1) | |
if foo_dev_id != master_pointer_dev_id and foo_dev_id != nipple_dev_id and foo_dev_id != synps_dev_id: | |
magictp = True | |
magictp_dev_id = foo_dev_id | |
break | |
if synps and magictp: | |
# turn off built-in only if both built-in and magic | |
# trackpad are found | |
print("Turning off built-in touchpad (id=%d)" % (int(synps_dev_id))) | |
turn_off_tp(synps_dev_id) | |
set_midbutton() | |
set_speed() | |
set_coasting() | |
set_tap() | |
set_hysteresis() | |
if __name__ == "__main__": | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment