Skip to content
Merged
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
3 changes: 3 additions & 0 deletions src/UniGetUI.Avalonia/Views/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@
<Setter Property="Background" Value="{DynamicResource SubtleFillColorSecondaryBrush}"/>
<Setter Property="CornerRadius" Value="0"/>
</Style>
<Style Selector="Button.caption:pressed">
<Setter Property="RenderTransform" Value="none"/>
</Style>
<Style Selector="Button.caption:pressed /template/ ContentPresenter">
<Setter Property="Background" Value="{DynamicResource SubtleFillColorTertiaryBrush}"/>
<Setter Property="CornerRadius" Value="0"/>
Expand Down
33 changes: 31 additions & 2 deletions src/UniGetUI.Avalonia/Views/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public partial class MainWindow : Window
private const uint WM_DWMCOLORIZATIONCOLORCHANGED = 0x0320;
private const nint SC_MAXIMIZE = 0xF030;
private const nint SC_RESTORE = 0xF120;
private const int HTCLIENT = 1;
private const int HTMAXBUTTON = 9;
private const uint TME_LEAVE = 0x0002;
private const uint TME_NONCLIENT = 0x0010;
Expand Down Expand Up @@ -978,8 +979,7 @@ private bool HitTestMaximizeButton(nint lParam)
return false;
try
{
int x = unchecked((short)(lParam.ToInt64() & 0xFFFF));
int y = unchecked((short)((lParam.ToInt64() >> 16) & 0xFFFF));
var (x, y) = ScreenPointFromLParam(lParam);
PixelPoint topLeft = MaximizeButton.PointToScreen(new Point(0, 0));
PixelPoint bottomRight = MaximizeButton.PointToScreen(
new Point(MaximizeButton.Bounds.Width, MaximizeButton.Bounds.Height));
Expand All @@ -991,6 +991,30 @@ private bool HitTestMaximizeButton(nint lParam)
}
}

private bool HitTestCaptionButtons(nint lParam)
{
if (!WindowButtons.IsVisible)
return false;
try
{
var (x, y) = ScreenPointFromLParam(lParam);
PixelPoint topLeft = WindowButtons.PointToScreen(new Point(0, 0));
PixelPoint bottomRight = WindowButtons.PointToScreen(
new Point(WindowButtons.Bounds.Width, WindowButtons.Bounds.Height));
return x >= topLeft.X && x < bottomRight.X && y >= topLeft.Y && y < bottomRight.Y;
}
catch
{
return false;
}
}

private static (int X, int Y) ScreenPointFromLParam(nint lParam)
{
long packed = lParam.ToInt64();
return (unchecked((short)(packed & 0xFFFF)), unchecked((short)((packed >> 16) & 0xFFFF)));
}

// Emulates the button's pointer-over/pressed fill (lost once input is non-client) using the
// same Fluent brushes the neighbouring min/close buttons use, so the row stays consistent.
private void SetMaximizeButtonVisual(bool hover, bool pressed)
Expand Down Expand Up @@ -1130,6 +1154,11 @@ private static nint OnWindowsWndProc(nint hWnd, uint msg, nint wParam, nint lPar
handled = true;
return HTMAXBUTTON;
}
if (self.HitTestCaptionButtons(lParam))
{
handled = true;
return HTCLIENT;
}
break;

case WM_NCMOUSEMOVE:
Expand Down
Loading