From 4509b67ed9a8d9ba8de22db42ab580a0ecd37874 Mon Sep 17 00:00:00 2001 From: nopeless <38830903+nopeless@users.noreply.github.com> Date: Mon, 2 Oct 2023 14:00:52 -0500 Subject: [PATCH] feat: improve focus behavior --- app/Program.cs | 17 +++++++++++++---- app/Settings.cs | 21 +++++++++++++++++++++ 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/app/Program.cs b/app/Program.cs index a903a3fd..88948c83 100644 --- a/app/Program.cs +++ b/app/Program.cs @@ -213,11 +213,21 @@ namespace GHelper SetAutoModes(true); } - - public static void SettingsToggle(string action = "") { - if (settingsForm.Visible) settingsForm.HideAll(); + if (settingsForm.Visible) + { + // If helper window is not on top, this just focuses on the app again + // Pressing the ghelper button again will hide the app + if (!settingsForm.HasAnyFocus()) + { + settingsForm.ShowAll(); + } + else + { + settingsForm.HideAll(); + } + } else { @@ -279,5 +289,4 @@ namespace GHelper } - } \ No newline at end of file diff --git a/app/Settings.cs b/app/Settings.cs index 4fbd9a0d..bfd5c415 100644 --- a/app/Settings.cs +++ b/app/Settings.cs @@ -847,6 +847,27 @@ namespace GHelper if (updates != null && updates.Text != "") updates.Close(); } + /// + /// Brings all visible windows to the top, with settings being the focus + ///
+ /// Note: this will not respect previous focus i.e. will always focus settings + ///
+ public void ShowAll() + { + if (fans != null && fans.Visible) fans.Activate(); + if (keyb != null && keyb.Visible) keyb.Activate(); + if (updates != null && updates.Visible) updates.Activate(); + this.Activate(); + } + + /// + /// Check if any of fans, keyboard, update, or itself has focus + /// + /// Focus state + public bool HasAnyFocus() + { + return (fans != null && fans.ContainsFocus) || (keyb != null && keyb.ContainsFocus) || (updates != null && updates.ContainsFocus) || this.ContainsFocus; + } private void SettingsForm_FormClosing(object? sender, FormClosingEventArgs e) {