How to programmatically prevent linux computer from sleeping or turning on screensaver?

后端 未结 3 1996
既然无缘
既然无缘 2021-02-12 19:25

While developing a small cross-platform game on C++, I got stuck with following issue: when players are playing with a USB gamepad without touching a keyboard or mouse, the comp

3条回答
  •  佛祖请我去吃肉
    2021-02-12 20:09

    From a quick look at how mplayer and SDL do it, there are two things you can do to prevent the screensaver from firing up:

    • Disable it for the duration of the program:
      • Using XScreenSaverSuspend
      • Using DBus, calling org.freedesktop.ScreenSaver.Inhibit
    • Ping it periodically:
      • Using XResetScreenSaver
      • Using DBus, calling org.freedesktop.ScreenSaver.SimulateUserActivity

提交回复
热议问题