Forked from yinonburgansky/windows-acceleration-function.py
Created
November 20, 2022 15:40
-
-
Save alexhorner/863982f78d7981128613e0c7ae4552cd to your computer and use it in GitHub Desktop.
windows acceleration function
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
# calculation are based on http://www.esreality.com/index.php?a=post&id=1945096 | |
# assuming windows 10 uses the same calculation as windows 7. | |
import struct | |
# set according to your device: | |
device_dpi = 304 # mouse/touchpad dpi | |
screen_dpi = 157 | |
sample_point_count = 30 | |
sensitivity_factor = 1.0 | |
# sensitivity factor translation table: (windows slider notches) | |
# 1 = 0.1 | |
# 2 = 0.2 | |
# 3 = 0.4 | |
# 4 = 0.6 | |
# 5 = 0.8 | |
# 6 = 1.0 default | |
# 7 = 1.2 | |
# 8 = 1.4 | |
# 9 = 1.6 | |
# 10 = 1.8 | |
# 11 = 2.0 | |
# inch/s to native-device-units/us | |
scaling_factor = device_dpi / 1e6 | |
def float16x16(num): | |
return struct.unpack('<i', num[:-4])[0] / int(0xffff) | |
# windows registry values: | |
# HKEY_CURRENT_USER\Control Panel\Mouse\SmoothMouseXCurve | |
X = [ | |
b'\x00\x00\x00\x00\x00\x00\x00\x00', | |
b'\x15\x6e\x00\x00\x00\x00\x00\x00', | |
b'\x00\x40\x01\x00\x00\x00\x00\x00', | |
b'\x29\xdc\x03\x00\x00\x00\x00\x00', | |
b'\x00\x00\x28\x00\x00\x00\x00\x00', | |
] | |
# HKEY_CURRENT_USER\Control Panel\Mouse\SmoothMouseYCurve | |
Y=[ | |
b'\x00\x00\x00\x00\x00\x00\x00\x00', | |
b'\xfd\x11\x01\x00\x00\x00\x00\x00', | |
b'\x00\x24\x04\x00\x00\x00\x00\x00', | |
b'\x00\xfc\x12\x00\x00\x00\x00\x00', | |
b'\x00\xc0\xbb\x01\x00\x00\x00\x00', | |
] | |
points = [] | |
for x,y in zip(X,Y): | |
x = float16x16(x) * scaling_factor | |
y = float16x16(y) * scaling_factor | |
gain = 0 if x == 0 else (y / x) / (3.5 * 150 / screen_dpi) | |
points.append((x, y, gain)) | |
def find2points(x): | |
i = 0 | |
while i < len(points) - 2 and x > points[i][0]: | |
i +=1 | |
return points[i], points[i+1] | |
max_x = points[-1][0] | |
step = max_x / (sample_point_count - 1) # we need another point for 0 | |
sample_points = [] | |
pi = 0 | |
for si in range(sample_point_count): | |
x = si * step | |
(x0, _, y0), (x1, _, y1) = find2points(x) | |
interpolated_value = ((x-x0)*y1+(x1-x)*y0)/(x1-x0) | |
sample_points.append(interpolated_value) | |
sample_points_str = ",".join(["%.2f" % number for number in sample_points]) | |
print("device dpi: ", device_dpi) | |
print("screen dpi: ", screen_dpi) | |
print("sensitivity factor: ", sensitivity_factor) | |
print("windows points scaled to native-device-units/us (x, y, gain):") | |
for p in points: | |
print("\t", p) | |
print(f"libinput delta-x: {step}") | |
print(f"libinput sample points ({sample_point_count}):") | |
print("\t", sample_points_str) | |
print("libinput test:") | |
print("\t", f"sudo ./builddir/libinput-debug-gui --verbose --set-profile=custom --set-custom-points={sample_points_str} --set-custom-step={step} --set-custom-type=1") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment