Here is an alternative, building on top of the answer by @JoeSchmoe, that does not rely on external scripts but also works slightly differently: It does not care whether the fullscreen window is focused.
# Get screen size
root_geo=$(xwininfo -root | awk -F'[ +]' '$3 ~ /-geometry/ {print $4}')
# Check if any window fills the screen
xwininfo -root -tree | grep $root_geo | grep -qv "\(Desktop\|has no name\)"
If there is any window that covers the whole screen, the last command will return exit code 0, otherwise 1. Note that this was devised on KDE Plasma as a desktop - you may need to adjust it for other desktop environments, see below.
Explanation
It first obtains the measurements of the screen and saves it to root_geo
. For single time-use, you can also inline that call.
Multiple screens
For multiple screens, if both have the same resolution, you can either hard-code it or modify awk to do this calculation automatically (this assumes they are arranged horizontally):
xwininfo -root | awk -F'[ +x]' '$3 ~ /-geometry/ {printf "%dx%d",$4/2,$5}'
Furthermore, this should get the number of screens you have connected:
xrandr | grep ' connected ' | wc -l
So, putting it together, this should work for any number of screens, as long as they are arranged horizontally without whitespace in between and have the same resolution (quite useful if you use a Laptop and regularly connect to external screens):
root_geo=$(xwininfo -root | awk -F'[ +x]' '$3 ~ /-geometry/ {printf "%dx%d",$4/'"$(xrandr | grep ' connected ' | wc -l)"',$5}')
If they have different resolutions or are arranged in a different way, you could also use xrandr to obtain the resolution for each and construct a regex that matches any of them. Note that this may falsely match on a window that matches the exact dimensions of another screen in a bigger one.
You could construct something that matches on the respective screen to remedy this, but I won't dig that deep here.
Checking for fullscreen windows
xwininfo -root -tree | grep $root_geo | grep -qv "\(Desktop\|has no name\)"
Here, you may have to adjust the last pattern.
What this command does is list all existing windows, including your desktop, in a tree-like fashion. So after filtering for the ones that cover the whole screen, you also have to filter out the ones that are there anyways. The easiest way to check is to run the command without the last grep, which produced the following output for me (using KDE Plasma as desktop):
❯ xwininfo -root -tree | grep $root_geo
0xe001cd (has no name): () 1920x1080+1920+0 +1920+0
0xe001ce (has no name): () 1920x1080+0+0 +1920+0
0x1e00180 "Desktop — Plasma": ("plasmashell" "plasmashell") 1920x1080+0+0 +1920+0
0xe0001e (has no name): () 1920x1080+0+0 +0+0
0xe0001f (has no name): () 1920x1080+0+0 +0+0
0x1e0000b "Desktop — Plasma": ("plasmashell" "plasmashell") 1920x1080+0+0 +0+0
Thus, grepping out Desktop and "has no name" (which seems to be a sort of grouping) was sufficient here.