nixos-config/pkgs/eyezoom.nix

47 lines
1.6 KiB
Nix
Raw Normal View History

2024-09-15 19:45:05 +02:00
{ pkgs, ... }:
pkgs.writeScript "eyezoom" ''
2024-09-24 14:25:39 +02:00
arg="$1"
2024-09-15 19:45:05 +02:00
2024-09-24 14:25:39 +02:00
set -- $(
${pkgs.xorg.xrandr}/bin/xrandr |
${pkgs.gawk}/bin/awk -F "[x+ ]" '/primary/ { print $4" "$5" "$6" "$7 }'
)
W="$1"
H="$2"
offx="$3"
offy="$4"
2024-09-15 19:45:05 +02:00
HFACTOR=10
WFACTOR=4
2024-09-24 12:40:56 +02:00
WIDEDIV=2
2024-09-24 17:43:56 +02:00
mouse="pointer:Logitech MX Vertical"
zoomsens=0.1
# calculated using this with x = x+1, y = y+1. works, not sure why...
# https://unix.stackexchange.com/questions/491531/how-to-avoid-mouse-cursor-jumping-while-using-xinput-coordinate-transformation-m
xpos=$(( offx + (W / 2) + 1 ))
ypos=$(( offy + (H / 2) + 1 ))
zoommatrix="$zoomsens 0 $(${pkgs.bc}/bin/bc -l <<< "(1-$zoomsens)*$xpos") 0 $zoomsens $(${pkgs.bc}/bin/bc -l <<< "(1-$zoomsens)*$ypos") 0 0 1"
2024-09-24 14:25:39 +02:00
case "$arg" in
2024-09-15 19:45:05 +02:00
eye)
2024-09-24 12:40:56 +02:00
${pkgs.wmctrl}/bin/wmctrl -R ':ACTIVE:' -e 0,$offx,$(( offy - (H * HFACTOR / 2) + (H / 2) )),$W,$((H*HFACTOR))
2024-09-24 17:43:56 +02:00
xinput set-prop "pointer:Logitech MX Vertical" "Coordinate Transformation Matrix" $zoommatrix
2024-09-15 19:45:05 +02:00
;;
tiktok)
2024-09-24 12:40:56 +02:00
${pkgs.wmctrl}/bin/wmctrl -R ':ACTIVE:' -e 0,$(( offx - ((W/WFACTOR)/2) + (W/2))),$offy,$((W/WFACTOR)),$H
2024-09-24 17:43:56 +02:00
xinput set-prop "pointer:Logitech MX Vertical" "Coordinate Transformation Matrix" 1 0 0 0 1 0 0 0 1
2024-09-24 12:40:56 +02:00
;;
wide)
${pkgs.wmctrl}/bin/wmctrl -R ':ACTIVE:' -e 0,$offx,$(( offy - ((H / WIDEDIV) / 2) + (H / 2) )),$W,$((H/WIDEDIV))
2024-09-24 17:43:56 +02:00
xinput set-prop "pointer:Logitech MX Vertical" "Coordinate Transformation Matrix" 1 0 0 0 1 0 0 0 1
2024-09-15 19:45:05 +02:00
;;
*)
2024-09-24 12:40:56 +02:00
${pkgs.wmctrl}/bin/wmctrl -R ':ACTIVE:' -e 0,$offx,$offy,$W,$H
2024-09-24 17:43:56 +02:00
xinput set-prop "pointer:Logitech MX Vertical" "Coordinate Transformation Matrix" 1 0 0 0 1 0 0 0 1
2024-09-15 19:45:05 +02:00
;;
esac
''