mirror of
https://github.com/ppy/osu
synced 2024-12-25 00:02:48 +00:00
Disable the windows key only when in gameplay.
This commit is contained in:
parent
022e4b6335
commit
939441ae40
@ -11,26 +11,26 @@ namespace osu.Desktop.Windows
|
|||||||
{
|
{
|
||||||
public class GameplayWinKeyHandler : Component
|
public class GameplayWinKeyHandler : Component
|
||||||
{
|
{
|
||||||
private Bindable<bool> allowScreenSuspension;
|
|
||||||
private Bindable<bool> disableWinKey;
|
private Bindable<bool> disableWinKey;
|
||||||
|
private Bindable<bool> disableWinKeySetting;
|
||||||
|
|
||||||
private GameHost host;
|
private GameHost host;
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(GameHost host, OsuConfigManager config)
|
private void load(GameHost host, OsuConfigManager config, SessionStatics statics)
|
||||||
{
|
{
|
||||||
this.host = host;
|
this.host = host;
|
||||||
|
|
||||||
allowScreenSuspension = host.AllowScreenSuspension.GetBoundCopy();
|
disableWinKey = statics.GetBindable<bool>(Static.DisableWindowsKey);
|
||||||
allowScreenSuspension.ValueChanged += toggleWinKey;
|
disableWinKey.ValueChanged += toggleWinKey;
|
||||||
|
|
||||||
disableWinKey = config.GetBindable<bool>(OsuSetting.GameplayDisableWinKey);
|
disableWinKeySetting = config.GetBindable<bool>(OsuSetting.GameplayDisableWinKey);
|
||||||
disableWinKey.BindValueChanged(t => allowScreenSuspension.TriggerChange(), true);
|
disableWinKeySetting.BindValueChanged(t => disableWinKey.TriggerChange(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void toggleWinKey(ValueChangedEvent<bool> e)
|
private void toggleWinKey(ValueChangedEvent<bool> e)
|
||||||
{
|
{
|
||||||
if (!e.NewValue && disableWinKey.Value)
|
if (e.NewValue && disableWinKeySetting.Value)
|
||||||
host.InputThread.Scheduler.Add(WindowsKey.Disable);
|
host.InputThread.Scheduler.Add(WindowsKey.Disable);
|
||||||
else
|
else
|
||||||
host.InputThread.Scheduler.Add(WindowsKey.Enable);
|
host.InputThread.Scheduler.Add(WindowsKey.Enable);
|
||||||
|
@ -12,12 +12,14 @@ namespace osu.Game.Configuration
|
|||||||
{
|
{
|
||||||
Set(Static.LoginOverlayDisplayed, false);
|
Set(Static.LoginOverlayDisplayed, false);
|
||||||
Set(Static.MutedAudioNotificationShownOnce, false);
|
Set(Static.MutedAudioNotificationShownOnce, false);
|
||||||
|
Set(Static.DisableWindowsKey, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum Static
|
public enum Static
|
||||||
{
|
{
|
||||||
LoginOverlayDisplayed,
|
LoginOverlayDisplayed,
|
||||||
MutedAudioNotificationShownOnce
|
MutedAudioNotificationShownOnce,
|
||||||
|
DisableWindowsKey
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ using osu.Framework.Allocation;
|
|||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
|
using osu.Game.Configuration;
|
||||||
|
|
||||||
namespace osu.Game.Screens.Play
|
namespace osu.Game.Screens.Play
|
||||||
{
|
{
|
||||||
@ -22,6 +23,9 @@ namespace osu.Game.Screens.Play
|
|||||||
[Resolved]
|
[Resolved]
|
||||||
private GameHost host { get; set; }
|
private GameHost host { get; set; }
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private SessionStatics statics { get; set; }
|
||||||
|
|
||||||
public ScreenSuspensionHandler([NotNull] GameplayClockContainer gameplayClockContainer)
|
public ScreenSuspensionHandler([NotNull] GameplayClockContainer gameplayClockContainer)
|
||||||
{
|
{
|
||||||
this.gameplayClockContainer = gameplayClockContainer ?? throw new ArgumentNullException(nameof(gameplayClockContainer));
|
this.gameplayClockContainer = gameplayClockContainer ?? throw new ArgumentNullException(nameof(gameplayClockContainer));
|
||||||
@ -36,7 +40,11 @@ namespace osu.Game.Screens.Play
|
|||||||
Debug.Assert(host.AllowScreenSuspension.Value);
|
Debug.Assert(host.AllowScreenSuspension.Value);
|
||||||
|
|
||||||
isPaused = gameplayClockContainer.IsPaused.GetBoundCopy();
|
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)
|
protected override void Dispose(bool isDisposing)
|
||||||
@ -46,7 +54,10 @@ namespace osu.Game.Screens.Play
|
|||||||
isPaused?.UnbindAll();
|
isPaused?.UnbindAll();
|
||||||
|
|
||||||
if (host != null)
|
if (host != null)
|
||||||
|
{
|
||||||
host.AllowScreenSuspension.Value = true;
|
host.AllowScreenSuspension.Value = true;
|
||||||
|
statics.Set(Static.DisableWindowsKey, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user