modified PopupLayout

This commit is contained in:
2026-08-09 20:24:21 +05:00
parent 1fc9765a3d
commit 163b86d239
6 changed files with 193 additions and 69 deletions
+24 -7
View File
@@ -103,17 +103,18 @@ public sealed class MainWindowPlacement
private static PopupWindowNative.Point? CenterOnActiveMonitor(PopupWindowNative.Rect bounds)
{
(PopupWindowNative.Rect work, _) = PopupWindowNative.GetActiveMonitorWorkArea();
if (IsEmpty(work))
{
return null;
}
return IsEmpty(work) ? null : Center(bounds, work);
}
return new PopupWindowNative.Point
/// <summary>
/// The point at which a window with the given bounds ends up in the centre of the work area.
/// </summary>
internal static PopupWindowNative.Point Center(
PopupWindowNative.Rect bounds, PopupWindowNative.Rect work) => new()
{
X = work.Left + (((work.Right - work.Left) - Width(bounds)) / 2),
Y = work.Top + (((work.Bottom - work.Top) - Height(bounds)) / 2),
};
}
/// <summary>
/// Pulls the window into the work area of the nearest monitor.
@@ -145,6 +146,22 @@ public sealed class MainWindowPlacement
return null;
}
return Clamp(position, bounds, work);
}
/// <summary>
/// Pulls the point so that a window with the given bounds fits into the work area
/// entirely. A window taller than the work area gets its top edge: the title bar
/// is needed more than the lower part of the window.
/// </summary>
internal static PopupWindowNative.Point Clamp(
PopupWindowNative.Point position,
PopupWindowNative.Rect bounds,
PopupWindowNative.Rect work)
{
int width = Width(bounds);
int height = Height(bounds);
return new PopupWindowNative.Point
{
X = Math.Clamp(position.X, work.Left, Math.Max(work.Left, work.Right - width)),
@@ -156,6 +173,6 @@ public sealed class MainWindowPlacement
private static int Height(PopupWindowNative.Rect rect) => rect.Bottom - rect.Top;
private static bool IsEmpty(PopupWindowNative.Rect rect) =>
internal static bool IsEmpty(PopupWindowNative.Rect rect) =>
rect.Right <= rect.Left || rect.Bottom <= rect.Top;
}