<commit_before>﻿// Copyright (c) p<NAME>ty Ltd <<EMAIL>>. 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.Configuration;

namespace osu.Desktop.Windows
{
    public class GameplayWinKeyBlocker : Component
    {
        private Bindable<bool> allowScreenSuspension;
        private Bindable<bool> disableWinKey;

        private GameHost host;

        [BackgroundDependencyLoader]
        private void load(GameHost host, OsuConfigManager config)
        {
            this.host = host;

            allowScreenSuspension = host.AllowScreenSuspension.GetBoundCopy();
            allowScreenSuspension.BindValueChanged(_ => updateBlocking());

            disableWinKey = config.GetBindable<bool>(OsuSetting.GameplayDisableWinKey);
            disableWinKey.BindValueChanged(_ => updateBlocking(), true);
        }

        private void updateBlocking()
        {
            bool shouldDisable = disableWinKey.Value && !allowScreenSuspension.Value;

            if (shouldDisable)
                host.InputThread.Scheduler.Add(WindowsKey.Disable);
            else
                host.InputThread.Scheduler.Add(WindowsKey.Enable);<commit_msg>Fix windows key blocking applying when window is inactive / when watching a replay<commit_after>﻿// Copyright (c) p<NAME> Ltd <<EMAIL>>. 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;
using osu.Game.Configuration;

namespace osu.Desktop.Windows
{
    public class GameplayWinKeyBlocker : Component
    {
        private Bindable<bool> disableWinKey;
        private Bindable<bool> localUserPlaying;

        [Resolved]
        private GameHost host { get; set; }

        [BackgroundDependencyLoader(true)]
        private void load(OsuGame game, OsuConfigManager config)
        {
            localUserPlaying = game.LocalUserPlaying.GetBoundCopy();
            localUserPlaying.BindValueChanged(_ => updateBlocking());

            disableWinKey = config.GetBindable<bool>(OsuSetting.GameplayDisableWinKey);
            disableWinKey.BindValueChanged(_ => updateBlocking(), true);
        }

        private void updateBlocking()
        {
            bool shouldDisable = disableWinKey.Value && localUserPlaying.Value;

            if (shouldDisable)
                host.InputThread.Scheduler.Add(WindowsKey.Disable);
            else
                host.InputThread.Scheduler.Add(WindowsKey.Enable);
{'fraction_non_alphanumeric': 0.08476434051881622, 'fraction_numerical': 0.0, 'mean_word_length': 2.9114285714285715, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3944484', 'n_tokens_mistral': 744, 'n_tokens_neox': 712, 'n_words': 170}