Skip to content

Feature Request: Prevent OS screen-lock or sleep when using a gamepad #145

Open

Description

@j-h-a

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:

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.

Activity

  1. j-h-a commented on Dec 8, 2024

    @j-h-a
    Author

    Hrm... I wonder if this is something Defold should do directly, and automatically, rather than in an extension 🤔? It's not something that really should need any developer-interaction, and the engine knows when there are inputs, etc.

  2. britzl commented on Dec 17, 2024

    @britzl
    Collaborator

    Hrm... I wonder if this is something Defold should do directly, and automatically, rather than in an extension 🤔? It's not something that really should need any developer-interaction, and the engine knows when there are inputs, etc.

    Yes, this feels like something which should be available as a game.project option in desktop builds of Defold.

  3. subsoap commented on Mar 13, 2026

    @subsoap
    Owner

    @britzl was that feature ever added to Defold?

  4. subsoap commented on Mar 13, 2026

    @subsoap
    Owner

    HTML5 has a way to do it too. It requires user interaction so it should be used in a settings screen to enable.

    https://developer.mozilla.org/en-US/docs/Web/API/Screen_Wake_Lock_API

  5. subsoap commented on Apr 1, 2026

    @subsoap
    Owner

    WIP branch for this feature needs testing on each platform I only tested on macos/html5 for crashing

    https://github.com/subsoap/defos/tree/copilot/fix-screen-dimming-issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions