OpenTTD icon indicating copy to clipboard operation
OpenTTD copied to clipboard

Allow the computer to go to sleep when the game is paused

Open mrixner opened this issue 2 months ago • 7 comments

Motivation / Problem

As seen in #12937, there is absolutely no reason to keep the screen on while the game is paused. I agree that the screensaver should be inhibited while the user is playing or the simulation is running, so they can enjoy watching the vehicles move around, but when the game is paused all that blocking the screensaver does is unnecessarily waste power (this happened to me yesterday; apparently my computer was on all night because OpenTTD was open, but paused).

Description

If the game is paused, the screensaver is undisabled, and when it is unpaused the screensaver is redisabled.

Limitations

This only applies to SDL backends.

Checklist for review

Some things are not automated, and forgotten often. This list is a reminder for the reviewers.

  • The bug fix is important enough to be backported? (label: 'backport requested')
  • This PR touches english.txt or translations? Check the guidelines
  • This PR affects the GS/AI API? (label 'needs review: Script API')
    • ai_changelog.hpp, game_changelog.hpp need updating.
    • The compatibility wrappers (compat_*.nut) need updating.
  • This PR affects the NewGRF API? (label 'needs review: NewGRF')

mrixner avatar Oct 14 '25 17:10 mrixner

Nice!

But not exactly going to work (or even compile) on anything that isn't SDL. I would expect this should be implemented as an (empty) method in the VideoDriver class, then overridden as needed.

LordAro avatar Oct 14 '25 17:10 LordAro

And

This function is available since SDL 3.2.0.

Does not bode well for systems using older SDL versions (i.e. pretty much all of them)

LordAro avatar Oct 14 '25 18:10 LordAro

And

This function is available since SDL 3.2.0.

Does not bode well for systems using older SDL versions (i.e. pretty much all of them)

You're looking at the SDL3 one, not SDL2 one. It's been available since SDL 2.0.0.

mrixner avatar Oct 14 '25 18:10 mrixner

Bear in mind that #12937 has opinions on this -- notably the game being paused doesn't actually mean that nothing can happen.

PeterN avatar Oct 14 '25 18:10 PeterN

Like building? If you're building, the screensaver is likely inhibited anyway, since you're moving the mouse.

mrixner avatar Oct 14 '25 18:10 mrixner

Which video driver is used with SDL? I put it in VideoDriver_SDL_Base (since that's what everything inherits from) but it's no longer working; I know that my system is using an SDL video driver, though, because it did work earlier when it wasn't going through the VideoDriver class.

mrixner avatar Oct 14 '25 18:10 mrixner

I have tested it to work with the new VideoDriver utilization. This, obviously, only applies to SDL backends.

mrixner avatar Oct 15 '25 23:10 mrixner