diff --git a/PicView/Shortcuts/MainKeyboardShortcuts.cs b/PicView/Shortcuts/MainKeyboardShortcuts.cs index b0ae09d33..b4c4998c9 100644 --- a/PicView/Shortcuts/MainKeyboardShortcuts.cs +++ b/PicView/Shortcuts/MainKeyboardShortcuts.cs @@ -273,7 +273,7 @@ internal static async Task MainWindow_KeysDownAsync(object sender, KeyEventArgs } else if (Settings.Default.Fullscreen) { - WindowSizing.Fullscreen_Restore(); + WindowSizing.Fullscreen_Restore(false); } else if (GetQuickResize is not null && GetQuickResize.Opacity > 0) { @@ -571,7 +571,7 @@ internal static async Task MainWindow_KeysDownAsync(object sender, KeyEventArgs // F11 case Key.F11: - WindowSizing.Fullscreen_Restore(); + WindowSizing.Fullscreen_Restore(!Settings.Default.Fullscreen); break; // Home @@ -615,7 +615,7 @@ internal static void MainWindow_KeysUp(object sender, KeyEventArgs e) { if (Settings.Default.FullscreenGalleryHorizontal == false) { - WindowSizing.Fullscreen_Restore(); + WindowSizing.Fullscreen_Restore(!Settings.Default.Fullscreen); } } return; diff --git a/PicView/SystemIntegration/Wallpaper.cs b/PicView/SystemIntegration/Wallpaper.cs index a6d247532..6c1f5fa4b 100644 --- a/PicView/SystemIntegration/Wallpaper.cs +++ b/PicView/SystemIntegration/Wallpaper.cs @@ -1,5 +1,6 @@ using Microsoft.Win32; using PicView.ChangeImage; +using PicView.FileHandling; using PicView.ImageHandling; using PicView.UILogic; using System.ComponentModel; @@ -50,6 +51,9 @@ await ConfigureWindows.GetMainWindow.Dispatcher.BeginInvoke(DispatcherPriority.N } SetDesktopWallpaper(destination, style); + // Wait a while and then delete file + await Task.Delay(TimeSpan.FromSeconds(15)).ConfigureAwait(false); + DeleteFiles.TryDeleteFile(destination, false); } /// diff --git a/PicView/UILogic/Loading/LoadContextMenus.cs b/PicView/UILogic/Loading/LoadContextMenus.cs index 137dc215b..8b4f88902 100644 --- a/PicView/UILogic/Loading/LoadContextMenus.cs +++ b/PicView/UILogic/Loading/LoadContextMenus.cs @@ -277,7 +277,7 @@ internal static void AddContextMenus() WindowContextMenu = (ContextMenu)Application.Current.Resources["windowCM"]; var fullscreenWindow = (MenuItem)WindowContextMenu.Items[0]; - fullscreenWindow.Click += (_,_) => WindowSizing.Fullscreen_Restore(); + fullscreenWindow.Click += (_,_) => WindowSizing.Fullscreen_Restore(!Settings.Default.Fullscreen); var minWindow = (MenuItem)WindowContextMenu.Items[1]; minWindow.Click += (_, _) => SystemCommands.MinimizeWindow(ConfigureWindows.GetMainWindow); diff --git a/PicView/UILogic/Sizing/WindowSizing.cs b/PicView/UILogic/Sizing/WindowSizing.cs index 828e4323a..18b150479 100644 --- a/PicView/UILogic/Sizing/WindowSizing.cs +++ b/PicView/UILogic/Sizing/WindowSizing.cs @@ -105,8 +105,9 @@ internal static void Move(object sender, MouseButtonEventArgs e) { Settings.Default.AutoFitWindow = false; SetWindowBehavior(); + Settings.Default.AutoFitWindow = true; } - SetMaximized(); + Fullscreen_Restore(true); } else { @@ -118,7 +119,6 @@ internal static void Move(object sender, MouseButtonEventArgs e) // Update info for possible new screen, needs more engineering // Seems to work MonitorInfo = MonitorSize.GetMonitorSize(); - SetWindowSize(); } } @@ -135,7 +135,6 @@ internal static void MoveAlt(object sender, MouseButtonEventArgs e) if (e.LeftButton == MouseButtonState.Pressed) { GetMainWindow.DragMove(); - SetWindowSize(); } } @@ -158,9 +157,14 @@ internal static void Restore_From_Move() /// /// Fullscreen/restore window /// - internal static void Fullscreen_Restore(bool forceFullscreen = false) + internal static void Fullscreen_Restore(bool gotoFullscreen) { - if (forceFullscreen || Settings.Default.Fullscreen == false) + if (Settings.Default.AutoFitWindow == false) + { + SetWindowSize(); + } + + if (gotoFullscreen) { // Show fullscreen logic RenderFullscreen(); @@ -200,13 +204,13 @@ internal static void Fullscreen_Restore(bool forceFullscreen = false) GetMainWindow.TitleBar.Margin = new Thickness(0); GetMainWindow.LowerBar.Margin = new Thickness(0); + SetWindowBehavior(); + if (Settings.Default.AutoFitWindow == false) { SetLastWindowSize(); } - SetWindowBehavior(); - if (Slideshow.SlideTimer != null && Slideshow.SlideTimer.Enabled) { Slideshow.SlideTimer.Enabled = false; @@ -220,8 +224,6 @@ internal static void RenderFullscreen() { Settings.Default.ScrollEnabled = false; // Don't scroll in fulscreen - SetWindowSize(); - ShowTopandBottom(false); GetMainWindow.Topmost = true; @@ -230,9 +232,6 @@ internal static void RenderFullscreen() GetMainWindow.Width = MonitorInfo.WorkArea.Width; GetMainWindow.Height = MonitorInfo.WorkArea.Height; - GetMainWindow.MainImageBorder.Width = GetMainWindow.Width; - GetMainWindow.MainImageBorder.Height = GetMainWindow.Height; - _ = TryFitImageAsync(); GetMainWindow.Top = 0; @@ -287,8 +286,8 @@ internal static void SetWindowSize() { Settings.Default.Top = GetMainWindow.Top; Settings.Default.Left = GetMainWindow.Left; - Settings.Default.Height = GetMainWindow.Height; - Settings.Default.Width = GetMainWindow.Width; + Settings.Default.Height = GetMainWindow.ActualHeight; + Settings.Default.Width = GetMainWindow.ActualWidth; Settings.Default.Save(); }); @@ -303,10 +302,6 @@ internal static void MainWindow_StateChanged() switch (GetMainWindow.WindowState) { case WindowState.Normal: - if (Settings.Default.Fullscreen) - { - Fullscreen_Restore(); - } return; case WindowState.Maximized: diff --git a/PicView/UILogic/Slideshow.cs b/PicView/UILogic/Slideshow.cs index 2deb9e567..cf0acf350 100644 --- a/PicView/UILogic/Slideshow.cs +++ b/PicView/UILogic/Slideshow.cs @@ -59,7 +59,7 @@ internal static void StopSlideshow() if (!Settings.Default.Fullscreen) { - WindowSizing.Fullscreen_Restore(); + WindowSizing.Fullscreen_Restore(false); } _ = NativeMethods.SetThreadExecutionState(NativeMethods.ES_CONTINUOUS); // Allow screensaver again diff --git a/PicView/UILogic/TransformImage/Zoom.cs b/PicView/UILogic/TransformImage/Zoom.cs index 20abaf24d..74c2c47bc 100644 --- a/PicView/UILogic/TransformImage/Zoom.cs +++ b/PicView/UILogic/TransformImage/Zoom.cs @@ -136,36 +136,42 @@ internal static void PanImage(object sender, MouseEventArgs e) var dragDelta = start - e.GetPosition(ConfigureWindows.GetMainWindow); // Update the image position - translateTransform.X = origin.X - dragDelta.X; - translateTransform.Y = origin.Y - dragDelta.Y; + var dragMousePosition = start - e.GetPosition(ConfigureWindows.GetMainWindow); - // Check if auto-fit window is enabled and full-screen mode is disabled - if (Settings.Default.AutoFitWindow && !Settings.Default.Fullscreen && !Settings.Default.FullscreenGalleryHorizontal) + var newXproperty = origin.X - dragMousePosition.X; + var newYproperty = origin.Y - dragMousePosition.Y; + + // Keep panning it in bounds + if (Properties.Settings.Default.AutoFitWindow) // TODO develop solution where you can keep window in bounds when using normal window behavior and fullscreen { - // Calculate if the image is outside of the window bounds var isXOutOfBorder = ConfigureWindows.GetMainWindow.Scroller.ActualWidth < (ConfigureWindows.GetMainWindow.MainImageBorder.ActualWidth * scaleTransform.ScaleX); var isYOutOfBorder = ConfigureWindows.GetMainWindow.Scroller.ActualHeight < (ConfigureWindows.GetMainWindow.MainImageBorder.ActualHeight * scaleTransform.ScaleY); + var maxX = ConfigureWindows.GetMainWindow.Scroller.ActualWidth - (ConfigureWindows.GetMainWindow.MainImageBorder.ActualWidth * scaleTransform.ScaleX); + var maxY = ConfigureWindows.GetMainWindow.Scroller.ActualHeight - (ConfigureWindows.GetMainWindow.MainImageBorder.ActualHeight * scaleTransform.ScaleY); - // Keep the image within the window bounds - if (isXOutOfBorder) + if (isXOutOfBorder && newXproperty < maxX || isXOutOfBorder == false && newXproperty > maxX) { - translateTransform.X = Math.Min(0, Math.Max(ConfigureWindows.GetMainWindow.Scroller.ActualWidth - (ConfigureWindows.GetMainWindow.MainImageBorder.ActualWidth * scaleTransform.ScaleX), translateTransform.X)); + newXproperty = maxX; } - else + + if (isXOutOfBorder && newYproperty < maxY || isXOutOfBorder == false && newYproperty > maxY) { - translateTransform.X = Math.Max(0, Math.Min(ConfigureWindows.GetMainWindow.Scroller.ActualWidth - (ConfigureWindows.GetMainWindow.MainImageBorder.ActualWidth * scaleTransform.ScaleX), translateTransform.X)); + newYproperty = maxY; } - if (isYOutOfBorder) + if (isXOutOfBorder && newXproperty > 0 || isXOutOfBorder == false && newXproperty < 0) { - translateTransform.Y = Math.Min(0, Math.Max(ConfigureWindows.GetMainWindow.Scroller.ActualHeight - (ConfigureWindows.GetMainWindow.MainImageBorder.ActualHeight * scaleTransform.ScaleY), translateTransform.Y)); + newXproperty = 0; } - else + if (isYOutOfBorder && newYproperty > 0 || isYOutOfBorder == false && newYproperty < 0) { - translateTransform.Y = Math.Max(0, Math.Min(ConfigureWindows.GetMainWindow.Scroller.ActualHeight - (ConfigureWindows.GetMainWindow.MainImageBorder.ActualHeight * scaleTransform.ScaleY), translateTransform.Y)); + newYproperty = 0; } } + translateTransform.X = newXproperty; + translateTransform.Y = newYproperty; + e.Handled = true; } diff --git a/PicView/Views/UserControls/Buttons/FullscreenButton.xaml.cs b/PicView/Views/UserControls/Buttons/FullscreenButton.xaml.cs index d0461f52d..712ce9e80 100644 --- a/PicView/Views/UserControls/Buttons/FullscreenButton.xaml.cs +++ b/PicView/Views/UserControls/Buttons/FullscreenButton.xaml.cs @@ -34,7 +34,7 @@ public FullscreenButton() TheButton.Click += delegate { - WindowSizing.Fullscreen_Restore(); + WindowSizing.Fullscreen_Restore(!Settings.Default.Fullscreen); }; if (!Settings.Default.DarkTheme) diff --git a/PicView/Views/UserControls/Buttons/RestoreButton.xaml.cs b/PicView/Views/UserControls/Buttons/RestoreButton.xaml.cs index c6a81071d..73b442264 100644 --- a/PicView/Views/UserControls/Buttons/RestoreButton.xaml.cs +++ b/PicView/Views/UserControls/Buttons/RestoreButton.xaml.cs @@ -15,7 +15,7 @@ public Restorebutton() { InitializeComponent(); - TheButton.Click += delegate { WindowSizing.Fullscreen_Restore(); }; + TheButton.Click += delegate { WindowSizing.Fullscreen_Restore(!Settings.Default.Fullscreen); }; MouseEnter += delegate {