本文介绍了如何以编程方式防止linux计算机休眠或打开屏保?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C ++上开发小型跨平台游戏时,我遇到了以下问题:当玩家在不触摸键盘或鼠标的情况下使用USB游戏板进行游戏时,计算机在游戏时会自动进入睡眠状态.

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 computer sleeps automatically while they're playing.

在Windows中,可以使用 SetThreadExecutionState 函数.我认为在OS X中,可以使用 UpdateSystemActivity ,但尚未测试.

In Windows, it can be done easily using SetThreadExecutionState function. In OS X, I think it can be done with UpdateSystemActivity but not tested yet.

但是问题是,在Linux中,没有什么像DE之间的通用API一样.我发现在Gnome中,您可以通过使用DBus调用 Inhibit() Uninhibit()来停止自动暂停,但这仅适用于Gnome.

But the problem is, in Linux there's nothing like a common API between DE's. I've found that in Gnome you can stop the auto-suspending by using DBus calls Inhibit() and Uninhibit(), but it works only for Gnome.

PS:不要以为它太复杂了,但是不知道它是多么不幸.

PS: Don't think that it's too complicated, but don't know how unfortunately.

推荐答案

通过快速查看mplayer和SDL如何做到这一点,您可以执行两项操作来防止屏幕保护程序启动:

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:

  • 在程序运行期间将其禁用:
    • 使用 XScreenSaverSuspend
    • 使用DBus,调用 org.freedesktop.ScreenSaver.Inhibit
    • 使用 XResetScreenSaver
    • 使用DBus,调用 org.freedesktop.ScreenSaver.SimulateUserActivity

    这篇关于如何以编程方式防止linux计算机休眠或打开屏保?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-14 18:36