osu/osu.Desktop/Windows/GameplayWinKeyBlocker.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

46 lines
1.6 KiB
C#
Raw Normal View History

2020-07-01 15:15:41 +00:00
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Platform;
using osu.Game.Configuration;
using osu.Game.Screens.Play;
2020-07-01 15:15:41 +00:00
namespace osu.Desktop.Windows
{
public partial class GameplayWinKeyBlocker : Component
2020-07-01 15:15:41 +00:00
{
private Bindable<bool> disableWinKey = null!;
private IBindable<LocalUserPlayingState> localUserPlaying = null!;
private IBindable<bool> isActive = null!;
2020-07-01 15:15:41 +00:00
[Resolved]
private GameHost host { get; set; } = null!;
2020-07-01 15:15:41 +00:00
2020-10-10 04:28:24 +00:00
[BackgroundDependencyLoader]
private void load(ILocalUserPlayInfo localUserInfo, OsuConfigManager config)
2020-07-01 15:15:41 +00:00
{
localUserPlaying = localUserInfo.PlayingState.GetBoundCopy();
localUserPlaying.BindValueChanged(_ => updateBlocking());
2020-07-01 15:15:41 +00:00
isActive = host.IsActive.GetBoundCopy();
isActive.BindValueChanged(_ => updateBlocking());
2020-07-22 19:45:27 +00:00
disableWinKey = config.GetBindable<bool>(OsuSetting.GameplayDisableWinKey);
disableWinKey.BindValueChanged(_ => updateBlocking(), true);
2020-07-01 15:15:41 +00:00
}
private void updateBlocking()
2020-07-01 15:15:41 +00:00
{
bool shouldDisable = isActive.Value && disableWinKey.Value && localUserPlaying.Value == LocalUserPlayingState.Playing;
if (shouldDisable)
2020-07-01 15:15:41 +00:00
host.InputThread.Scheduler.Add(WindowsKey.Disable);
else
host.InputThread.Scheduler.Add(WindowsKey.Enable);
}
}
}