Stopping the screensaver kicking in

Monkey Forums/Monkey Programming/Stopping the screensaver kicking in

Oddball(Posted 2013) [#1]
Hey gang. Is everybody well? Good. I'm having a little trouble with the game I'm working on. The game uses controllers only, no keyboard/mouse input. Unfortunately after a while the OS thinks the system is inactive and starts the screensaver or puts the system to sleep. Is there any way to tell the OS that the game is active? A kind of "hey OS, I'm doing stuff over here. Don't go to sleep."? This is on Mac, not sure if the same happens on Windows. Cheers.


therevills(Posted 2013) [#2]
Just checking the GLFW user guide (2.7) and it states:
If mode is GLFW_FULLSCREEN, ..... Furthermore, the mouse pointer will be hidden, and screensavers are prohibited.

If mode is GLFW_WINDOW, ..... The mouse pointer will not be hidden and screensavers are allowed to be activated.


That doesn't sound good...

Also I found in the TODO for GLFW 3 (http://wiki.glfw.org/wiki/TODO_for_GLFW_3.0):
Update screensaver status depending on window focus

But it doesn't look crossed-out to me...


Paul - Taiphoz(Posted 2013) [#3]
I used to hook the windows api and set the screensaver flag so that it did not come on but ghat was ages ago there might be an easier way to do it now.

is your game windowed or full screen ?


therevills(Posted 2013) [#4]
Looking in the GLFW code, I wonder if you could hack it...

In the file win32_window.c we can see this bit of code:
        case WM_SYSCOMMAND:
        {
            switch( wParam & 0xfff0 )
            {
                case SC_SCREENSAVE:
                case SC_MONITORPOWER:
                {
                    if( _glfwWin.fullscreen )
                    {
                        // Disallow screen saver and screen blanking if we are
                        // running in fullscreen mode
                        return 0;
                    }
                    else
                    {
                        break;
                    }
                }

                // User trying to access application menu using ALT?
                case SC_KEYMENU:
                    return 0;
            }
            break;
        }


So in theory adding a "return 0;" to SC_SCREENSAVE should stop it always...

But this file is for Windows... not Mac :(


Gerry Quinn(Posted 2013) [#5]
Is it possible to send a system message emulating a keystroke or otherwise saying 'not idle'?


Soap(Posted 2013) [#6]
http://msdn.microsoft.com/en-us/library/windows/desktop/aa373208(v=vs.85).aspx

http://developer.apple.com/library/mac/qa/qa1160/_index.html

Emulating user input is not the way to do it. There are specific system things the programs should be able to have on while they are running / have focus which disable sleep/screen savers.

Those links might be leads to what the correct things are. No time to test.


Gerry Quinn(Posted 2013) [#7]
Well, that was the sort of thing I meant by "otherwise not idle"!