This reverts commit ac70e4369a.

This commit is contained in:
Markus Hofknecht 2022-06-05 02:43:18 +02:00
parent ac70e4369a
commit faa32f96a2
5 changed files with 24 additions and 45 deletions

View file

@ -18,7 +18,6 @@ namespace SystemTrayMenu
private readonly AppNotifyIcon menuNotifyIcon = new(); private readonly AppNotifyIcon menuNotifyIcon = new();
private readonly Menus menus = new(); private readonly Menus menus = new();
private readonly TaskbarForm taskbarForm = null; private readonly TaskbarForm taskbarForm = null;
private readonly Timer timerActivateMenuAfterTaskbarFormMinimizedFinished = new();
public App() public App()
{ {
@ -29,43 +28,29 @@ namespace SystemTrayMenu
menuNotifyIcon.Click += () => menus.SwitchOpenClose(true); menuNotifyIcon.Click += () => menus.SwitchOpenClose(true);
menuNotifyIcon.OpenLog += Log.OpenLogFile; menuNotifyIcon.OpenLog += Log.OpenLogFile;
menus.MainPreload(); menus.MainPreload();
timerActivateMenuAfterTaskbarFormMinimizedFinished.Interval = 20;
timerActivateMenuAfterTaskbarFormMinimizedFinished.Tick += Timer_Tick;
void Timer_Tick(object sender, EventArgs e)
{
timerActivateMenuAfterTaskbarFormMinimizedFinished.Stop();
if (menus.IsNotNullAndIsUsableAndNotClosing())
{
taskbarForm.Activate();
menus.ReActivateIfVisible();
}
}
if (Properties.Settings.Default.ShowInTaskbar) if (Properties.Settings.Default.ShowInTaskbar)
{ {
taskbarForm = new TaskbarForm(); taskbarForm = new TaskbarForm();
taskbarForm.FormClosed += (s, e) => Application.Exit(); taskbarForm.FormClosed += (s, e) => Application.Exit();
int eachSecondResizeEvent = 1; taskbarForm.Deactivate += (s, e) => SetStateNormal();
taskbarForm.Resize += (s, e) => taskbarForm.Resize += (s, e) => SetStateNormal();
taskbarForm.Activated += TasbkarItemActivated;
void TasbkarItemActivated(object sender, EventArgs e)
{ {
if (eachSecondResizeEvent++ % 2 == 0 && Form.ActiveForm != null) SetStateNormal();
{ taskbarForm.Activate();
menus.SwitchOpenCloseByTaskbarItem(); taskbarForm.Focus();
timerActivateMenuAfterTaskbarFormMinimizedFinished.Start(); menus.SwitchOpenCloseByTaskbarItem();
} }
taskbarForm.WindowState = FormWindowState.Minimized;
};
taskbarForm.Show();
} }
DllImports.NativeMethods.User32ShowInactiveTopmost(taskbarForm);
} }
public void Dispose() public void Dispose()
{ {
taskbarForm?.Dispose(); taskbarForm?.Dispose();
timerActivateMenuAfterTaskbarFormMinimizedFinished.Dispose();
SystemEvents.DisplaySettingsChanged -= (s, e) => SystemEvents_DisplaySettingsChanged(); SystemEvents.DisplaySettingsChanged -= (s, e) => SystemEvents_DisplaySettingsChanged();
menus.Dispose(); menus.Dispose();
menuNotifyIcon.Dispose(); menuNotifyIcon.Dispose();
@ -75,5 +60,16 @@ namespace SystemTrayMenu
{ {
menus.ReAdjustSizeAndLocation(); menus.ReAdjustSizeAndLocation();
} }
/// <summary>
/// This ensures that next click on taskbaritem works as activate event/click event.
/// </summary>
private void SetStateNormal()
{
if (Form.ActiveForm == taskbarForm)
{
taskbarForm.WindowState = FormWindowState.Normal;
}
}
} }
} }

View file

@ -14,7 +14,6 @@ namespace SystemTrayMenu.Business
using System.Linq; using System.Linq;
using System.Windows.Forms; using System.Windows.Forms;
using SystemTrayMenu.DataClasses; using SystemTrayMenu.DataClasses;
using SystemTrayMenu.DllImports;
using SystemTrayMenu.Handler; using SystemTrayMenu.Handler;
using SystemTrayMenu.Helper; using SystemTrayMenu.Helper;
using SystemTrayMenu.UserInterface; using SystemTrayMenu.UserInterface;
@ -563,19 +562,6 @@ namespace SystemTrayMenu.Business
timerStillActiveCheck.Start(); timerStillActiveCheck.Start();
} }
internal bool IsNotNullAndIsUsableAndNotClosing()
{
return menus[0] != null && menus[0].IsUsable && Form.ActiveForm == menus[0];
}
internal void ReActivateIfVisible()
{
menus[0].Activate();
NativeMethods.User32ShowInactiveTopmost(menus[0]);
NativeMethods.ForceForegroundWindow(menus[0].Handle);
timerStillActiveCheck.Start();
}
internal bool IsOpenCloseStateOpening() internal bool IsOpenCloseStateOpening()
{ {
return openCloseState == OpenCloseState.Opening; return openCloseState == OpenCloseState.Opening;

View file

@ -39,5 +39,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.9.11")] [assembly: AssemblyVersion("1.2.9.10")]
[assembly: AssemblyFileVersion("1.2.9.11")] [assembly: AssemblyFileVersion("1.2.9.10")]

View file

@ -45,7 +45,6 @@
this.Name = "TaskbarForm"; this.Name = "TaskbarForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual; this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.Text = "SystemTrayMenu"; this.Text = "SystemTrayMenu";
this.WindowState = System.Windows.Forms.FormWindowState.Minimized;
this.LocationChanged += new System.EventHandler(this.TaskbarForm_LocationChanged); this.LocationChanged += new System.EventHandler(this.TaskbarForm_LocationChanged);
this.ResumeLayout(false); this.ResumeLayout(false);

View file

@ -22,9 +22,7 @@ namespace SystemTrayMenu.UserInterface
private void TaskbarForm_LocationChanged(object sender, System.EventArgs e) private void TaskbarForm_LocationChanged(object sender, System.EventArgs e)
{ {
this.LocationChanged -= new System.EventHandler(this.TaskbarForm_LocationChanged);
SetLocation(); SetLocation();
this.LocationChanged += new System.EventHandler(this.TaskbarForm_LocationChanged);
} }
/// <summary> /// <summary>