From 45ed86f46cdf413d1acaa189f0faea7a10b0ad44 Mon Sep 17 00:00:00 2001 From: Susko3 Date: Thu, 23 May 2024 12:53:33 +0200 Subject: [PATCH] Add back `SDL2BatteryInfo` --- osu.Desktop/OsuGameDesktop.cs | 2 +- osu.Desktop/SDL2BatteryInfo.cs | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 osu.Desktop/SDL2BatteryInfo.cs diff --git a/osu.Desktop/OsuGameDesktop.cs b/osu.Desktop/OsuGameDesktop.cs index b1e1a8f118..3e06dad4c5 100644 --- a/osu.Desktop/OsuGameDesktop.cs +++ b/osu.Desktop/OsuGameDesktop.cs @@ -160,7 +160,7 @@ namespace osu.Desktop host.Window.Title = Name; } - protected override BatteryInfo CreateBatteryInfo() => new SDL3BatteryInfo(); + protected override BatteryInfo CreateBatteryInfo() => FrameworkEnvironment.UseSDL3 ? new SDL3BatteryInfo() : new SDL2BatteryInfo(); protected override void Dispose(bool isDisposing) { diff --git a/osu.Desktop/SDL2BatteryInfo.cs b/osu.Desktop/SDL2BatteryInfo.cs new file mode 100644 index 0000000000..9ca2dc3a5c --- /dev/null +++ b/osu.Desktop/SDL2BatteryInfo.cs @@ -0,0 +1,25 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Game.Utils; + +namespace osu.Desktop +{ + internal class SDL2BatteryInfo : BatteryInfo + { + public override double? ChargeLevel + { + get + { + SDL2.SDL.SDL_GetPowerInfo(out _, out int percentage); + + if (percentage == -1) + return null; + + return percentage / 100.0; + } + } + + public override bool OnBattery => SDL2.SDL.SDL_GetPowerInfo(out _, out _) == SDL2.SDL.SDL_PowerState.SDL_POWERSTATE_ON_BATTERY; + } +}