diff --git a/src/Eto.Gtk/Forms/GtkWindow.cs b/src/Eto.Gtk/Forms/GtkWindow.cs index 449c5d838..5b47dc8c4 100644 --- a/src/Eto.Gtk/Forms/GtkWindow.cs +++ b/src/Eto.Gtk/Forms/GtkWindow.cs @@ -723,6 +723,8 @@ public WindowState WindowState Control.Unfullscreen(); if (gdkWindow.State.HasFlag(Gdk.WindowState.Iconified)) Control.Deiconify(); + if (gdkWindow.State.HasFlag(Gdk.WindowState.Iconified)) + Control.Present(); } Control.Maximize(); break; @@ -738,6 +740,8 @@ public WindowState WindowState Control.Unmaximize(); if (gdkWindow.State.HasFlag(Gdk.WindowState.Iconified)) Control.Deiconify(); + if (gdkWindow.State.HasFlag(Gdk.WindowState.Iconified)) + Control.Present(); } break; } @@ -783,7 +787,18 @@ public Screen Screen protected override void GrabFocus() => Control.Present(); - public void BringToFront() => Control.GetWindow()?.Raise(); + public void BringToFront() + { + if (WindowState == WindowState.Minimized) + { + Control.Deiconify(); + // if it didn't work, present it + if (WindowState == WindowState.Minimized) + Control.Present(); + } + + Control.GetWindow()?.Raise(); + } public void SendToBack() => Control.GetWindow()?.Lower(); diff --git a/src/Eto.WinForms/Forms/WindowHandler.cs b/src/Eto.WinForms/Forms/WindowHandler.cs index e7685c7fc..1da2d2085 100755 --- a/src/Eto.WinForms/Forms/WindowHandler.cs +++ b/src/Eto.WinForms/Forms/WindowHandler.cs @@ -547,8 +547,7 @@ public WindowStyle WindowStyle public virtual void BringToFront() { - if (Control.WindowState == swf.FormWindowState.Minimized) - Control.WindowState = swf.FormWindowState.Normal; + RestoreFromMinimized(); var hWnd = NativeHandle; if (hWnd != IntPtr.Zero) @@ -557,6 +556,25 @@ public virtual void BringToFront() public void SendToBack() => Control.SendToBack(); + public override void Focus() + { + RestoreFromMinimized(); + + base.Focus(); + } + + private void RestoreFromMinimized() + { + if (Control.WindowState == swf.FormWindowState.Minimized) + { + var placement = new Win32.WINDOWPLACEMENT(); + if (Win32.GetWindowPlacement(NativeHandle, ref placement) && placement.flags.HasFlag(Win32.WPF.RESTORETOMAXIMIZED)) + Control.WindowState = swf.FormWindowState.Maximized; + else + Control.WindowState = swf.FormWindowState.Normal; + } + } + public virtual void SetOwner(Window owner) { Control.Owner = owner.ToSWF(); diff --git a/src/Eto.WinForms/Win32.cs b/src/Eto.WinForms/Win32.cs index a6981f2c5..3cf7647ea 100755 --- a/src/Eto.WinForms/Win32.cs +++ b/src/Eto.WinForms/Win32.cs @@ -768,5 +768,29 @@ public struct SHSTOCKICONINFO /// N/A [DllImport("User32.dll")] public static extern int DestroyIcon(IntPtr hIcon); + + [DllImport("user32.dll", SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool GetWindowPlacement(IntPtr hWnd, ref WINDOWPLACEMENT lpwndpl); + + [Flags] + public enum WPF : int + { + SETMINPOSITION = 0x01, + RESTORETOMAXIMIZED = 0x02, + ASYNCWINDOWPLACEMENT = 0x04 + } + + [StructLayout(LayoutKind.Sequential)] + public struct WINDOWPLACEMENT + { + public int length; + public WPF flags; + public int showCmd; + public System.Drawing.Point ptMinPosition; + public System.Drawing.Point ptMaxPosition; + public System.Drawing.Rectangle rcNormalPosition; + } + } } diff --git a/src/Eto.Wpf/Forms/WpfWindow.cs b/src/Eto.Wpf/Forms/WpfWindow.cs index c91974c9a..ed03b78d2 100755 --- a/src/Eto.Wpf/Forms/WpfWindow.cs +++ b/src/Eto.Wpf/Forms/WpfWindow.cs @@ -967,6 +967,13 @@ void SetWindowChrome(bool enabled) RestoreWindowStyle(oldStyle); } + public override void Focus() + { + if (Control.WindowState == sw.WindowState.Minimized) + Control.WindowState = sw.WindowState.Normal; + base.Focus(); + } + public void BringToFront() { if (Control.WindowState == sw.WindowState.Minimized)