From 320719ed3407bf112ebb564a6958fee69e720249 Mon Sep 17 00:00:00 2001 From: Ruben Date: Fri, 10 Jan 2025 18:38:51 +0100 Subject: [PATCH] Show window when minimized --- src/PicView.Avalonia.MacOS/App.axaml.cs | 64 +++++++++++++++++-- src/PicView.Avalonia.Win32/App.axaml.cs | 64 +++++++++++++++++-- .../WindowBehavior/WindowFunctions.cs | 10 ++- 3 files changed, 123 insertions(+), 15 deletions(-) diff --git a/src/PicView.Avalonia.MacOS/App.axaml.cs b/src/PicView.Avalonia.MacOS/App.axaml.cs index 944983ea..dbd8a23f 100644 --- a/src/PicView.Avalonia.MacOS/App.axaml.cs +++ b/src/PicView.Avalonia.MacOS/App.axaml.cs @@ -12,6 +12,7 @@ using PicView.Avalonia.StartUp; using PicView.Avalonia.UI; using PicView.Avalonia.ViewModels; +using PicView.Avalonia.WindowBehavior; using PicView.Core.Config; using PicView.Core.FileHandling; using PicView.Core.Localization; @@ -148,7 +149,14 @@ void Set() } else { - _aboutWindow.Activate(); + if (_aboutWindow.WindowState == WindowState.Minimized) + { + WindowFunctions.ShowMinimizedWindow(_aboutWindow); + } + else + { + _aboutWindow.Show(); + } } _ = FunctionsHelper.CloseMenus(); @@ -186,7 +194,14 @@ void Set() } else { - _exifWindow.Activate(); + if (_exifWindow.WindowState == WindowState.Minimized) + { + WindowFunctions.ShowMinimizedWindow(_exifWindow); + } + else + { + _exifWindow.Show(); + } } _ = FunctionsHelper.CloseMenus(); @@ -224,7 +239,14 @@ void Set() } else { - _keybindingsWindow.Activate(); + if (_keybindingsWindow.WindowState == WindowState.Minimized) + { + WindowFunctions.ShowMinimizedWindow(_keybindingsWindow); + } + else + { + _keybindingsWindow.Show(); + } } _ = FunctionsHelper.CloseMenus(); @@ -260,7 +282,14 @@ void Set() } else { - _settingsWindow.Activate(); + if (_settingsWindow.WindowState == WindowState.Minimized) + { + WindowFunctions.ShowMinimizedWindow(_settingsWindow); + } + else + { + _settingsWindow.Show(); + } } _= FunctionsHelper.CloseMenus(); @@ -296,7 +325,14 @@ void Set() } else { - _effectsWindow.Activate(); + if (_effectsWindow.WindowState == WindowState.Minimized) + { + WindowFunctions.ShowMinimizedWindow(_effectsWindow); + } + else + { + _effectsWindow.Show(); + } } _= FunctionsHelper.CloseMenus(); } @@ -331,7 +367,14 @@ void Set() } else { - _singleImageResizeWindow.Activate(); + if (_singleImageResizeWindow.WindowState == WindowState.Minimized) + { + WindowFunctions.ShowMinimizedWindow(_singleImageResizeWindow); + } + else + { + _singleImageResizeWindow.Show(); + } } _= FunctionsHelper.CloseMenus(); } @@ -366,7 +409,14 @@ void Set() } else { - _batchResizeWindow.Activate(); + if (_batchResizeWindow.WindowState == WindowState.Minimized) + { + WindowFunctions.ShowMinimizedWindow(_batchResizeWindow); + } + else + { + _batchResizeWindow.Show(); + } } _= FunctionsHelper.CloseMenus(); } diff --git a/src/PicView.Avalonia.Win32/App.axaml.cs b/src/PicView.Avalonia.Win32/App.axaml.cs index a6420c6b..d8df6f74 100644 --- a/src/PicView.Avalonia.Win32/App.axaml.cs +++ b/src/PicView.Avalonia.Win32/App.axaml.cs @@ -13,6 +13,7 @@ using PicView.Avalonia.UI; using PicView.Avalonia.ViewModels; using PicView.Avalonia.Win32.Views; +using PicView.Avalonia.WindowBehavior; using PicView.Core.Config; using PicView.Core.FileHandling; using PicView.Core.Localization; @@ -191,7 +192,14 @@ void Set() } else { - _aboutWindow.Activate(); + if (_aboutWindow.WindowState == WindowState.Minimized) + { + WindowFunctions.ShowMinimizedWindow(_aboutWindow); + } + else + { + _aboutWindow.Show(); + } } _ = FunctionsHelper.CloseMenus(); @@ -229,7 +237,14 @@ void Set() } else { - _exifWindow.Activate(); + if (_exifWindow.WindowState == WindowState.Minimized) + { + WindowFunctions.ShowMinimizedWindow(_exifWindow); + } + else + { + _exifWindow.Show(); + } } _ = FunctionsHelper.CloseMenus(); @@ -267,7 +282,14 @@ void Set() } else { - _keybindingsWindow.Activate(); + if (_keybindingsWindow.WindowState == WindowState.Minimized) + { + WindowFunctions.ShowMinimizedWindow(_keybindingsWindow); + } + else + { + _keybindingsWindow.Show(); + } } _ = FunctionsHelper.CloseMenus(); @@ -303,7 +325,14 @@ void Set() } else { - _settingsWindow.Activate(); + if (_settingsWindow.WindowState == WindowState.Minimized) + { + WindowFunctions.ShowMinimizedWindow(_settingsWindow); + } + else + { + _settingsWindow.Show(); + } } _= FunctionsHelper.CloseMenus(); @@ -339,7 +368,14 @@ void Set() } else { - _singleImageResizeWindow.Activate(); + if (_singleImageResizeWindow.WindowState == WindowState.Minimized) + { + WindowFunctions.ShowMinimizedWindow(_singleImageResizeWindow); + } + else + { + _singleImageResizeWindow.Show(); + } } _= FunctionsHelper.CloseMenus(); } @@ -374,7 +410,14 @@ void Set() } else { - _batchResizeWindow.Show(); + if (_batchResizeWindow.WindowState == WindowState.Minimized) + { + WindowFunctions.ShowMinimizedWindow(_batchResizeWindow); + } + else + { + _batchResizeWindow.Show(); + } } _= FunctionsHelper.CloseMenus(); } @@ -409,7 +452,14 @@ void Set() } else { - _effectsWindow.Show(); + if (_effectsWindow.WindowState == WindowState.Minimized) + { + WindowFunctions.ShowMinimizedWindow(_effectsWindow); + } + else + { + _effectsWindow.Show(); + } } _= FunctionsHelper.CloseMenus(); } diff --git a/src/PicView.Avalonia/WindowBehavior/WindowFunctions.cs b/src/PicView.Avalonia/WindowBehavior/WindowFunctions.cs index e7dc633e..9e7289db 100644 --- a/src/PicView.Avalonia/WindowBehavior/WindowFunctions.cs +++ b/src/PicView.Avalonia/WindowBehavior/WindowFunctions.cs @@ -66,7 +66,15 @@ public static async Task WindowClosingBehavior(Window window) Environment.Exit(0); } - #region Window State Management + #region Window State + + public static void ShowMinimizedWindow(Window window) + { + window.BringIntoView(); + window.WindowState = WindowState.Normal; + window.Activate(); + window.Focus(); + } public static async Task ToggleTopMost(MainViewModel vm) {