Skip to content

Commit

Permalink
Fix window too big using high screen scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
timokoessler committed Sep 10, 2024
1 parent e5ab795 commit 3cd7224
Showing 1 changed file with 39 additions and 5 deletions.
44 changes: 39 additions & 5 deletions Guard.WPF/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ private void OnWindowLoaded()

SimpleIconsManager.LoadIcons();

CheckWindowSizeAndPosition();

if (SettingsManager.Settings.MinimizeToTray)
{
AddTrayIcon();
}

StatsClient = new(
"A-SH-2619747927",
new AptabaseOptions { Host = "https://aptabase.tkoessler.de" }
Expand All @@ -93,11 +100,6 @@ private void OnWindowLoaded()
}

CheckLocalTime();

if (SettingsManager.Settings.MinimizeToTray)
{
AddTrayIcon();
}
}

internal void ApplyTheme(ThemeSetting theme)
Expand Down Expand Up @@ -412,5 +414,37 @@ internal IntPtr GetWindowHandle()
{
return windowInteropHandle;
}

private void CheckWindowSizeAndPosition()
{
try
{
if (Left < 0)
{
Left = 0;
}
if (Top < 0)
{
Top = 0;
}
int screenWidth = (int)SystemParameters.WorkArea.Width;
int screenHeight = (int)SystemParameters.WorkArea.Height;
if (Left + Width > screenWidth)
{
Width = screenWidth - Left;
}
if (Top + Height > screenHeight)
{
Height = screenHeight - Top;
}
}
catch (Exception e)
{
Log.Logger.Warning(
"Failed to check window size and position: {Exception}",
e.Message
);
}
}
}
}

0 comments on commit 3cd7224

Please sign in to comment.