Skip to content

Commit

Permalink
BringToFront() and Focus() should un-minimize the Window
Browse files Browse the repository at this point in the history
  • Loading branch information
cwensley committed Apr 24, 2024
1 parent c312ea1 commit e4042a6
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 3 deletions.
17 changes: 16 additions & 1 deletion src/Eto.Gtk/Forms/GtkWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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();

Expand Down
22 changes: 20 additions & 2 deletions src/Eto.WinForms/Forms/WindowHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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();
Expand Down
23 changes: 23 additions & 0 deletions src/Eto.WinForms/Win32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -768,5 +768,28 @@ public struct SHSTOCKICONINFO
/// <returns>N/A</returns>
[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
}

public struct WINDOWPLACEMENT
{
public int length;

Check failure on line 786 in src/Eto.WinForms/Win32.cs

View workflow job for this annotation

GitHub Actions / build-windows

Field 'Win32.WINDOWPLACEMENT.length' is never assigned to, and will always have its default value 0

Check failure on line 786 in src/Eto.WinForms/Win32.cs

View workflow job for this annotation

GitHub Actions / build-windows

Field 'Win32.WINDOWPLACEMENT.length' is never assigned to, and will always have its default value 0
public WPF flags;

Check failure on line 787 in src/Eto.WinForms/Win32.cs

View workflow job for this annotation

GitHub Actions / build-windows

Field 'Win32.WINDOWPLACEMENT.flags' is never assigned to, and will always have its default value

Check failure on line 787 in src/Eto.WinForms/Win32.cs

View workflow job for this annotation

GitHub Actions / build-windows

Field 'Win32.WINDOWPLACEMENT.flags' is never assigned to, and will always have its default value
public int showCmd;

Check failure on line 788 in src/Eto.WinForms/Win32.cs

View workflow job for this annotation

GitHub Actions / build-windows

Field 'Win32.WINDOWPLACEMENT.showCmd' is never assigned to, and will always have its default value 0
public System.Drawing.Point ptMinPosition;

Check failure on line 789 in src/Eto.WinForms/Win32.cs

View workflow job for this annotation

GitHub Actions / build-windows

Field 'Win32.WINDOWPLACEMENT.ptMinPosition' is never assigned to, and will always have its default value
public System.Drawing.Point ptMaxPosition;

Check failure on line 790 in src/Eto.WinForms/Win32.cs

View workflow job for this annotation

GitHub Actions / build-windows

Field 'Win32.WINDOWPLACEMENT.ptMaxPosition' is never assigned to, and will always have its default value

Check failure on line 790 in src/Eto.WinForms/Win32.cs

View workflow job for this annotation

GitHub Actions / build-windows

Field 'Win32.WINDOWPLACEMENT.ptMaxPosition' is never assigned to, and will always have its default value
public System.Drawing.Rectangle rcNormalPosition;

Check failure on line 791 in src/Eto.WinForms/Win32.cs

View workflow job for this annotation

GitHub Actions / build-windows

Field 'Win32.WINDOWPLACEMENT.rcNormalPosition' is never assigned to, and will always have its default value

Check failure on line 791 in src/Eto.WinForms/Win32.cs

View workflow job for this annotation

GitHub Actions / build-windows

Field 'Win32.WINDOWPLACEMENT.rcNormalPosition' is never assigned to, and will always have its default value
}

}
}
7 changes: 7 additions & 0 deletions src/Eto.Wpf/Forms/WpfWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit e4042a6

Please sign in to comment.