I made a one liner script to auto hide a specific window when mouse is not hover over that window. It gets mouse position and geometry of the window and its position (topleftx,toplefty), I added its geometry to the window's starting position to get (bottomrightx, bottomrighty) coordinates, then it compares if mouse is over the window. If mouse is not on the window, it hides the window.
It works but only once, because xprop
window info command that I use to extract window info in the script fails if it doesn't find the
window name in the window stack. It outputs an error message and --help
message then exits.
I need xprop
because it's the only window info command that gives info about decoration id
of any window. Because mainstream window info tools in Linux only prints geometry and position of a window without its decoration. I wanted to include the window decoration for completeness.
How can I trick it into working?
while [ 1 ]
do
string=$(xdotool getmouselocation 2>/dev/null | sed 's/x:\([0-9]\+\)[ \t]y:\([0-9]\+\)[ \t].*/\1;\2/' | tr ';' ',')
string2=$(xdotool getwindowgeometry $(xprop -name "kenn" | grep _COMPIZ_WINDOW_DECOR_INPUT_FRAME | grep -Po ' # \K.*') | grep -Po ': \K.*' |cut -d" " -f1 | tr '\n' ',' | tr 'x' ','| sed 's/-[0-9][0-9]*/0/')
A="$string2$string"
IFS=,
set $A
if [[(($5 -lt $(($1+$3)))) && (($5 -gt $1))]] && [[(($6 -lt $(($2+$4)))) && (( $6 -gt $2 ))]]
then echo "mouse is on the window"
else
then echo "mouse is out of the window"
fi
done