From 65b59676ba5344a7365d47003773419060e5edf6 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 19 Jun 2024 22:30:52 +0100 Subject: [PATCH] added get-focused-monitor helper script --- .../dwm/scripts/get-focused-monitor.nix | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 home/common/optional/desktop/dwm/scripts/get-focused-monitor.nix diff --git a/home/common/optional/desktop/dwm/scripts/get-focused-monitor.nix b/home/common/optional/desktop/dwm/scripts/get-focused-monitor.nix new file mode 100644 index 0000000..3de584d --- /dev/null +++ b/home/common/optional/desktop/dwm/scripts/get-focused-monitor.nix @@ -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) + + '') + ]; +}