1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 17:35:10 +08:00

Rename class and remove screen conditionals

This commit is contained in:
Dean Herbert 2020-07-24 16:38:48 +09:00
parent 5e6adfff99
commit dbe9180c55
3 changed files with 8 additions and 19 deletions

View File

@ -101,7 +101,7 @@ namespace osu.Desktop
LoadComponentAsync(new DiscordRichPresence(), Add);
if (RuntimeInfo.OS == RuntimeInfo.Platform.Windows)
LoadComponentAsync(new GameplayWinKeyHandler(ScreenStack), Add);
LoadComponentAsync(new GameplayWinKeyBlocker(), Add);
}
protected override void ScreenChanged(IScreen lastScreen, IScreen newScreen)

View File

@ -1,49 +1,38 @@
// 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 System;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Platform;
using osu.Game.Configuration;
using osu.Game.Screens;
using osu.Game.Screens.Play;
namespace osu.Desktop.Windows
{
public class GameplayWinKeyHandler : Component
public class GameplayWinKeyBlocker : Component
{
private Bindable<bool> allowScreenSuspension;
private Bindable<bool> disableWinKey;
private readonly OsuScreenStack screenStack;
private GameHost host;
private Type currentScreenType => screenStack.CurrentScreen?.GetType();
public GameplayWinKeyHandler(OsuScreenStack stack)
{
screenStack = stack;
}
[BackgroundDependencyLoader]
private void load(GameHost host, OsuConfigManager config)
{
this.host = host;
allowScreenSuspension = host.AllowScreenSuspension.GetBoundCopy();
allowScreenSuspension.ValueChanged += toggleWinKey;
allowScreenSuspension.BindValueChanged(_ => updateBlocking());
disableWinKey = config.GetBindable<bool>(OsuSetting.GameplayDisableWinKey);
disableWinKey.BindValueChanged(t => allowScreenSuspension.TriggerChange(), true);
disableWinKey.BindValueChanged(_ => updateBlocking(), true);
}
private void toggleWinKey(ValueChangedEvent<bool> e)
private void updateBlocking()
{
var isPlayer = typeof(Player).IsAssignableFrom(currentScreenType) && currentScreenType != typeof(ReplayPlayer);
bool shouldDisable = disableWinKey.Value && !allowScreenSuspension.Value;
if (!e.NewValue && disableWinKey.Value && isPlayer)
if (shouldDisable)
host.InputThread.Scheduler.Add(WindowsKey.Disable);
else
host.InputThread.Scheduler.Add(WindowsKey.Enable);

View File

@ -21,7 +21,7 @@ namespace osu.Desktop.Windows
private static IntPtr keyHook;
[StructLayout(LayoutKind.Explicit)]
private struct KdDllHookStruct
private readonly struct KdDllHookStruct
{
[FieldOffset(0)]
public readonly int VkCode;