From 939441ae408d5f4eb7ee61dba8da54e5e056d481 Mon Sep 17 00:00:00 2001 From: Lucas A Date: Thu, 16 Jul 2020 14:50:11 +0200 Subject: [PATCH] Disable the windows key only when in gameplay. --- osu.Desktop/Windows/GameplayWinKeyHandler.cs | 14 +++++++------- osu.Game/Configuration/SessionStatics.cs | 4 +++- osu.Game/Screens/Play/ScreenSuspensionHandler.cs | 13 ++++++++++++- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/osu.Desktop/Windows/GameplayWinKeyHandler.cs b/osu.Desktop/Windows/GameplayWinKeyHandler.cs index 4f74a4f492..d5ef89c680 100644 --- a/osu.Desktop/Windows/GameplayWinKeyHandler.cs +++ b/osu.Desktop/Windows/GameplayWinKeyHandler.cs @@ -11,26 +11,26 @@ namespace osu.Desktop.Windows { public class GameplayWinKeyHandler : Component { - private Bindable allowScreenSuspension; private Bindable disableWinKey; + private Bindable disableWinKeySetting; private GameHost host; [BackgroundDependencyLoader] - private void load(GameHost host, OsuConfigManager config) + private void load(GameHost host, OsuConfigManager config, SessionStatics statics) { this.host = host; - allowScreenSuspension = host.AllowScreenSuspension.GetBoundCopy(); - allowScreenSuspension.ValueChanged += toggleWinKey; + disableWinKey = statics.GetBindable(Static.DisableWindowsKey); + disableWinKey.ValueChanged += toggleWinKey; - disableWinKey = config.GetBindable(OsuSetting.GameplayDisableWinKey); - disableWinKey.BindValueChanged(t => allowScreenSuspension.TriggerChange(), true); + disableWinKeySetting = config.GetBindable(OsuSetting.GameplayDisableWinKey); + disableWinKeySetting.BindValueChanged(t => disableWinKey.TriggerChange(), true); } private void toggleWinKey(ValueChangedEvent e) { - if (!e.NewValue && disableWinKey.Value) + if (e.NewValue && disableWinKeySetting.Value) host.InputThread.Scheduler.Add(WindowsKey.Disable); else host.InputThread.Scheduler.Add(WindowsKey.Enable); diff --git a/osu.Game/Configuration/SessionStatics.cs b/osu.Game/Configuration/SessionStatics.cs index 40b2adb867..7aad79b5ad 100644 --- a/osu.Game/Configuration/SessionStatics.cs +++ b/osu.Game/Configuration/SessionStatics.cs @@ -12,12 +12,14 @@ namespace osu.Game.Configuration { Set(Static.LoginOverlayDisplayed, false); Set(Static.MutedAudioNotificationShownOnce, false); + Set(Static.DisableWindowsKey, false); } } public enum Static { LoginOverlayDisplayed, - MutedAudioNotificationShownOnce + MutedAudioNotificationShownOnce, + DisableWindowsKey } } diff --git a/osu.Game/Screens/Play/ScreenSuspensionHandler.cs b/osu.Game/Screens/Play/ScreenSuspensionHandler.cs index 8585a5c309..c2c7f1ac41 100644 --- a/osu.Game/Screens/Play/ScreenSuspensionHandler.cs +++ b/osu.Game/Screens/Play/ScreenSuspensionHandler.cs @@ -8,6 +8,7 @@ using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Platform; +using osu.Game.Configuration; namespace osu.Game.Screens.Play { @@ -22,6 +23,9 @@ namespace osu.Game.Screens.Play [Resolved] private GameHost host { get; set; } + [Resolved] + private SessionStatics statics { get; set; } + public ScreenSuspensionHandler([NotNull] GameplayClockContainer gameplayClockContainer) { this.gameplayClockContainer = gameplayClockContainer ?? throw new ArgumentNullException(nameof(gameplayClockContainer)); @@ -36,7 +40,11 @@ namespace osu.Game.Screens.Play Debug.Assert(host.AllowScreenSuspension.Value); isPaused = gameplayClockContainer.IsPaused.GetBoundCopy(); - isPaused.BindValueChanged(paused => host.AllowScreenSuspension.Value = paused.NewValue, true); + isPaused.BindValueChanged(paused => + { + host.AllowScreenSuspension.Value = paused.NewValue; + statics.Set(Static.DisableWindowsKey, !paused.NewValue); + }, true); } protected override void Dispose(bool isDisposing) @@ -46,7 +54,10 @@ namespace osu.Game.Screens.Play isPaused?.UnbindAll(); if (host != null) + { host.AllowScreenSuspension.Value = true; + statics.Set(Static.DisableWindowsKey, false); + } } } }