diff --git a/app/Input/InputDispatcher.cs b/app/Input/InputDispatcher.cs index 8565cb34..0cc17d66 100644 --- a/app/Input/InputDispatcher.cs +++ b/app/Input/InputDispatcher.cs @@ -337,7 +337,7 @@ namespace GHelper.Input if (e.Modifier == (ModifierKeys.Control | ModifierKeys.Shift)) { if (e.Key == keyProfile) modeControl.CyclePerformanceMode(); - if (e.Key == keyApp) Program.SettingsToggle(); + if (e.Key == keyApp) Program.SettingsToggle("", true); if (e.Key == Keys.F20) KeyProcess("m3"); } @@ -427,7 +427,7 @@ namespace GHelper.Input { Program.settingsForm.BeginInvoke(delegate { - Program.SettingsToggle(); + Program.SettingsToggle("", true); }); } catch (Exception ex) diff --git a/app/Program.cs b/app/Program.cs index a903a3fd..390c568c 100644 --- a/app/Program.cs +++ b/app/Program.cs @@ -213,11 +213,21 @@ namespace GHelper SetAutoModes(true); } - - - public static void SettingsToggle(string action = "") + public static void SettingsToggle(string action = "", bool checkForFocus = false) { - 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 (checkForFocus && !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..f3c3dd11 100644 --- a/app/Settings.cs +++ b/app/Settings.cs @@ -547,6 +547,7 @@ namespace GHelper if (matrix == null || matrix.Text == "") { matrix = new Matrix(); + AddOwnedForm(matrix); } if (matrix.Visible) @@ -615,6 +616,7 @@ namespace GHelper { keyb = new Extra(); keyb.Show(); + AddOwnedForm(keyb); } else { @@ -643,6 +645,7 @@ namespace GHelper if (fans == null || fans.Text == "") { fans = new Fans(); + AddOwnedForm(fans); } if (fans.Visible) @@ -839,6 +842,9 @@ namespace GHelper Application.Exit(); } + /// + /// Closes all forms except the settings. Hides the settings + /// public void HideAll() { this.Hide(); @@ -847,6 +853,22 @@ namespace GHelper if (updates != null && updates.Text != "") updates.Close(); } + /// + /// Brings all visible windows to the top, with settings being the focus + /// + public void ShowAll() + { + 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) {