Skip to content

Commit

Permalink
Fixed incorrect window behavior issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben2776 committed Mar 24, 2023
1 parent 3803d61 commit 046c139
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 39 deletions.
6 changes: 3 additions & 3 deletions PicView/Shortcuts/MainKeyboardShortcuts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions PicView/SystemIntegration/Wallpaper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.Win32;
using PicView.ChangeImage;
using PicView.FileHandling;
using PicView.ImageHandling;
using PicView.UILogic;
using System.ComponentModel;
Expand Down Expand Up @@ -50,6 +51,9 @@ internal static async Task SetWallpaperAsync(WallpaperStyle style)
}

SetDesktopWallpaper(destination, style);
// Wait a while and then delete file
await Task.Delay(TimeSpan.FromSeconds(15)).ConfigureAwait(false);
DeleteFiles.TryDeleteFile(destination, false);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion PicView/UILogic/Loading/LoadContextMenus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
31 changes: 13 additions & 18 deletions PicView/UILogic/Sizing/WindowSizing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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();
}
}

Expand All @@ -135,7 +135,6 @@ internal static void MoveAlt(object sender, MouseButtonEventArgs e)
if (e.LeftButton == MouseButtonState.Pressed)
{
GetMainWindow.DragMove();
SetWindowSize();
}
}

Expand All @@ -158,9 +157,14 @@ internal static void Restore_From_Move()
/// <summary>
/// Fullscreen/restore window
/// </summary>
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();
Expand Down Expand Up @@ -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;
Expand All @@ -220,8 +224,6 @@ internal static void RenderFullscreen()
{
Settings.Default.ScrollEnabled = false; // Don't scroll in fulscreen

SetWindowSize();

ShowTopandBottom(false);
GetMainWindow.Topmost = true;

Expand All @@ -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;
Expand Down Expand Up @@ -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();
});
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion PicView/UILogic/Slideshow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 20 additions & 14 deletions PicView/UILogic/TransformImage/Zoom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public FullscreenButton()

TheButton.Click += delegate
{
WindowSizing.Fullscreen_Restore();
WindowSizing.Fullscreen_Restore(!Settings.Default.Fullscreen);
};

if (!Settings.Default.DarkTheme)
Expand Down
2 changes: 1 addition & 1 deletion PicView/Views/UserControls/Buttons/RestoreButton.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public Restorebutton()
{
InitializeComponent();

TheButton.Click += delegate { WindowSizing.Fullscreen_Restore(); };
TheButton.Click += delegate { WindowSizing.Fullscreen_Restore(!Settings.Default.Fullscreen); };

MouseEnter += delegate
{
Expand Down

0 comments on commit 046c139

Please sign in to comment.