From 5d5f2354c123ac90600d83cdb85f8d473cdc61cc Mon Sep 17 00:00:00 2001 From: goat <16760685+goaaats@users.noreply.github.com> Date: Sat, 11 Sep 2021 20:04:03 +0200 Subject: [PATCH] feat: add IsFocusManagementEnabled to dalamud config --- Dalamud/Configuration/Internal/DalamudConfiguration.cs | 5 +++++ Dalamud/Game/Internal/DalamudAtkTweaks.cs | 4 ++-- Dalamud/Interface/Internal/Windows/SettingsWindow.cs | 6 ++++++ Dalamud/Interface/Windowing/Window.cs | 5 +++-- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Dalamud/Configuration/Internal/DalamudConfiguration.cs b/Dalamud/Configuration/Internal/DalamudConfiguration.cs index c56a31b9d..4f3e4e59c 100644 --- a/Dalamud/Configuration/Internal/DalamudConfiguration.cs +++ b/Dalamud/Configuration/Internal/DalamudConfiguration.cs @@ -169,6 +169,11 @@ namespace Dalamud.Configuration.Internal /// public bool IsGamepadNavigationEnabled { get; set; } = true; + /// + /// Gets or sets a value indicating whether or not focus management is enabled. + /// + public bool IsFocusManagementEnabled { get; set; } = true; + /// /// Gets or sets a value indicating whether or not the anti-anti-debug check is enabled on startup. /// diff --git a/Dalamud/Game/Internal/DalamudAtkTweaks.cs b/Dalamud/Game/Internal/DalamudAtkTweaks.cs index 2e081e9a6..0169bd723 100644 --- a/Dalamud/Game/Internal/DalamudAtkTweaks.cs +++ b/Dalamud/Game/Internal/DalamudAtkTweaks.cs @@ -77,7 +77,7 @@ namespace Dalamud.Game.Internal // Log.Information("{0}: cmd#{1} a3#{2} - HasAnyFocus:{3}", Marshal.PtrToStringAnsi(new IntPtr(thisPtr->Name)), cmd, a3, WindowSystem.HasAnyWindowSystemFocus); // "Close Addon" - if (cmd == 12 && WindowSystem.HasAnyWindowSystemFocus) + if (cmd == 12 && WindowSystem.HasAnyWindowSystemFocus && Service.Get().IsFocusManagementEnabled) { Log.Verbose($"Cancelling global event CloseAddon command due to WindowSystem {WindowSystem.FocusedWindowSystemNamespace}"); return IntPtr.Zero; @@ -88,7 +88,7 @@ namespace Dalamud.Game.Internal private void AgentHudOpenSystemMenuDetour(void* thisPtr, AtkValue* atkValueArgs, uint menuSize) { - if (WindowSystem.HasAnyWindowSystemFocus) + if (WindowSystem.HasAnyWindowSystemFocus && Service.Get().IsFocusManagementEnabled) { Log.Verbose($"Cancelling OpenSystemMenu due to WindowSystem {WindowSystem.FocusedWindowSystemNamespace}"); return; diff --git a/Dalamud/Interface/Internal/Windows/SettingsWindow.cs b/Dalamud/Interface/Internal/Windows/SettingsWindow.cs index 4d1ddec3e..260aa8ed9 100644 --- a/Dalamud/Interface/Internal/Windows/SettingsWindow.cs +++ b/Dalamud/Interface/Internal/Windows/SettingsWindow.cs @@ -44,6 +44,7 @@ namespace Dalamud.Interface.Internal.Windows private bool doDocking; private bool doViewport; private bool doGamepad; + private bool doFocus; private List thirdRepoList; private bool thirdRepoListChanged; @@ -89,6 +90,7 @@ namespace Dalamud.Interface.Internal.Windows this.doDocking = configuration.IsDocking; this.doViewport = !configuration.IsDisableViewport; this.doGamepad = configuration.IsGamepadNavigationEnabled; + this.doFocus = configuration.IsFocusManagementEnabled; this.doPluginTest = configuration.DoPluginTest; this.thirdRepoList = configuration.ThirdRepoList.Select(x => x.Clone()).ToList(); @@ -249,6 +251,9 @@ namespace Dalamud.Interface.Internal.Windows ImGuiHelpers.ScaledDummy(10, 16); + ImGui.Checkbox(Loc.Localize("DalamudSettingToggleFocusManagement", "Use escape to close Dalamud windows"), ref this.doFocus); + ImGui.TextColored(this.hintTextColor, Loc.Localize("DalamudSettingToggleFocusManagementHint", "This will cause Dalamud windows to behave like in-game windows when pressing escape.\nThey will close one after another until all are closed. May not work for all plugins.")); + ImGui.Checkbox(Loc.Localize("DalamudSettingToggleViewports", "Enable multi-monitor windows"), ref this.doViewport); ImGui.TextColored(this.hintTextColor, Loc.Localize("DalamudSettingToggleViewportsHint", "This will allow you move plugin windows onto other monitors.\nWill only work in Borderless Window or Windowed mode.")); @@ -566,6 +571,7 @@ namespace Dalamud.Interface.Internal.Windows configuration.IsDocking = this.doDocking; configuration.IsGamepadNavigationEnabled = this.doGamepad; + configuration.IsFocusManagementEnabled = this.doFocus; // This is applied every frame in InterfaceManager::CheckViewportState() configuration.IsDisableViewport = !this.doViewport; diff --git a/Dalamud/Interface/Windowing/Window.cs b/Dalamud/Interface/Windowing/Window.cs index 7764e1e2c..575a65b79 100644 --- a/Dalamud/Interface/Windowing/Window.cs +++ b/Dalamud/Interface/Windowing/Window.cs @@ -1,5 +1,5 @@ using System.Numerics; - +using Dalamud.Configuration.Internal; using Dalamud.Game.ClientState.Keys; using ImGuiNET; @@ -200,7 +200,8 @@ namespace Dalamud.Interface.Windowing this.IsFocused = ImGui.IsWindowFocused(ImGuiFocusedFlags.RootAndChildWindows); var escapeDown = Service.Get()[VirtualKey.ESCAPE]; - if (escapeDown && this.IsFocused && !wasEscPressedLastFrame && this.RespectCloseHotkey) + var isAllowed = Service.Get().IsFocusManagementEnabled; + if (escapeDown && this.IsFocused && isAllowed && !wasEscPressedLastFrame && this.RespectCloseHotkey) { this.IsOpen = false; wasEscPressedLastFrame = true;