From 61373e41f9c82e933621afce4e80458ec1294d8b Mon Sep 17 00:00:00 2001 From: Ruben Date: Thu, 8 Feb 2024 14:15:41 +0100 Subject: [PATCH] #117 --- .../UILogic/Loading/StartLoading.cs | 9 ++---- .../UILogic/Sizing/WindowSizing.cs | 29 +++++++++++++++++-- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/PicView.WPF/UILogic/Loading/StartLoading.cs b/src/PicView.WPF/UILogic/Loading/StartLoading.cs index a7b6fcf6f..e00383909 100644 --- a/src/PicView.WPF/UILogic/Loading/StartLoading.cs +++ b/src/PicView.WPF/UILogic/Loading/StartLoading.cs @@ -88,18 +88,15 @@ await startupWindow.Dispatcher.InvokeAsync(() => ConfigureWindows.GetMainWindow = mainWindow; GetSpinWaiter = GetSpinWaiter; - if (SettingsHelper.Settings.WindowProperties.AutoFit == false) - { - SetLastWindowSize(mainWindow); - } - // Set min size to DPI scaling mainWindow.MinWidth *= MonitorInfo.DpiScaling; mainWindow.MinHeight *= MonitorInfo.DpiScaling; SetWindowBehavior(); if (SettingsHelper.Settings.WindowProperties.AutoFit == false) - SetLastWindowSize(ConfigureWindows.GetMainWindow); + { + SetLastWindowSize(mainWindow); + } mainWindow.Scroller.VerticalScrollBarVisibility = SettingsHelper.Settings.Zoom.ScrollEnabled ? ScrollBarVisibility.Auto diff --git a/src/PicView.WPF/UILogic/Sizing/WindowSizing.cs b/src/PicView.WPF/UILogic/Sizing/WindowSizing.cs index 1ab8d9e1d..21a93223f 100644 --- a/src/PicView.WPF/UILogic/Sizing/WindowSizing.cs +++ b/src/PicView.WPF/UILogic/Sizing/WindowSizing.cs @@ -293,8 +293,33 @@ internal static void SetLastWindowSize(Window window) { window?.Dispatcher.Invoke(() => { - window.Top = SettingsHelper.Settings.WindowProperties.Top; - window.Left = SettingsHelper.Settings.WindowProperties.Left; + var top = SettingsHelper.Settings.WindowProperties.Top; + if (top < SystemParameters.VirtualScreenTop) + { + top = SystemParameters.VirtualScreenTop; + } + if (window.Top + window.Height > SystemParameters.VirtualScreenTop + SystemParameters.VirtualScreenHeight) + { + top = SystemParameters.VirtualScreenHeight + SystemParameters.VirtualScreenTop - window.Height; + } + + var left = SettingsHelper.Settings.WindowProperties.Left; + if (left < 0) + { + left = MonitorInfo.WorkArea.Left; + } + + if (left < SystemParameters.VirtualScreenLeft) + { + left = SystemParameters.VirtualScreenLeft; + } + + if (left + window.Width > SystemParameters.VirtualScreenLeft + SystemParameters.VirtualScreenWidth) + { + left = SystemParameters.VirtualScreenWidth + SystemParameters.VirtualScreenLeft - window.Width; + } + window.Top = top; + window.Left = left; window.Width = double.IsNaN(SettingsHelper.Settings.WindowProperties.Width) ? window.Width : double.IsNaN(SettingsHelper.Settings.WindowProperties.Width) ? window.ActualWidth : SettingsHelper.Settings.WindowProperties.Width; window.Height = double.IsNaN(SettingsHelper.Settings.WindowProperties.Height) ? window.Height :