在使用 C++ 开发小型跨平台游戏时,我遇到了以下问题:当玩家在不接触键盘或鼠标的情况下使用 USB 游戏 handle 玩游戏时,电脑在玩游戏时会自动休眠。
在 Windows 中,可以使用 SetThreadExecutionState
轻松完成。功能。在 OS X 中,我认为可以使用 UpdateSystemActivity
但尚未测试。
但问题是,在 Linux 中,DE 之间没有通用 API。我发现在 Gnome 中,您可以使用 DBus 调用 Inhibit()
和 Uninhibit()
来停止自动挂起,但它仅适用于 Gnome。
So, is there exists a programatically cross-DE way (or non-DE way, for example if user is using something like
dwm
orawesome wm
) to prevent a Linux system (using Xorg and without root access of course) from sleeping or turning on screensaver without changing user configuration files?
PS:不要觉得太复杂,但不知道有多遗憾。
最佳答案
快速浏览一下 mplayer 和 SDL 是如何做到这一点的,您可以做两件事来防止屏幕保护程序启动:
- 在程序期间禁用它:
- 使用
XScreenSaverSuspend
- 使用 DBus,调用
org.freedesktop.ScreenSaver.Inhibit
- 使用
- 定期 Ping 它:
- 使用
XResetScreenSaver
- 使用DBus,调用
org.freedesktop.ScreenSaver.SimulateUserActivity
- 使用
关于c++ - 如何以编程方式防止 linux 计算机休眠或打开屏幕保护程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31498114/