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 1/3] 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) { From a30920ed70b7773c2d1fd9aaadcb68fecb0e3e9d Mon Sep 17 00:00:00 2001 From: nopeless <38830903+nopeless@users.noreply.github.com> Date: Mon, 2 Oct 2023 14:09:52 -0500 Subject: [PATCH 2/3] fix: respect tray icon behavior --- app/Input/InputDispatcher.cs | 4 ++-- app/Program.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) 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 88948c83..390c568c 100644 --- a/app/Program.cs +++ b/app/Program.cs @@ -213,13 +213,13 @@ namespace GHelper SetAutoModes(true); } - public static void SettingsToggle(string action = "") + public static void SettingsToggle(string action = "", bool checkForFocus = false) { 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()) + if (checkForFocus && !settingsForm.HasAnyFocus()) { settingsForm.ShowAll(); } From 97361e010ed800f4236e4def1391579f0c30b238 Mon Sep 17 00:00:00 2001 From: nopeless <38830903+nopeless@users.noreply.github.com> Date: Mon, 2 Oct 2023 14:30:57 -0500 Subject: [PATCH 3/3] refactor: use `AddOwnedForm` for group behavior --- app/Settings.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/Settings.cs b/app/Settings.cs index bfd5c415..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(); @@ -849,14 +855,9 @@ namespace GHelper /// /// 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(); }