Skip to content

Commit

Permalink
Enforce minimum window size
Browse files Browse the repository at this point in the history
  • Loading branch information
stnkl committed Jan 26, 2023
1 parent d6a6149 commit 1f8af7a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
12 changes: 9 additions & 3 deletions EverythingToolbar.Deskband/WindowPlacement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ private RECT CalculatePosition()

int margin = GetMargin();
Rectangle workingArea = Screen.PrimaryScreen.WorkingArea;
Size windowSize = Settings.Default.popupSize;
windowSize.Width /= DpiScalingFactor;
windowSize.Height /= DpiScalingFactor;
Size windowSize = GetTargetWindowSize();
Edge taskbarEdge = TaskbarStateManager.Instance.TaskbarEdge;

RECT windowPosition = new RECT();
Expand All @@ -84,6 +82,14 @@ private RECT CalculatePosition()
return windowPosition;
}

private Size GetTargetWindowSize()
{
Size windowSize = Settings.Default.popupSize;
windowSize.Width = Math.Max(windowSize.Width, AssociatedObject.MinWidth) / DpiScalingFactor;
windowSize.Height = Math.Max(windowSize.Height, AssociatedObject.MinHeight) / DpiScalingFactor;
return windowSize;
}

private double GetScalingFactor()
{
IntPtr hwnd = ((HwndSource)PresentationSource.FromVisual(AssociatedObject)).Handle;
Expand Down
12 changes: 9 additions & 3 deletions EverythingToolbar.Launcher/WindowPlacement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ private RECT CalculatePosition(double scalingFactor)
{
Screen screen = Screen.PrimaryScreen;
TaskbarLocation taskbar = FindDockedTaskBar(screen);
Size windowSize = Settings.Default.popupSize;
windowSize.Width /= scalingFactor;
windowSize.Height /= scalingFactor;
Size windowSize = GetTargetWindowSize(scalingFactor);
int margin = (int)(GetMargin() / scalingFactor);

RECT windowPosition = new RECT();
Expand Down Expand Up @@ -85,6 +83,14 @@ private RECT CalculatePosition(double scalingFactor)
return windowPosition;
}

private Size GetTargetWindowSize(double scalingFactor)
{
Size windowSize = Settings.Default.popupSize;
windowSize.Width = Math.Max(windowSize.Width, AssociatedObject.MinWidth) / scalingFactor;
windowSize.Height = Math.Max(windowSize.Height, AssociatedObject.MinHeight) / scalingFactor;
return windowSize;
}

private RECT SetHorizontalPosition(RECT windowPosition, Rectangle screenWorkingArea, Size windowSize, int margin)
{
if (Utils.IsTaskbarCenterAligned())
Expand Down

0 comments on commit 1f8af7a

Please sign in to comment.