Skip to content

Commit

Permalink
Fixed an issue with sizing with max witdh
Browse files Browse the repository at this point in the history
  • Loading branch information
Simnico99 committed Jan 8, 2024
1 parent d70a39b commit bde0e2b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 13 deletions.
18 changes: 8 additions & 10 deletions src/MicaWPF.Core/Controls/MicaWindow/MicaWindowInteropHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// This software is distributed under the MIT license and its code is open-source and free for use, modification, and distribution.
// </copyright>

using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Automation.Peers;
Expand All @@ -21,6 +22,9 @@ public class MicaWindowInteropHandler : MicaWindowProperty
protected const string _buttonMaxName = "Maximize";
protected const string _buttonRestoreName = "Restore";

private static readonly SolidColorBrush _transparentBrush = new(Color.FromArgb(0, 0, 0, 0));
private static readonly double _dpiScale = DpiHelper.LogicalToDeviceUnitsScalingFactorX;

public MicaWindowInteropHandler()
: base()
{
Expand Down Expand Up @@ -64,12 +68,11 @@ private nint ShowSnapLayout(nint lparam, ref bool handled)
var x = (short)(lparam.ToInt32() & 0xffff);
var y = lparam.ToInt32() >> 16;
var point = new Point(x, y);
var dpiScale = DpiHelper.LogicalToDeviceUnitsScalingFactorX;
var button = WindowState == WindowState.Maximized ? ButtonRestore : ButtonMax;

if (button != null)
{
var buttonSize = new Size(button.ActualWidth * dpiScale, button.ActualHeight * dpiScale);
var buttonSize = new Size(button.ActualWidth * _dpiScale, button.ActualHeight * _dpiScale);
var buttonLocation = button.PointToScreen(default);
var rect = new Rect(buttonLocation, buttonSize);

Expand All @@ -81,7 +84,7 @@ private nint ShowSnapLayout(nint lparam, ref bool handled)
}
else
{
button.Background = new SolidColorBrush(Color.FromArgb(0, 0, 0, 0));
button.Background = _transparentBrush;
}

return PtrHelper.Create(_hTMAXBUTTON);
Expand Down Expand Up @@ -120,11 +123,6 @@ private nint HwndSourceHook(nint hwnd, int msg, nint n, nint lparam, ref bool ha
return PtrHelper.Zero;
}

if (msg == InteropValues.HwndSourceMessages.WM_GETTEXT)
{
return PtrHelper.Zero;
}

switch (msg)
{
case InteropValues.HwndSourceMessages.WM_NCHITTEST:
Expand All @@ -138,6 +136,7 @@ private nint HwndSourceHook(nint hwnd, int msg, nint n, nint lparam, ref bool ha
HideMaximiseAndMinimiseButton(lparam, ref handled);
break;
case InteropValues.HwndSourceMessages.WM_GETMINMAXINFO:
Debug.WriteLine("Humsmm");
var mmiNullable = (InteropValues.MINMAXINFO?)Marshal.PtrToStructure(lparam, typeof(InteropValues.MINMAXINFO));
if (mmiNullable.HasValue)
{
Expand All @@ -150,7 +149,6 @@ private nint HwndSourceHook(nint hwnd, int msg, nint n, nint lparam, ref bool ha
mmi.ptMaxSize.Y = (int)screen.Height + 8;

Marshal.StructureToPtr(mmi, lparam, true);
handled = true;
}
}

Expand All @@ -159,7 +157,7 @@ private nint HwndSourceHook(nint hwnd, int msg, nint n, nint lparam, ref bool ha
var button = WindowState == WindowState.Maximized ? ButtonRestore : ButtonMax;
if (button is not null)
{
button.Background = new SolidColorBrush(Color.FromArgb(0, 0, 0, 0));
button.Background = _transparentBrush;
}

break;
Expand Down
1 change: 0 additions & 1 deletion src/MicaWPF.Core/Controls/MicaWindow/MicaWindowStyle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

using System.Windows;
using MicaWPF.Core.Helpers;
using MicaWPF.Core.Services;

namespace MicaWPF.Core.Controls.MicaWindow;

Expand Down
1 change: 0 additions & 1 deletion src/MicaWPF.Core/Extensions/DependencyObjectExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using MicaWPF.Core.Controls;

namespace MicaWPF.Core.Extensions;

Expand Down
2 changes: 1 addition & 1 deletion src/MicaWPF/Helpers/WindowsAccentHelperWinRT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace MicaWPF.Helpers;

public class WindowsAccentHelperWinRT : WindowsAccentHelper
public sealed class WindowsAccentHelperWinRT : WindowsAccentHelper
{
public override bool AreTitleBarAndBordersAccented()
{
Expand Down

0 comments on commit bde0e2b

Please sign in to comment.