2020-07-01 17:15:41 +02: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.
|
|
|
|
|
|
2022-06-17 16:37:17 +09:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2020-07-01 17:15:41 +02:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Platform;
|
|
|
|
|
using osu.Game.Configuration;
|
2021-08-17 16:13:45 +09:00
|
|
|
|
using osu.Game.Screens.Play;
|
2020-07-01 17:15:41 +02:00
|
|
|
|
|
|
|
|
|
namespace osu.Desktop.Windows
|
|
|
|
|
{
|
2020-07-24 16:38:48 +09:00
|
|
|
|
public class GameplayWinKeyBlocker : Component
|
2020-07-01 17:15:41 +02:00
|
|
|
|
{
|
|
|
|
|
private Bindable<bool> disableWinKey;
|
2021-08-17 16:13:45 +09:00
|
|
|
|
private IBindable<bool> localUserPlaying;
|
2021-12-20 17:38:14 +09:00
|
|
|
|
private IBindable<bool> isActive;
|
2020-07-01 17:15:41 +02:00
|
|
|
|
|
2020-10-10 13:11:36 +09:00
|
|
|
|
[Resolved]
|
|
|
|
|
private GameHost host { get; set; }
|
2020-07-01 17:15:41 +02:00
|
|
|
|
|
2020-10-10 13:28:24 +09:00
|
|
|
|
[BackgroundDependencyLoader]
|
2021-08-17 16:13:45 +09:00
|
|
|
|
private void load(ILocalUserPlayInfo localUserInfo, OsuConfigManager config)
|
2020-07-01 17:15:41 +02:00
|
|
|
|
{
|
2021-08-17 16:13:45 +09:00
|
|
|
|
localUserPlaying = localUserInfo.IsPlaying.GetBoundCopy();
|
2020-10-10 13:11:36 +09:00
|
|
|
|
localUserPlaying.BindValueChanged(_ => updateBlocking());
|
2020-07-01 17:15:41 +02:00
|
|
|
|
|
2021-12-20 17:38:14 +09:00
|
|
|
|
isActive = host.IsActive.GetBoundCopy();
|
|
|
|
|
isActive.BindValueChanged(_ => updateBlocking());
|
|
|
|
|
|
2020-07-22 21:45:27 +02:00
|
|
|
|
disableWinKey = config.GetBindable<bool>(OsuSetting.GameplayDisableWinKey);
|
2020-07-24 16:38:48 +09:00
|
|
|
|
disableWinKey.BindValueChanged(_ => updateBlocking(), true);
|
2020-07-01 17:15:41 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-24 16:38:48 +09:00
|
|
|
|
private void updateBlocking()
|
2020-07-01 17:15:41 +02:00
|
|
|
|
{
|
2021-12-20 17:38:14 +09:00
|
|
|
|
bool shouldDisable = isActive.Value && disableWinKey.Value && localUserPlaying.Value;
|
2020-07-23 12:45:14 +02:00
|
|
|
|
|
2020-07-24 16:38:48 +09:00
|
|
|
|
if (shouldDisable)
|
2020-07-01 17:15:41 +02:00
|
|
|
|
host.InputThread.Scheduler.Add(WindowsKey.Disable);
|
|
|
|
|
else
|
|
|
|
|
host.InputThread.Scheduler.Add(WindowsKey.Enable);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|