I only want to execute a certain action with xdotool
if the window is not visible to the user, this includes minimized windows, but also windows which are 100% covered by other windows (if no transparency is used at least). Ignoring the transparency issue is there a simple way to do this?
xdotool
has a --onlyvisible
option, but that only includes minimized windows, not covered windows. Of course there is the option of cycling through all visible windows, getting their window geometries and calculating how much of the window of interest they cover, but I do hope there is an easier and faster solution than doing this in bash.
Here is a nice illustration of the problem, but there it is only about listing windows, also it is for Max OS X. This question only has an answer which hints, but not shows how to do it by listing all visible windows with their respective z-order and calculating the visible area manually.
Best Answer
For completeness sake here is the naive / brute-force solution which I hoped is already implemented in some other utility. The
fullyobscured
notify-event in @Gilles link in the comment sounds very promising, but I wasn't sure how to get it to work, and this solution was also quite fun to implement.The script simply calculates the coverage area of all overlapping window subtracting double counted areas and checks if it is as large as the window area. Because it correctly includes the frame borders the code looks a bit more complex than it could. It returns exit code 0 if fully covered and 1 if not. It takes a window ID as an argument. E.g. call it with
if xcovered 0x1a00003; then echo 'covered!'; fi
Not counting the comments, debug comments and error-checking it could be only 40 lines long, surely even less. I actually wanted to use bc instead of python, but I couldn't find an easy way to transfer a bash array to a bc array.