diff --git a/GitOut/Features/Wpf/NavigatorShell.xaml b/GitOut/Features/Wpf/NavigatorShell.xaml index 353a4b61..a3dad4ba 100644 --- a/GitOut/Features/Wpf/NavigatorShell.xaml +++ b/GitOut/Features/Wpf/NavigatorShell.xaml @@ -13,7 +13,6 @@ Width="1280" Height="800" MinHeight="300" - MaxHeight="{x:Static SystemParameters.MaximizedPrimaryScreenHeight}" MinWidth="320" WindowStyle="None" AllowsTransparency="True" diff --git a/GitOut/Features/Wpf/NavigatorShell.xaml.cs b/GitOut/Features/Wpf/NavigatorShell.xaml.cs index 0255b83d..d72d82a7 100644 --- a/GitOut/Features/Wpf/NavigatorShell.xaml.cs +++ b/GitOut/Features/Wpf/NavigatorShell.xaml.cs @@ -1,7 +1,9 @@ using System; +using System.Runtime.InteropServices; using System.Windows; using System.Windows.Input; using System.Windows.Interop; +using Microsoft.Windows.Sdk; namespace GitOut.Features.Wpf { @@ -35,9 +37,43 @@ protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e) private IntPtr WindowResizedHook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { const int WM_EXITSIZEMOVE = 0x232; - if (msg == WM_EXITSIZEMOVE) + const int WM_GETMINMAXINFO = 0x0024; + + switch (msg) { - Resized?.Invoke(this, EventArgs.Empty); + case WM_EXITSIZEMOVE: + Resized?.Invoke(this, EventArgs.Empty); + break; + case WM_GETMINMAXINFO: + { + // from https://stackoverflow.com/a/46465322/238902 + var minMaxInfo = (MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(MINMAXINFO))!; + + HMONITOR monitor = PInvoke.MonitorFromWindow( + new HWND(hwnd), + MonitorFrom_dwFlags.MONITOR_DEFAULTTONEAREST + ); + + if (monitor != IntPtr.Zero) + { + var monitorinfo = new MONITORINFO + { + cbSize = (uint)Marshal.SizeOf(typeof(MONITORINFO)) + }; + PInvoke.GetMonitorInfo(monitor, ref monitorinfo); + RECT rcWork = monitorinfo.rcWork; + RECT rcMonitor = monitorinfo.rcMonitor; + + minMaxInfo.ptMaxPosition.x = Math.Abs(rcWork.left - rcMonitor.left); + minMaxInfo.ptMaxPosition.y = Math.Abs(rcWork.top - rcMonitor.top); + minMaxInfo.ptMaxSize.x = Math.Abs(rcWork.right - rcWork.left); + minMaxInfo.ptMaxSize.y = Math.Abs(rcWork.bottom - rcWork.top); + minMaxInfo.ptMinTrackSize.x = (int)MinWidth; + minMaxInfo.ptMinTrackSize.y = (int)MinHeight; + } + Marshal.StructureToPtr(minMaxInfo, lParam, true); + } + break; } return IntPtr.Zero; } diff --git a/GitOut/GitOut.csproj b/GitOut/GitOut.csproj index 763ba4b8..c8211a10 100644 --- a/GitOut/GitOut.csproj +++ b/GitOut/GitOut.csproj @@ -7,11 +7,16 @@ 8 enable gitout.ico + true + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + diff --git a/GitOut/NativeMethods.txt b/GitOut/NativeMethods.txt new file mode 100644 index 00000000..dcde63a8 --- /dev/null +++ b/GitOut/NativeMethods.txt @@ -0,0 +1,3 @@ +GetMonitorInfo +MonitorFromWindow +MINMAXINFO