nix/bin/invert.nix (view raw)
1{ pkgs, ... }:
2
3let
4 xrandr = "${pkgs.xorg.xrandr}/bin/xrandr";
5 xinput = "${pkgs.xorg.xinput}/bin/xinput";
6in
7pkgs.writeShellScriptBin "invert"
8 ''
9 orientation="$(${xrandr} --query --verbose | grep eDP | cut -d ' ' -f 6)"
10 if [[ "$orientation" == "normal" ]];
11 then
12 echo "turning screen upside down..."
13 ${xrandr} -o inverted
14 ${xinput} set-prop 'ELAN9008:00 04F3:2C82' 'Coordinate Transformation Matrix' -1 0 1 0 -1 1 0 0 1
15 ${xinput} set-prop 'ELAN9008:00 04F3:2C82 Stylus Pen (0)' 'Coordinate Transformation Matrix' -1 0 1 0 -1 1 0 0 1
16 ${xinput} set-prop 'ELAN9008:00 04F3:2C82 Stylus Eraser (0)' 'Coordinate Transformation Matrix' -1 0 1 0 -1 1 0 0 1
17 else
18 echo "reverting back to normal..."
19 ${xrandr} -o normal
20 ${xinput} set-prop 'ELAN9008:00 04F3:2C82' 'Coordinate Transformation Matrix' 1 0 0 0 1 0 0 0 1
21 ${xinput} set-prop 'ELAN9008:00 04F3:2C82 Stylus Pen (0)' 'Coordinate Transformation Matrix' 1 0 0 0 1 0 0 0 1
22 ${xinput} set-prop 'ELAN9008:00 04F3:2C82 Stylus Eraser (0)' 'Coordinate Transformation Matrix' 1 0 0 0 1 0 0 0 1
23 fi
24 ''