Merge pull request #1407 from nopeless/main

feat: improve focus behavior
This commit is contained in:
Serge
2023-10-02 23:49:49 +02:00
committed by GitHub
3 changed files with 38 additions and 7 deletions

View File

@@ -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)

View File

@@ -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
}
}

View File

@@ -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();
}
/// <summary>
/// Closes all forms except the settings. Hides the settings
/// </summary>
public void HideAll()
{
this.Hide();
@@ -847,6 +853,22 @@ namespace GHelper
if (updates != null && updates.Text != "") updates.Close();
}
/// <summary>
/// Brings all visible windows to the top, with settings being the focus
/// </summary>
public void ShowAll()
{
this.Activate();
}
/// <summary>
/// Check if any of fans, keyboard, update, or itself has focus
/// </summary>
/// <returns>Focus state</returns>
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)
{