问题
X11 has a screensaver mechanism that can be controlled by xset
command. Without having to invoke the external command to disable or heartbeat the screensaver, from inside my X11 application, how can I heartbeat the screensaver mechanism so to prevent it from shutting down the monitor?
回答1:
If this on a modern Linux system, the preferred FreeDesktop method is to ping the DBus interface, specifically org.freedesktop.ScreenSaver.SimulateUserActivity()
or another part of the exposed interface, depending on your needs.
回答2:
As well as the D-Bus solution suggested by @Kitsune. You can also take the approach that some media players do and simulate the pressing of a key (e.g. Alt) at regular intervals.
This code in totem: http://git.gnome.org/browse/totem/tree/lib/totem-scrsaver.c is designed to be dropped into your code base (it's LGPL v2.1) and will use both the D-Bus interface and also use XTest
to synthesize pressing the Alt key every 30s.
来源:https://stackoverflow.com/questions/9369502/how-to-heartbeat-x11-screensaver