Use SDL3 screen saver functions to implement AllowScreenSuspension

This removes the custom Android and iOS implementations, and also adds support for desktop platforms.
This commit is contained in:
Susko3
2024-04-30 12:35:21 +02:00
parent 5071dacc9e
commit fac74e00ac
5 changed files with 22 additions and 20 deletions

View File

@@ -45,17 +45,6 @@ namespace osu.Framework.Android
protected override IRunnable CreateSDLMainRunnable() => new Runnable(() =>
{
host = new AndroidGameHost(this);
host.AllowScreenSuspension.Result.BindValueChanged(allow =>
{
RunOnUiThread(() =>
{
if (!allow.NewValue)
Window?.AddFlags(WindowManagerFlags.KeepScreenOn);
else
Window?.ClearFlags(WindowManagerFlags.KeepScreenOn);
});
}, true);
host.Run(CreateGame());
if (!IsFinishing)

View File

@@ -30,15 +30,6 @@ namespace osu.Framework.iOS
protected override IWindow CreateWindow(GraphicsSurfaceType preferredSurface) => new IOSWindow(preferredSurface, Options.FriendlyGameName);
protected override void SetupForRun()
{
base.SetupForRun();
AllowScreenSuspension.Result.BindValueChanged(allow =>
InputThread.Scheduler.Add(() => UIApplication.SharedApplication.IdleTimerDisabled = !allow.NewValue),
true);
}
protected override void SetupConfig(IDictionary<FrameworkSetting, object> defaultOverrides)
{
if (!defaultOverrides.ContainsKey(FrameworkSetting.ExecutionMode))

View File

@@ -1060,6 +1060,14 @@ namespace osu.Framework.Platform
}, true);
IsActive.BindTo(Window.IsActive);
AllowScreenSuspension.Result.BindValueChanged(e =>
{
if (e.NewValue)
Window.EnableScreenSuspension();
else
Window.DisableScreenSuspension();
}, true);
}
/// <summary>

View File

@@ -196,6 +196,16 @@ namespace osu.Framework.Platform
/// </remarks>
void CancelFlash();
/// <summary>
/// Enable any system level timers that might dim or turn off the screen.
/// </summary>
void EnableScreenSuspension();
/// <summary>
/// Disable any system level timers that might dim or turn off the screen.
/// </summary>
void DisableScreenSuspension();
/// <summary>
/// Start the window's run loop.
/// Is a blocking call on desktop platforms, and a non-blocking call on mobile platforms.

View File

@@ -407,6 +407,10 @@ namespace osu.Framework.Platform
SDL3.SDL_FlashWindow(SDLWindowHandle, SDL_FlashOperation.SDL_FLASH_CANCEL);
});
public void EnableScreenSuspension() => ScheduleCommand(() => SDL3.SDL_EnableScreenSaver());
public void DisableScreenSuspension() => ScheduleCommand(() => SDL3.SDL_DisableScreenSaver());
/// <summary>
/// Attempts to set the window's icon to the specified image.
/// </summary>