Disable windows key only while in gameplay.

This commit is contained in:
Lucas A 2020-07-23 12:45:14 +02:00
parent 4102dae999
commit 5e6adfff99
2 changed files with 15 additions and 2 deletions

View File

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

View File

@ -1,11 +1,14 @@
// 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
{
@ -14,8 +17,16 @@ namespace osu.Desktop.Windows
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)
{
@ -30,7 +41,9 @@ namespace osu.Desktop.Windows
private void toggleWinKey(ValueChangedEvent<bool> e)
{
if (!e.NewValue && disableWinKey.Value)
var isPlayer = typeof(Player).IsAssignableFrom(currentScreenType) && currentScreenType != typeof(ReplayPlayer);
if (!e.NewValue && disableWinKey.Value && isPlayer)
host.InputThread.Scheduler.Add(WindowsKey.Disable);
else
host.InputThread.Scheduler.Add(WindowsKey.Enable);