5

Current Situation

I'm suspending my laptop after a 30 minutes of idle state. I'm using this code inside this script to detect the idle duration.

Original Problem

VLC (and I'm pretty sure that any other video player that prevents screen saver from running) sends a periodic signal (on every 30 seconds) to disturb the mouse/keyboard events, so screen saver (thus my code) thinks that "end of idle time is reached" and never runs the desired command until VLC finishes playing the video playlist.

Introduced Problem

I worked around it by ignoring any small user input by keeping track of an offset. If the disturbance is very short, I just add up the previous measurement to the offset variable, so, the main problem is gone. However, I've also disabled the "suppress the screensaver while watching video" feature of VLC. Now I want to add this feature back.

Question

How can I detect if VLC is playing a full screen video (or more preferably, any "full screen video state" from any player) so I could disable "my screensaver" only when an application/VLC is in full screen mode?

ceremcem
  • 2,351

1 Answers1

7

You can use xdotool to get the root window geometry and the VLC window geometry. If they are equal, then VLC window is fullscreen.

gRoot=$(xdotool search --maxdepth 0 '.*' getwindowgeometry | grep 'Geometry:')
gActive=$(xdotool getactivewindow getwindowgeometry | grep 'Geometry:')
if [ "$gRoot" = "$gActive" ]; then
    echo "The active window is fullscreened."
else
    echo "The active window is not fullscreened."
fi

The first command uses --maxdepth 0 so that only the root window is searched.

A related command is xdotool getdisplaygeometry. It is undocumented in the manual but it has a mention on the changelist. Bear in mind it returns the display dimensions in the form [Width] [Height] instead of [Width]x[Height] as getwindowgeometry does, so using it requires further processing to make the equality comparison.

Quasímodo
  • 18,865
  • 4
  • 36
  • 73
  • 1
    nitpicking: what if there's a 2nd screen? Currently this makes the root geometry the geometry of a virtual rectangle able to include both screens. (eg two FHD screens side by side => 3840x1080), but a full screen video will still be on one screen: 1920x1080. Anyway I still upvoted, it solves OP's problem. – A.B Aug 22 '20 at 14:18
  • @A.B Thank you for your comment. I don't have two screens to test it, but AFAIK the default behavior of Xdotool when there is more than one window matching a search is to consider only the first one. You can verify that by launching various XTerms and then with xdotool search -class XTerm getwindowgeometry you will see the output of the geometry of only one single window. – Quasímodo Aug 22 '20 at 18:06
  • I did check your commands with two screens before leaving the comment. It behaves as I wrote: would return two different values and thus: The active window is not fullscreened. I'm not expecting any easy workaround for this (I don't have any idea about it), I was just stating the fact. – A.B Aug 22 '20 at 19:30
  • 1
    @A.B Oh, I didn't know you had already checked it, thanks again. If it returned two values and both were the same (i.e., both monitors have the same dimensions), then one could just get one of those values to check if the window is fullscreen, I guess? But indeed, the general case is more complicated and ultimately would depend on what the user wants to do. – Quasímodo Aug 22 '20 at 23:52