Created
March 28, 2019 09:49
-
-
Save jfunction/1635063f7c3a2a04d572eadd08ea2323 to your computer and use it in GitHub Desktop.
If the axis on your mouse screws up like mine did, you can move it left-right and see the counter-clockwise rotation required to make it horizontal, then up-down and see that rotation (degrees) then pass those to this script to get a linux cmd which will transform it accordingly.
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/python3.7 | |
from math import sin, cos, pi | |
import subprocess | |
import sys | |
skew_x_axis=int(sys.argv[1]) | |
skew_y_axis=int(sys.argv[2]) # if when you move your mouse up it moves up and to the right leaving 10 degrees drift from the y axis, write 10 here | |
c=pi/180. | |
def get_rotation_matrix(xt, yt): | |
return '%5f %.5f 0.00000 %5f %.5f 0.00000 0.00000 0.00000 1.00000' % (cos(c*xt), sin(c*yt), -sin(c*xt), cos(c*yt)) | |
def get_device_name(): | |
xinput_list = subprocess.check_output('xinput list', shell=True).decode('utf').split('\n') | |
mice = [line for line in xinput_list if 'Mouse' in line] | |
if len(mice) == 0: | |
print("Could not find a mouse in the xinput list, modify this method to return the relevant id from the following:", output) | |
raise(ValueError("This program will exit now")) | |
if len(mice)>1: | |
print("WARNING: You seem to have multiple mice. You'll need to pick the relevant id. We'll just take the first one we found though.") | |
dname = mice[0].split('id=')[1].split()[0] | |
device_name = int(dname) | |
return device_name | |
transformed_coords = get_rotation_matrix(skew_x_axis, skew_y_axis) | |
device_name = get_device_name() | |
cmd=f"xinput set-prop '{device_name}' 'Coordinate Transformation Matrix' {transformed_coords}" | |
print(cmd) | |
if 'y' in input('ok? ').lower(): | |
subprocess.check_output(cmd, shell=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment