Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potential solution to #1202 (AutoFocus toolbar) regression #1363

Closed
Sxderp opened this issue Jun 14, 2022 · 2 comments
Closed

Potential solution to #1202 (AutoFocus toolbar) regression #1363

Sxderp opened this issue Jun 14, 2022 · 2 comments

Comments

@Sxderp
Copy link
Contributor

Sxderp commented Jun 14, 2022

The problem with the original solution to #1202 is that it unconditionally focused the toolbar when the mouse hovered over it. This would cause odd behavior if you focused the program, moved your mouse over the toolbar, and expected certain keyboard shortcuts to work.

I'm not making this a PR as it seems a bit hacky as it (ab)uses Control.Tag. I wanted to use a custom property on frmMain but I was running into typing issues (property doesn't exist on TopLevelControl type etc etc) and I don't know enough about C# to fix it.

diff --git a/Source/Components/ImageGlass.UI/Toolbar/ModernToolbar.cs b/Source/Components/ImageGlass.UI/Toolbar/ModernToolbar.cs
index 3a547879..cbd52efa 100644
--- a/Source/Components/ImageGlass.UI/Toolbar/ModernToolbar.cs
+++ b/Source/Components/ImageGlass.UI/Toolbar/ModernToolbar.cs
@@ -126,7 +126,8 @@ namespace ImageGlass.UI {
         }
 
         protected override void OnMouseEnter(EventArgs e) {
-            if (AutoFocus && CanFocus && !Focused)
+            bool isWinActive = (bool) TopLevelControl.Tag;
+            if (AutoFocus && !isWinActive && CanFocus && !Focused)
                 Focus();
 
             base.OnMouseEnter(e);
diff --git a/Source/ImageGlass/frmMain.Designer.cs b/Source/ImageGlass/frmMain.Designer.cs
index 8ae1887e..012ac3fb 100644
--- a/Source/ImageGlass/frmMain.Designer.cs
+++ b/Source/ImageGlass/frmMain.Designer.cs
@@ -2049,6 +2049,7 @@
             this.RightToLeftLayout = true;
             this.Text = "ImageGlass";
             this.Activated += new System.EventHandler(this.frmMain_Activated);
+            this.Deactivate += new System.EventHandler(this.frmMain_Deactivate);
             this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.frmMain_FormClosing);
             this.Load += new System.EventHandler(this.frmMain_Load);
             this.ResizeBegin += new System.EventHandler(this.frmMain_ResizeBegin);
diff --git a/Source/ImageGlass/frmMain.cs b/Source/ImageGlass/frmMain.cs
index 93d0a0f5..ee16a51a 100644
--- a/Source/ImageGlass/frmMain.cs
+++ b/Source/ImageGlass/frmMain.cs
@@ -3355,6 +3355,7 @@ namespace ImageGlass {
         }
 
         private void frmMain_Activated(object sender, EventArgs e) {
+            Tag = true;
             var flags = Local.ForceUpdateActions;
 
             // do nothing
@@ -3699,6 +3700,9 @@ namespace ImageGlass {
             Local.ForceUpdateActions = ForceUpdateActions.NONE;
         }
 
+        private void frmMain_Deactivate(object sender, EventArgs e) {
+            Tag = false;
+        }
 
         private void frmMain_Resize(object sender, EventArgs e) {
             if (WindowState != _windowState) {
@d2phap
Copy link
Owner

d2phap commented Jul 25, 2023

This issue is fixed in ImageGlass 9.0 beta 5

@d2phap
Copy link
Owner

d2phap commented Sep 26, 2023

This issue is also fixed in v8.10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants