// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Input; using osu.Framework.Input.Bindings; using osu.Framework.Input.Handlers; using osu.Framework.Input.Handlers.Mouse; using osu.Framework.Platform.Windows.Native; namespace osu.Framework.Platform.Windows { public class WindowsGameHost : DesktopGameHost { private TimePeriod timePeriod; public override Clipboard GetClipboard() => new WindowsClipboard(); public override IEnumerable UserStoragePaths => // on windows this is guaranteed to exist (and be usable) so don't fallback to the base/default. Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData).Yield(); #if NET5_0 [System.Runtime.Versioning.SupportedOSPlatform("windows")] #endif public override bool CapsLockEnabled => Console.CapsLock; internal WindowsGameHost(string gameName, bool bindIPC = false, bool portableInstallation = false) : base(gameName, bindIPC, portableInstallation) { } public override void OpenFileExternally(string filename) { if (Directory.Exists(filename)) { Process.Start("explorer.exe", filename); return; } base.OpenFileExternally(filename); } protected override IEnumerable CreateAvailableInputHandlers() { // for windows platforms we want to override the relative mouse event handling behaviour. return base.CreateAvailableInputHandlers() .Where(t => !(t is MouseHandler)) .Concat(new InputHandler[] { new WindowsMouseHandler() }); } protected override void SetupForRun() { base.SetupForRun(); // OnActivate / OnDeactivate may not fire, so the initial activity state may be unknown here. // In order to be certain we have the correct activity state we are querying the Windows API here. timePeriod = new TimePeriod(1); } protected override IWindow CreateWindow() => new WindowsWindow(); public override IEnumerable PlatformKeyBindings => base.PlatformKeyBindings.Concat(new[] { new KeyBinding(new KeyCombination(InputKey.Alt, InputKey.F4), PlatformAction.Exit) }).ToList(); protected override void Dispose(bool isDisposing) { timePeriod?.Dispose(); base.Dispose(isDisposing); } protected override void OnActivated() { Execution.SetThreadExecutionState(Execution.ExecutionState.Continuous | Execution.ExecutionState.SystemRequired | Execution.ExecutionState.DisplayRequired); base.OnActivated(); } protected override void OnDeactivated() { Execution.SetThreadExecutionState(Execution.ExecutionState.Continuous); base.OnDeactivated(); } } }