From 5f862a36779d8738cef6a8958d54e704aaf471b6 Mon Sep 17 00:00:00 2001 From: committer Date: Sun, 19 May 2024 20:13:20 -0500 Subject: [PATCH] + monitorshot https://gist.github.com/naelstrof/f9b74b5221cdc324c0911c89a47b8d97 --- dots/bin/monitorshot.sh | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 dots/bin/monitorshot.sh diff --git a/dots/bin/monitorshot.sh b/dots/bin/monitorshot.sh new file mode 100644 index 0000000..5f14de6 --- /dev/null +++ b/dots/bin/monitorshot.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash + +# src: https://gist.github.com/naelstrof/f9b74b5221cdc324c0911c89a47b8d97 + +this_file_name=`basename "$0"` +if [ $# -lt 1 ]; then + echo "usage: '$this_file_name [path_to_output_image]'" + exit 1 +fi +output=$1 + + +MONITORS=$(xrandr | grep -o '[0-9]*x[0-9]*[+-][0-9]*[+-][0-9]*') +# Get the location of the mouse +XMOUSE=$(xdotool getmouselocation | awk -F "[: ]" '{print $2}') +YMOUSE=$(xdotool getmouselocation | awk -F "[: ]" '{print $4}') + +for mon in ${MONITORS}; do + # Parse the geometry of the monitor + MONW=$(echo ${mon} | awk -F "[x+]" '{print $1}') + MONH=$(echo ${mon} | awk -F "[x+]" '{print $2}') + MONX=$(echo ${mon} | awk -F "[x+]" '{print $3}') + MONY=$(echo ${mon} | awk -F "[x+]" '{print $4}') + # Use a simple collision check + if (( ${XMOUSE} >= ${MONX} )); then + if (( ${XMOUSE} <= ${MONX}+${MONW} )); then + if (( ${YMOUSE} >= ${MONY} )); then + if (( ${YMOUSE} <= ${MONY}+${MONH} )); then + # We have found our monitor! + maim -g "${MONW}x${MONH}+${MONX}+${MONY}" output + exit 0 + fi + fi + fi + fi +done +echo "Oh no the mouse is in the void!" +exit 1 \ No newline at end of file