added get-focused-monitor helper script

This commit is contained in:
Sam 2024-06-19 22:30:52 +01:00
parent 1a4bf927a4
commit 65b59676ba
1 changed files with 25 additions and 0 deletions

View File

@ -0,0 +1,25 @@
{ pkgs, ... }:
{
home.packages = with pkgs; [
(writeShellScriptBin "get-focused-monitor" ''
# get the current cursor location into X and Y variables
eval $(xdotool getmouselocation --shell)
# compare mouse location to monitor coordinates
while IFS= read -r line; do
if [[ $line =~ " connected" ]]; then
display=$(echo "$line" | awk '{print $1}')
coords=$(echo "$line" | grep -oP "\d+x\d+" | tr 'x+' ' ')
read width height x_offset y_offset <<< $coords
if (( X >= x_offset && X <= width + x_offset )) && (( Y >= y_offset && Y <= height + y_offset )); then
echo "$display"
break
fi
fi
done < <(xrandr)
'')
];
}