From ed9f82fad0cd99c013f657f569567043fe6dc7d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 12 Oct 2022 10:47:10 +0200 Subject: [PATCH] Platform: SDL disables power-saving when running. That's stupid, don't. I'm getting kinda pissed at the strange defaults. Should I be using a different toolkit altogether because SDL IS FOR GAMES ONLY? Given how many bugreports and complaints there is about "Dosbox blocking screensaver" I'm beginning to think it's SDL's fault, not mine. Let the users control what they want, ffs, don't enable problematic features like blocking powersave or disabling compositor by default. Those should be a runtime option anyway, similarly to how video players block powersaving only when *an actual video is playing*. --- doc/changelog.dox | 4 ++++ src/Magnum/Platform/Sdl2Application.cpp | 8 ++++++++ src/Magnum/Platform/Sdl2Application.h | 16 +++++++++++++++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/doc/changelog.dox b/doc/changelog.dox index e084963af..8bd118a3a 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -505,6 +505,10 @@ See also: @relativeref{Platform::Sdl2Application::KeyEvent::Key,Menu} for consistency with @ref Platform::EmscriptenApplication and @ref Platform::GlfwApplication (see [mosra/magnum#547](https://github.com/mosra/magnum/pull/547)) +- @ref Platform::Sdl2Application now overrides SDL's default behavior that + prevents computer from entering a power-saving mode while the application + is running, as that's generally undesirable for regular GUI applications. + See @ref Platform-Sdl2Application-usage-power for more information. @subsubsection changelog-latest-changes-scenegraph SceneGraph library diff --git a/src/Magnum/Platform/Sdl2Application.cpp b/src/Magnum/Platform/Sdl2Application.cpp index ec2fc49c9..57b0d8b7f 100644 --- a/src/Magnum/Platform/Sdl2Application.cpp +++ b/src/Magnum/Platform/Sdl2Application.cpp @@ -149,6 +149,14 @@ Sdl2Application::Sdl2Application(const Arguments& arguments, NoCreateT): #ifdef SDL_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR SDL_SetHint(SDL_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR, "0"); #endif + /* By default, SDL behaves like if it was playing a video or whatever, + preventing the computer from turning off the screen or going to sleep. + While it sorta makes sense for games, it's useless and annoying for + regular apps. Together with the compositor disabling those two are the + most stupid defaults. */ + #ifdef SDL_HINT_VIDEO_ALLOW_SCREENSAVER + SDL_SetHint(SDL_HINT_VIDEO_ALLOW_SCREENSAVER, "1"); + #endif /* Available since 2.0.12, use EGL if desired */ #if defined(MAGNUM_TARGET_EGL) && defined(SDL_HINT_VIDEO_X11_FORCE_EGL) SDL_SetHint(SDL_HINT_VIDEO_X11_FORCE_EGL, "1"); diff --git a/src/Magnum/Platform/Sdl2Application.h b/src/Magnum/Platform/Sdl2Application.h index aface1bb5..aac12d8af 100644 --- a/src/Magnum/Platform/Sdl2Application.h +++ b/src/Magnum/Platform/Sdl2Application.h @@ -286,6 +286,19 @@ If no other application header is included, this class is also aliased to @cpp Platform::Application @ce and the macro is aliased to @cpp MAGNUM_APPLICATION_MAIN() @ce to simplify porting. +@subsection Platform-Sdl2Application-usage-power Power management + +SDL by default prevents the computer from powering off the or screen going to +sleep. While possibly useful for game-like use cases, it's generally +undesirable for regular applications. @ref Sdl2Application turns this behavior +off. You can restore SDL's default behavior by disabling the +[corresponding SDL hint](https://wiki.libsdl.org/CategoryHints) through an +environment variable or through @cpp SDL_SetHint() @ce from your application. + +@code{.sh} +SDL_VIDEO_ALLOW_SCREENSAVER=0 ./your-app +@endcode + @subsection Platform-Sdl2Application-usage-posix POSIX specifics On POSIX systems, SDL by default intercepts the `SIGTERM` signal and generates @@ -314,7 +327,8 @@ for non-fullscreen apps (KWin, among others, is known to respect this setting). When using SDL >= 2.0.8, @ref Sdl2Application turns this behavior off, keeping the compositor running to avoid the flicker. You can turn this behavior back on by enabling the [corresponding SDL hint](https://wiki.libsdl.org/CategoryHints) -through an environment variable: +through an environment variable or through @cpp SDL_SetHint() @ce from your +application. @code{.sh} SDL_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR=1 ./your-app