1

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
1
  • You should expand your one-liner into a multi-line script, at least here. It's very hard to read that way using a scroll bar for such a long line. Thanks!
    – Byte Commander
    Dec 25, 2015 at 18:51

1 Answer 1

1

You may try

(xprop -name "kenn" 2>/dev/null || echo "") |...

The stderr redirect gets rid of the error and the part after || kicks in if xprop bombs out.

2
  • Thank you for suggestion. I tried it but I still can not make it work
    – kenn
    Dec 25, 2015 at 20:06
  • Your proposition fixed error related to xprop but I get another strange error message bash: 1025+: syntax error: operand expected (error token is "+")
    – kenn
    Dec 25, 2015 at 20:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .