1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 18:42:56 +08:00
osu-lazer/osu.Desktop/Windows/GameplayWinKeyBlocker.cs

42 lines
1.3 KiB
C#
Raw Normal View History

2020-07-01 23:15:41 +08: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;
2020-07-01 23:15:41 +08:00
using osu.Game.Configuration;
namespace osu.Desktop.Windows
{
public class GameplayWinKeyBlocker : Component
2020-07-01 23:15:41 +08:00
{
private Bindable<bool> disableWinKey;
private Bindable<bool> localUserPlaying;
2020-07-01 23:15:41 +08:00
[Resolved]
private GameHost host { get; set; }
2020-07-01 23:15:41 +08:00
2020-10-10 12:28:24 +08:00
[BackgroundDependencyLoader]
private void load(OsuGame game, OsuConfigManager config)
2020-07-01 23:15:41 +08:00
{
localUserPlaying = game.LocalUserPlaying.GetBoundCopy();
localUserPlaying.BindValueChanged(_ => updateBlocking());
2020-07-01 23:15:41 +08:00
2020-07-23 03:45:27 +08:00
disableWinKey = config.GetBindable<bool>(OsuSetting.GameplayDisableWinKey);
disableWinKey.BindValueChanged(_ => updateBlocking(), true);
2020-07-01 23:15:41 +08:00
}
private void updateBlocking()
2020-07-01 23:15:41 +08:00
{
bool shouldDisable = disableWinKey.Value && localUserPlaying.Value;
if (shouldDisable)
2020-07-01 23:15:41 +08:00
host.InputThread.Scheduler.Add(WindowsKey.Disable);
else
host.InputThread.Scheduler.Add(WindowsKey.Enable);
}
}
}