-
Notifications
You must be signed in to change notification settings - Fork 24
Description
Description
Most OSes have a screen-lock or sleep feature that activates when the user does not provide input for some time. When using a gamepad the OS does not recognise this input. It would be great to have a single cross-platform function in Defos to prevent this behaviour across macOS, Windows, and Linux.
Proposed solution
Tell the OS not to allow sleeping while the game is active. Co-pilot reckons these OS functions are how to do it:
Implementation research:
- macOS:
IOPMAssertionCreateWithNamewhile using this assertion type. Suggest the assertion name come from window title also set by defos or default project name from Defold. - Windows:
SetThreadExecutionState. Probably with theES_DISPLAY_REQUIREDflag, but maybe theES_SYSTEM_REQUIREDone - not sure. - Linux:
XScreenSaverSuspendwithsuspendset tofalseto reset the timer.
The Windows and Linux ones appear to reset the idle timer, whereas the macOS one sets your requested assertion off/on. In order to present a consistent API to defos users, it might make sense to have them call a single function periodically and define a short time (20s or something) that if not called it will turn off the macOS one, and for Windows and Linux it can just pass on the call to reset the idle timer. This way it's the game developer's responsibility to keep calling it periodically while receiving gamepad input, then stop calling it to allow the system to sleep if the user really has gone away.