nixos-config/pkgs/eyezoom.nix
2024-10-13 21:37:11 +02:00

45 lines
1.1 KiB
Nix

{ pkgs, ... }:
pkgs.writeScript "eyezoom" ''
arg="$1"
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"
ZH=16384
ZW=320
WDIV=4
WIDEDIV=2
mouse="pointer:pulsar X2H Mini"
normalaccel=0
zoomaccel=-0.90
case "$arg" in
eye)
${pkgs.wmctrl}/bin/wmctrl -R ':ACTIVE:' -e 0,$(( offx - (ZW / 2) + (W / 2) )),$(( offy - (ZH / 2) + (H / 2) )),$ZW,$((ZH))
xinput set-prop "pointer:Logitech MX Vertical" "libinput Accel Speed" $zoomaccel
;;
tiktok)
${pkgs.wmctrl}/bin/wmctrl -R ':ACTIVE:' -e 0,$(( offx - ((W/WDIV)/2) + (W/2))),$offy,$((W/WDIV)),$H
xinput set-prop "pointer:Logitech MX Vertical" "libinput Accel Speed" $normalaccel
;;
wide)
${pkgs.wmctrl}/bin/wmctrl -R ':ACTIVE:' -e 0,$offx,$(( offy - ((H / WIDEDIV) / 2) + (H / 2) )),$W,$((H/WIDEDIV))
xinput set-prop "pointer:Logitech MX Vertical" "libinput Accel Speed" $normalaccel
;;
*)
${pkgs.wmctrl}/bin/wmctrl -R ':ACTIVE:' -e 0,$offx,$offy,$W,$H
xinput set-prop "pointer:Logitech MX Vertical" "libinput Accel Speed" $normalaccel
;;
esac
''