Files
I38/scripts/find_mouse.sh

50 lines
1.8 KiB
Bash
Executable File

#!/usr/bin/env bash
# This file is part of I38.
# I38 is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation,
# either version 3 of the License, or (at your option) any later version.
# I38 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along with I38. If not, see <https://www.gnu.org/licenses/>.
# Move the mouse pointer to the center of the focused window.
if ! command -v xdotool &> /dev/null; then
if command -v notify-send &> /dev/null; then
notify-send "I38" "xdotool is required to move the mouse pointer."
fi
exit 1
fi
activeWindow="$(xdotool getactivewindow 2> /dev/null || true)"
if [[ "$activeWindow" =~ ^[0-9]+$ ]]; then
while IFS='=' read -r key value; do
case "$key" in
X|Y|WIDTH|HEIGHT)
if [[ "$value" =~ ^-?[0-9]+$ ]]; then
printf -v "$key" '%s' "$value"
fi
;;
esac
done < <(xdotool getwindowgeometry --shell "$activeWindow" 2> /dev/null || true)
fi
if [[ "${X:-}" =~ ^-?[0-9]+$ ]] &&
[[ "${Y:-}" =~ ^-?[0-9]+$ ]] &&
[[ "${WIDTH:-}" =~ ^[0-9]+$ ]] &&
[[ "${HEIGHT:-}" =~ ^[0-9]+$ ]] &&
[[ "$WIDTH" -gt 0 ]] &&
[[ "$HEIGHT" -gt 0 ]]; then
pointerX=$((X + WIDTH / 2))
pointerY=$((Y + HEIGHT / 2))
else
read -r displayWidth displayHeight < <(xdotool getdisplaygeometry)
pointerX=$((displayWidth / 2))
pointerY=$((displayHeight / 2))
fi
xdotool mousemove "$pointerX" "$pointerY"