The bad news is, that there is no official method for such a trivial task, which works on all installations. In addition, there is the energy saving mode, which has nothing to do with the screensaver, and must thus be disabled separately.
The Xlib method
You get the screensaver status with
XGetScreenSaver(), disable it with
XSetScreenSaver()and restore it after video playback. Advantage is, that this method is core X11. Disadvatage is, that it never works.
Old gnome method
Older gnome versions had a way to ping the screensaver by executing the command:
gnome-screensaver-command --poke > /dev/null 2> /dev/null
Actually pinging the screensaver (which resets the idle timer) is a better method, because it restores the screensaver even if the player got killed (or crashed). The bad news is, that starting with some never gnome version (don't know exactly which), this stopped working. To make things worse, the command is still available and even gives zero return code, it's just a noop.
I never owned a Linux installation with KDE. But with a little help from a friends, I found a method. My implementation however is so ugly, that I won't show it here :)
The holy grail: Fake key events
After the old gnome variant stopped working for me, I finally found the XTest extension. It was developed to test XServers. I abuse it to send fake key events, which are handled indentically to real keystrokes. They will reset the idle counters of all screensaver variants, and will also disable the energy saving mode.
Also it's a ping approach (with the advantage described above). But it works with an X11 protocol request instead of forking a subprocess, so the overhead will be much smaller. The documentation for the XTest extension is from 1992, so I expect it to be present on all installations, which are sufficiently new for video playback.
Here is how I implemented it:
<X11/extensions/XTest.h>, link with
2. Test for presence of the XTest extension with
3. Get the keycode of the left shift key with
4. Each 40 seconds, I press the key with
XTestFakeKeyEvent(dpy, keycode, True, CurrentTime);
5. One video frame later, I release the key with
XTestFakeKeyEvent(dpy, keycode, False, CurrentTime);
The one frame delay was done to make sure, that the press and release events will arrive with different timestamps. I don't want to know, what happens if press- and release-events for a key have identical timestamps.
This method will hopefully work forever, no matter what crazy ideas the desktop developers get in the future. Also, this is one more reason not to use any GUI toolkit for video playback. If you use Xlib and it's extensions, you have full access to all available features of X. When using a toolkit, you have just the features the toolkit developers think you deserve.