mirror of
https://github.com/SK-la/osu-framework.git
synced 2026-03-15 03:20:30 +00:00
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:
@@ -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)
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user