Skip to content

Instantly share code, notes, and snippets.

@koonix
Last active December 17, 2022 10:33
Show Gist options
  • Save koonix/c1d7c7ae68538c56967ce3e4ade5b819 to your computer and use it in GitHub Desktop.
Save koonix/c1d7c7ae68538c56967ce3e4ade5b819 to your computer and use it in GitHub Desktop.
Detect if the pointer is on the root window (background) on Linux.
#!/bin/sh
# this script return true if the pointer is on the root window.
# requires xorg-xwininfo and xdotool.
rootwin=$(xwininfo -root | grep -Po 'Window id: \K\S+')
currentwin=$(printf '0x%x\n' "$(xdotool getmouselocation | cut -d: -f5)")
[ -n "$currentwin" ] && [ "$currentwin" = "$rootwin" ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment