feat: add IsFocusManagementEnabled to dalamud config

This commit is contained in:
goat 2021-09-11 20:04:03 +02:00
parent eb11857bac
commit 5d5f2354c1
No known key found for this signature in database
GPG key ID: 7773BB5B43BA52E5
4 changed files with 16 additions and 4 deletions

View file

@ -169,6 +169,11 @@ namespace Dalamud.Configuration.Internal
/// </summary> /// </summary>
public bool IsGamepadNavigationEnabled { get; set; } = true; public bool IsGamepadNavigationEnabled { get; set; } = true;
/// <summary>
/// Gets or sets a value indicating whether or not focus management is enabled.
/// </summary>
public bool IsFocusManagementEnabled { get; set; } = true;
/// <summary> /// <summary>
/// Gets or sets a value indicating whether or not the anti-anti-debug check is enabled on startup. /// Gets or sets a value indicating whether or not the anti-anti-debug check is enabled on startup.
/// </summary> /// </summary>

View file

@ -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); // Log.Information("{0}: cmd#{1} a3#{2} - HasAnyFocus:{3}", Marshal.PtrToStringAnsi(new IntPtr(thisPtr->Name)), cmd, a3, WindowSystem.HasAnyWindowSystemFocus);
// "Close Addon" // "Close Addon"
if (cmd == 12 && WindowSystem.HasAnyWindowSystemFocus) if (cmd == 12 && WindowSystem.HasAnyWindowSystemFocus && Service<DalamudConfiguration>.Get().IsFocusManagementEnabled)
{ {
Log.Verbose($"Cancelling global event CloseAddon command due to WindowSystem {WindowSystem.FocusedWindowSystemNamespace}"); Log.Verbose($"Cancelling global event CloseAddon command due to WindowSystem {WindowSystem.FocusedWindowSystemNamespace}");
return IntPtr.Zero; return IntPtr.Zero;
@ -88,7 +88,7 @@ namespace Dalamud.Game.Internal
private void AgentHudOpenSystemMenuDetour(void* thisPtr, AtkValue* atkValueArgs, uint menuSize) private void AgentHudOpenSystemMenuDetour(void* thisPtr, AtkValue* atkValueArgs, uint menuSize)
{ {
if (WindowSystem.HasAnyWindowSystemFocus) if (WindowSystem.HasAnyWindowSystemFocus && Service<DalamudConfiguration>.Get().IsFocusManagementEnabled)
{ {
Log.Verbose($"Cancelling OpenSystemMenu due to WindowSystem {WindowSystem.FocusedWindowSystemNamespace}"); Log.Verbose($"Cancelling OpenSystemMenu due to WindowSystem {WindowSystem.FocusedWindowSystemNamespace}");
return; return;

View file

@ -44,6 +44,7 @@ namespace Dalamud.Interface.Internal.Windows
private bool doDocking; private bool doDocking;
private bool doViewport; private bool doViewport;
private bool doGamepad; private bool doGamepad;
private bool doFocus;
private List<ThirdPartyRepoSettings> thirdRepoList; private List<ThirdPartyRepoSettings> thirdRepoList;
private bool thirdRepoListChanged; private bool thirdRepoListChanged;
@ -89,6 +90,7 @@ namespace Dalamud.Interface.Internal.Windows
this.doDocking = configuration.IsDocking; this.doDocking = configuration.IsDocking;
this.doViewport = !configuration.IsDisableViewport; this.doViewport = !configuration.IsDisableViewport;
this.doGamepad = configuration.IsGamepadNavigationEnabled; this.doGamepad = configuration.IsGamepadNavigationEnabled;
this.doFocus = configuration.IsFocusManagementEnabled;
this.doPluginTest = configuration.DoPluginTest; this.doPluginTest = configuration.DoPluginTest;
this.thirdRepoList = configuration.ThirdRepoList.Select(x => x.Clone()).ToList(); this.thirdRepoList = configuration.ThirdRepoList.Select(x => x.Clone()).ToList();
@ -249,6 +251,9 @@ namespace Dalamud.Interface.Internal.Windows
ImGuiHelpers.ScaledDummy(10, 16); 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.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.")); 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.IsDocking = this.doDocking;
configuration.IsGamepadNavigationEnabled = this.doGamepad; configuration.IsGamepadNavigationEnabled = this.doGamepad;
configuration.IsFocusManagementEnabled = this.doFocus;
// This is applied every frame in InterfaceManager::CheckViewportState() // This is applied every frame in InterfaceManager::CheckViewportState()
configuration.IsDisableViewport = !this.doViewport; configuration.IsDisableViewport = !this.doViewport;

View file

@ -1,5 +1,5 @@
using System.Numerics; using System.Numerics;
using Dalamud.Configuration.Internal;
using Dalamud.Game.ClientState.Keys; using Dalamud.Game.ClientState.Keys;
using ImGuiNET; using ImGuiNET;
@ -200,7 +200,8 @@ namespace Dalamud.Interface.Windowing
this.IsFocused = ImGui.IsWindowFocused(ImGuiFocusedFlags.RootAndChildWindows); this.IsFocused = ImGui.IsWindowFocused(ImGuiFocusedFlags.RootAndChildWindows);
var escapeDown = Service<KeyState>.Get()[VirtualKey.ESCAPE]; var escapeDown = Service<KeyState>.Get()[VirtualKey.ESCAPE];
if (escapeDown && this.IsFocused && !wasEscPressedLastFrame && this.RespectCloseHotkey) var isAllowed = Service<DalamudConfiguration>.Get().IsFocusManagementEnabled;
if (escapeDown && this.IsFocused && isAllowed && !wasEscPressedLastFrame && this.RespectCloseHotkey)
{ {
this.IsOpen = false; this.IsOpen = false;
wasEscPressedLastFrame = true; wasEscPressedLastFrame = true;