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

fix(shell): maximize respect height of active screen #118

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion GitOut/Features/Wpf/NavigatorShell.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
Width="1280"
Height="800"
MinHeight="300"
MaxHeight="{x:Static SystemParameters.MaximizedPrimaryScreenHeight}"
MinWidth="320"
WindowStyle="None"
AllowsTransparency="True"
Expand Down
40 changes: 38 additions & 2 deletions GitOut/Features/Wpf/NavigatorShell.xaml.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down Expand Up @@ -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;
}
Expand Down
5 changes: 5 additions & 0 deletions GitOut/GitOut.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@
<LangVersion>8</LangVersion>
<Nullable>enable</Nullable>
<ApplicationIcon>gitout.ico</ApplicationIcon>
<IncludePackageReferencesDuringMarkupCompilation>true</IncludePackageReferencesDuringMarkupCompilation>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.3" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.3" />
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.1.422-beta">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="System.Reactive" Version="4.4.1" />
</ItemGroup>

Expand Down
3 changes: 3 additions & 0 deletions GitOut/NativeMethods.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
GetMonitorInfo
MonitorFromWindow
MINMAXINFO