mirror of
https://github.com/osukey/osukey.git
synced 2025-07-02 00:40:09 +09:00
Rename class and remove screen conditionals
This commit is contained in:
@ -101,7 +101,7 @@ namespace osu.Desktop
|
|||||||
LoadComponentAsync(new DiscordRichPresence(), Add);
|
LoadComponentAsync(new DiscordRichPresence(), Add);
|
||||||
|
|
||||||
if (RuntimeInfo.OS == RuntimeInfo.Platform.Windows)
|
if (RuntimeInfo.OS == RuntimeInfo.Platform.Windows)
|
||||||
LoadComponentAsync(new GameplayWinKeyHandler(ScreenStack), Add);
|
LoadComponentAsync(new GameplayWinKeyBlocker(), Add);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void ScreenChanged(IScreen lastScreen, IScreen newScreen)
|
protected override void ScreenChanged(IScreen lastScreen, IScreen newScreen)
|
||||||
|
@ -1,49 +1,38 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
using osu.Game.Configuration;
|
using osu.Game.Configuration;
|
||||||
using osu.Game.Screens;
|
|
||||||
using osu.Game.Screens.Play;
|
|
||||||
|
|
||||||
namespace osu.Desktop.Windows
|
namespace osu.Desktop.Windows
|
||||||
{
|
{
|
||||||
public class GameplayWinKeyHandler : Component
|
public class GameplayWinKeyBlocker : Component
|
||||||
{
|
{
|
||||||
private Bindable<bool> allowScreenSuspension;
|
private Bindable<bool> allowScreenSuspension;
|
||||||
private Bindable<bool> disableWinKey;
|
private Bindable<bool> disableWinKey;
|
||||||
|
|
||||||
private readonly OsuScreenStack screenStack;
|
|
||||||
private GameHost host;
|
private GameHost host;
|
||||||
|
|
||||||
private Type currentScreenType => screenStack.CurrentScreen?.GetType();
|
|
||||||
|
|
||||||
public GameplayWinKeyHandler(OsuScreenStack stack)
|
|
||||||
{
|
|
||||||
screenStack = stack;
|
|
||||||
}
|
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(GameHost host, OsuConfigManager config)
|
private void load(GameHost host, OsuConfigManager config)
|
||||||
{
|
{
|
||||||
this.host = host;
|
this.host = host;
|
||||||
|
|
||||||
allowScreenSuspension = host.AllowScreenSuspension.GetBoundCopy();
|
allowScreenSuspension = host.AllowScreenSuspension.GetBoundCopy();
|
||||||
allowScreenSuspension.ValueChanged += toggleWinKey;
|
allowScreenSuspension.BindValueChanged(_ => updateBlocking());
|
||||||
|
|
||||||
disableWinKey = config.GetBindable<bool>(OsuSetting.GameplayDisableWinKey);
|
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);
|
host.InputThread.Scheduler.Add(WindowsKey.Disable);
|
||||||
else
|
else
|
||||||
host.InputThread.Scheduler.Add(WindowsKey.Enable);
|
host.InputThread.Scheduler.Add(WindowsKey.Enable);
|
@ -21,7 +21,7 @@ namespace osu.Desktop.Windows
|
|||||||
private static IntPtr keyHook;
|
private static IntPtr keyHook;
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Explicit)]
|
[StructLayout(LayoutKind.Explicit)]
|
||||||
private struct KdDllHookStruct
|
private readonly struct KdDllHookStruct
|
||||||
{
|
{
|
||||||
[FieldOffset(0)]
|
[FieldOffset(0)]
|
||||||
public readonly int VkCode;
|
public readonly int VkCode;
|
||||||
|
Reference in New Issue
Block a user