]> Freerunner's - dotfiles.git/commitdiff
hypr: tweak colors and mouse acceleration profile
authorAndre Ramnitz <tux.rising@gmail.com>
Mon, 7 Oct 2024 22:54:30 +0000 (00:54 +0200)
committerAndre Ramnitz <tux.rising@gmail.com>
Mon, 7 Oct 2024 22:54:30 +0000 (00:54 +0200)
config/dot-config/hypr/hyprland.conf
config/dot-config/hypr/scripts/custom-accel-macos.py [new file with mode: 0644]
config/dot-config/hypr/scripts/custom-accel-windows.py [new file with mode: 0755]
local/dot-local/bin/accel.py [deleted file]

index 162c4fcdba87d0a94d546af73493bb4342f50057..f8f639fd9e6b85d51ab9325684d60ec0e0d6f027 100644 (file)
@@ -51,6 +51,7 @@ exec-once = ~/.config/hypr/scripts/startup.sh
 # exec-once = hypridle
 exec-once = foot -s
 exec-shutdown = pkill -f '/usr/lib/python-exec/python3.12/python /home/andy/.config/hypr/scripts/gammarelay-auto-temp.py'
+# exec = python ~/.config/hypr/scripts/macos_like_accel.py razer-razer-basilisk-v3
 
 # Source a file (multi-file configs)
 # source = ~/.config/hypr/myColors.conf
@@ -79,9 +80,9 @@ general {
     gaps_in = 4
     gaps_out = 8
     col.active_border = 0xff$base0C
-    col.inactive_border = 0x33$base0C 0x44$base0C 135deg
+    col.inactive_border = 0x77$base04
     col.nogroup_border_active = 0xff$base08
-    col.nogroup_border = 0x33$base08 0x44$base08 135deg
+    col.nogroup_border = 0x77$base08
 
     layout = master
 
@@ -178,16 +179,16 @@ misc {
 device {
     name = razer-razer-basilisk-v3
     sensitivity = 0
-    accel_profile = custom 0.3431164009 0.000 0.291 0.582 1.019 1.456 1.894 2.370 3.035 3.700 4.364 5.029 5.694 6.358 7.023 7.688 8.353 9.017 9.682 10.347 11.720
+    accel_profile = custom 0.3308622437 0.000 0.224 0.449 0.673 0.997 1.335 1.672 2.010 2.348 2.685 3.186 3.699 4.212 4.725 5.237 5.750 6.263 6.776 7.288 7.801 8.314 8.827 9.339 9.852 10.365 10.878 11.390 11.903 12.416 13.476
 }
 
 group {
        merge_groups_on_drag = 0
        insert_after_current = 0
-       col.border_active = 0xff$base0A 0xff$base04 90deg
-       col.border_inactive = 0xff$base0A 0xff$base02 270deg
-       col.border_locked_active = 0xff$base0B 0xff$base04 90deg
-       col.border_locked_inactive = 0xff$base0B 0xff$base02 270deg
+       col.border_active = 0xff$base0A
+       col.border_inactive = 0xAA$base0A
+       col.border_locked_active = 0xff$base09
+       col.border_locked_inactive = 0x77$base09
     groupbar {
        enabled = 0
        height = 22
@@ -208,13 +209,13 @@ plugin {
                bar_text_font = Iosevka Nerd Font Propo
                bar_text_size = 12
                bar_height = 24
-               bar_color = 0xee$base01
-               col.text = 0xff$base07
+               bar_color = 0xff$base01
+               col.text = 0xff$base05
                bar_part_of_window = 1
                bar_precedence_over_border = 1
                # hyprbars-button = color, size, icon, on-click
-               hyprbars-button = 0x70eb6f92, 20, 󰖭, hyprctl dispatch killactive
-               hyprbars-button = 0x80f6c177, 20, 󰁌, hyprctl dispatch fullscreen 1
+               hyprbars-button = 0x70$base08, 20, 󰖭, hyprctl dispatch killactive
+               hyprbars-button = 0x90$base0A, 20, 󰁌, hyprctl dispatch fullscreen 1
         }
 }
 
diff --git a/config/dot-config/hypr/scripts/custom-accel-macos.py b/config/dot-config/hypr/scripts/custom-accel-macos.py
new file mode 100644 (file)
index 0000000..4802400
--- /dev/null
@@ -0,0 +1,98 @@
+#!/usr/bin/env python3
+
+# based on https://gist.github.com/fufexan/de2099bc3086f3a6c83d61fc1fcc06c9
+
+import struct
+import os
+import sys
+import math
+
+# ===== PARAMETERS =====
+# set according to your device:
+device_dpi = 2048 * 1.5 # mouse dpi
+screen_dpi = 163
+screen_scaling_factor = 1
+sample_point_count = 20 
+sensitivity_factor = 6
+
+def sigmoid(x, a=1.0):
+    return 1 / (1 + math.exp(-a * (x - 0.5)))
+
+def find_arg(arg):
+    for i in sys.argv:
+        if i == arg:
+            return True
+    return False
+
+def float16x16(num):
+    return struct.unpack('<i', num[:-4])[0] / int(0xffff)
+
+if find_arg("help") or find_arg("-h") or find_arg("--help") or find_arg("h"):
+    print(f'{sys.argv[0]} <device>')
+    print('To get the device, run `hyprctl devices` and get its name')
+    exit(0)
+
+# Make sure the device is passed as the first argument
+if len(sys.argv) < 2:
+    print("Error: device not specified. Usage: <script> <device>")
+    exit(1)
+
+# The first argument is treated as the device
+device = sys.argv[1]
+
+scale_x = device_dpi / 1e3
+scale_y = screen_dpi / 1e3 / screen_scaling_factor * sensitivity_factor
+
+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',
+]
+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',
+]
+
+windows_points = [[float16x16(x), float16x16(y)] for x, y in zip(X, Y)]
+points = [[x * scale_x, y * scale_y] for x, y in windows_points]
+
+def find2points(x):
+    i = 0
+    while i < len(points) - 2 and x >= points[i + 1][0]:
+        i += 1
+    assert -1e6 + points[i][0] <= x <= points[i + 1][0] + 1e6, f'{points[i][0]} <= {x} <= {points[i + 1][0]}'
+    return points[i], points[i + 1]
+
+def interpolate(x):
+    (x0, y0), (x1, y1) = find2points(x)
+    factor = sigmoid(x)  # This smoothly adjusts based on x
+    y = factor * ((x - x0) * y1 + (x1 - x) * y0) / (x1 - x0)
+    
+    return y
+
+def sample_points(count):
+    last_point = -2
+    max_x = points[last_point][0]
+    step = max_x / (count + last_point)  # we need another point for 0
+    sample_points_x = [si * step for si in range(count)]
+    sample_points_y = [interpolate(x) for x in sample_points_x]
+    return sample_points_x, sample_points_y
+
+sample_points_x, sample_points_y = sample_points(sample_point_count)
+step = sample_points_x[1] - sample_points_x[0]
+sample_points_str = " ".join(["%.3f" % number for number in sample_points_y])
+
+print(f'\tPoints: {sample_points_str}')
+print(f'\tStep size: {step:0.10f}')
+
+def hyprctl(device, option, arg):
+    os.system(f"hyprctl keyword 'device[{device}]:{option}' '{arg}'")
+
+# Apply settings for the specified device
+print(f'Setting device:\'{device}\':accel_profile using hyprctl')
+hyprctl(device, 'accel_profile', f'custom {step} {sample_points_str}')
diff --git a/config/dot-config/hypr/scripts/custom-accel-windows.py b/config/dot-config/hypr/scripts/custom-accel-windows.py
new file mode 100755 (executable)
index 0000000..6041a38
--- /dev/null
@@ -0,0 +1,153 @@
+#!/usr/bin/env python3
+
+# original at https://gist.github.com/yinonburgansky/7be4d0489a0df8c06a923240b8eb0191
+# modified for ease of use in Hyprland
+
+# calculation are based on http://www.esreality.com/index.php?a=post&id=1945096
+# assuming windows 10 uses the same calculation as windows 7.
+# guesses have been made calculation is not accurate
+# touchpad users make sure your touchpad is calibrated with `sudo libinput measure touchpad-size`
+# import matplotlib.pyplot as plt
+import struct
+import os
+import sys
+
+# set according to your device:
+device_dpi = 2400 # mouse dpi
+screen_dpi = 109
+screen_scaling_factor = 1
+sample_point_count = 30 # should be enough but you can try to increase for accuracy of windows function
+sensitivity_factor = 6
+# 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
+
+def findArg(arg):
+    for i in sys.argv:
+        if i == arg:
+            return True
+
+    return False
+
+
+if findArg("help") or findArg("-h") or findArg("--help"):
+    print(f'{sys.argv[0]} [[accel_device] [scroll_points] device=<device>]')
+    print('To get the device, run `hyprctl devices`')
+    exit(0)
+
+# TODO: find accurate formulas for scale x and scale y
+# mouse speed: inch/s to device-units/millisecond
+scale_x = device_dpi / 1e3
+# pointer speed: inch/s to screen pixels/millisecond
+scale_y =  screen_dpi / 1e3 / screen_scaling_factor * sensitivity_factor
+
+print(f'scale_x={scale_x}, scale_y={scale_y}')
+
+
+def float16x16(num):
+    return struct.unpack('<i', num[:-4])[0] / int(0xffff)
+
+# windows 10 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',
+]
+
+windows_points = [[float16x16(x), float16x16(y)] for x,y in zip(X,Y)]
+
+print('Windows original points:')
+for point in windows_points:
+    print(point)
+
+# scale windows points according to device config
+points = [[x * scale_x, y * scale_y] for x, y in windows_points]
+
+print('Windows scaled points')
+for point in points:
+    print(point)
+
+
+# plt.plot(*list(zip(*windows_points)), label=f'windows points')
+# plt.plot(*list(zip(*points)), label=f'scaled points')
+# plt.xlabel('device-speed')
+# plt.ylabel('pointer-speed')
+# plt.legend(loc='best')
+# plt.show()
+# exit()
+
+def getDevice():
+    for i in sys.argv:
+        if str(i).startswith('device='):
+            print(str(i)[7::])
+            return str(i)[7::]
+
+
+def find2points(x):
+    i = 0
+    while i < len(points) - 2 and x >= points[i+1][0]:
+        i +=1
+    assert -1e6 + points[i][0] <= x <= points[i+1][0]+1e6, f'{points[i][0]} <= {x} <= {points[i+1][0]}'
+    return points[i], points[i+1]
+
+
+def interpolate(x):
+    (x0, y0), (x1, y1) = find2points(x)
+    y = ((x-x0)*y1+(x1-x)*y0)/(x1-x0)
+    return y
+
+
+def sample_points(count):
+    # use linear extrapolation for last point to get better accuracy for lower points
+    last_point = -2
+    max_x = points[last_point][0]
+    step = max_x / (count + last_point) # we need another point for 0
+    sample_points_x = [si * step for si in range(count)]
+    sample_points_y = [interpolate(x) for x in sample_points_x]
+    return sample_points_x, sample_points_y
+
+sample_points_x, sample_points_y = sample_points(sample_point_count)
+step = sample_points_x[1] - sample_points_x[0]
+
+# plt.plot(sample_points_x, sample_points_y, label=f'windows {sample_point_count} points')
+# plt.plot(*sample_points(1024), label=f'windows 1024 points')
+# plt.xlabel('device-speed')
+# plt.ylabel('pointer-speed')
+# plt.legend(loc='best')
+# plt.show()
+# exit()
+
+sample_points_str = " ".join(["%.3f" % number for number in sample_points_y])
+
+print(f'\tPoints: {sample_points_str}')
+print(f'\tStep size: {step:0.10f}')
+
+if (findArg("accel_profile")):
+    device = getDevice()
+    print(f'Setting device:\'{device}\':accel_profile using hyprctl')
+    os.system(f'hyprctl keyword device:\'{device}\':accel_profile \'custom {step} {sample_points_str}\'')
+
+if (findArg("scroll_points")):
+    device = getDevice()
+    print(f'Setting device:\'{device}\':scroll_points using hyprctl')
+    os.system(f'hyprctl keyword device:\'{device}\':scroll_points \'{step} {sample_points_str}\'')
diff --git a/local/dot-local/bin/accel.py b/local/dot-local/bin/accel.py
deleted file mode 100755 (executable)
index a78d2ca..0000000
+++ /dev/null
@@ -1,153 +0,0 @@
-#!/usr/bin/env python3
-
-# original at https://gist.github.com/yinonburgansky/7be4d0489a0df8c06a923240b8eb0191
-# modified for ease of use in Hyprland
-
-# calculation are based on http://www.esreality.com/index.php?a=post&id=1945096
-# assuming windows 10 uses the same calculation as windows 7.
-# guesses have been made calculation is not accurate
-# touchpad users make sure your touchpad is calibrated with `sudo libinput measure touchpad-size`
-# import matplotlib.pyplot as plt
-import struct
-import os
-import sys
-
-# set according to your device:
-device_dpi = 1600 # mouse dpi
-screen_dpi = 109
-screen_scaling_factor = 1
-sample_point_count = 20 # should be enough but you can try to increase for accuracy of windows function
-sensitivity_factor = 5
-# 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
-
-def findArg(arg):
-    for i in sys.argv:
-        if i == arg:
-            return True
-
-    return False
-
-
-if findArg("help") or findArg("-h") or findArg("--help"):
-    print(f'{sys.argv[0]} [[accel_device] [scroll_points] device=<device>]')
-    print('To get the device, run `hyprctl devices`')
-    exit(0)
-
-# TODO: find accurate formulas for scale x and scale y
-# mouse speed: inch/s to device-units/millisecond
-scale_x = device_dpi / 1e3
-# pointer speed: inch/s to screen pixels/millisecond
-scale_y =  screen_dpi / 1e3 / screen_scaling_factor * sensitivity_factor
-
-print(f'scale_x={scale_x}, scale_y={scale_y}')
-
-
-def float16x16(num):
-    return struct.unpack('<i', num[:-4])[0] / int(0xffff)
-
-# windows 10 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',
-]
-
-windows_points = [[float16x16(x), float16x16(y)] for x,y in zip(X,Y)]
-
-print('Windows original points:')
-for point in windows_points:
-    print(point)
-
-# scale windows points according to device config
-points = [[x * scale_x, y * scale_y] for x, y in windows_points]
-
-print('Windows scaled points')
-for point in points:
-    print(point)
-
-
-# plt.plot(*list(zip(*windows_points)), label=f'windows points')
-# plt.plot(*list(zip(*points)), label=f'scaled points')
-# plt.xlabel('device-speed')
-# plt.ylabel('pointer-speed')
-# plt.legend(loc='best')
-# plt.show()
-# exit()
-
-def getDevice():
-    for i in sys.argv:
-        if str(i).startswith('device='):
-            print(str(i)[7::])
-            return str(i)[7::]
-
-
-def find2points(x):
-    i = 0
-    while i < len(points) - 2 and x >= points[i+1][0]:
-        i +=1
-    assert -1e6 + points[i][0] <= x <= points[i+1][0]+1e6, f'{points[i][0]} <= {x} <= {points[i+1][0]}'
-    return points[i], points[i+1]
-
-
-def interpolate(x):
-    (x0, y0), (x1, y1) = find2points(x)
-    y = ((x-x0)*y1+(x1-x)*y0)/(x1-x0)
-    return y
-
-
-def sample_points(count):
-    # use linear extrapolation for last point to get better accuracy for lower points
-    last_point = -2
-    max_x = points[last_point][0]
-    step = max_x / (count + last_point) # we need another point for 0
-    sample_points_x = [si * step for si in range(count)]
-    sample_points_y = [interpolate(x) for x in sample_points_x]
-    return sample_points_x, sample_points_y
-
-sample_points_x, sample_points_y = sample_points(sample_point_count)
-step = sample_points_x[1] - sample_points_x[0]
-
-# plt.plot(sample_points_x, sample_points_y, label=f'windows {sample_point_count} points')
-# plt.plot(*sample_points(1024), label=f'windows 1024 points')
-# plt.xlabel('device-speed')
-# plt.ylabel('pointer-speed')
-# plt.legend(loc='best')
-# plt.show()
-# exit()
-
-sample_points_str = " ".join(["%.3f" % number for number in sample_points_y])
-
-print(f'\tPoints: {sample_points_str}')
-print(f'\tStep size: {step:0.10f}')
-
-if (findArg("accel_profile")):
-    device = getDevice()
-    print(f'Setting device:\'{device}\':accel_profile using hyprctl')
-    os.system(f'hyprctl keyword device:\'{device}\':accel_profile \'custom {step} {sample_points_str}\'')
-
-if (findArg("scroll_points")):
-    device = getDevice()
-    print(f'Setting device:\'{device}\':scroll_points using hyprctl')
-    os.system(f'hyprctl keyword device:\'{device}\':scroll_points \'{step} {sample_points_str}\'')