diff --git a/Flow.Launcher.Infrastructure/Win32Helper.cs b/Flow.Launcher.Infrastructure/Win32Helper.cs index f9c548de863..32c0c70fe2e 100644 --- a/Flow.Launcher.Infrastructure/Win32Helper.cs +++ b/Flow.Launcher.Infrastructure/Win32Helper.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.ComponentModel; using System.Globalization; using System.Runtime.InteropServices; @@ -517,5 +518,56 @@ public static bool IsNotificationSupported() } #endregion + + #region Window Freeze + + public static Dictionary ClearAllCacheModes(DependencyObject parent) + { + Dictionary cacheModes = new(); + + foreach (var element in FindVisualChildren(parent)) + { + if (element.CacheMode is null) continue; + + System.Diagnostics.Debug.WriteLine($"CacheMode Changed: {GetElementName(element)}{element.CacheMode.GetType().Name}"); + + // Store the previous CacheMode value + cacheModes[element] = element.CacheMode.Clone(); + + // Set the CacheMode to null + element.CacheMode = null; + } + + return cacheModes; + } + + private static string GetElementName(UIElement element) + { + if (element is FrameworkElement fe && !string.IsNullOrEmpty(fe.Name)) return fe.Name; + return element.GetType().Name; + } + + private static IEnumerable FindVisualChildren(DependencyObject parent) where T : DependencyObject + { + if (parent != null) + { + for (int i = 0; i < VisualTreeHelper.GetChildrenCount(parent); i++) + { + var child = VisualTreeHelper.GetChild(parent, i); + + if (child is T t) + { + yield return t; + } + + foreach (var childOfChild in FindVisualChildren(child)) + { + yield return childOfChild; + } + } + } + } + + #endregion } } diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index 30afe67a1f3..50c434f9d6d 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -105,7 +105,7 @@ private void OnSourceInitialized(object sender, EventArgs e) Win32Helper.HideFromAltTab(this); Win32Helper.DisableControlBox(this); } - + private async void OnLoaded(object sender, RoutedEventArgs _) { // Check first launch diff --git a/Flow.Launcher/SettingWindow.xaml.cs b/Flow.Launcher/SettingWindow.xaml.cs index 28140f0245c..b5a6a117f34 100644 --- a/Flow.Launcher/SettingWindow.xaml.cs +++ b/Flow.Launcher/SettingWindow.xaml.cs @@ -2,7 +2,6 @@ using System.Windows; using System.Windows.Forms; using System.Windows.Input; -using System.Windows.Interop; using CommunityToolkit.Mvvm.DependencyInjection; using Flow.Launcher.Infrastructure; using Flow.Launcher.Infrastructure.UserSettings; @@ -34,11 +33,12 @@ public SettingWindow() private void OnLoaded(object sender, RoutedEventArgs e) { RefreshMaximizeRestoreButton(); + // Fix (workaround) for the window freezes after lock screen (Win+L) or sleep // https://stackoverflow.com/questions/4951058/software-rendering-mode-wpf - HwndSource hwndSource = PresentationSource.FromVisual(this) as HwndSource; - HwndTarget hwndTarget = hwndSource.CompositionTarget; - hwndTarget.RenderMode = RenderMode.SoftwareOnly; // Must use software only render mode here + //HwndSource hwndSource = PresentationSource.FromVisual(this) as HwndSource; + //HwndTarget hwndTarget = hwndSource.CompositionTarget; + //hwndTarget.RenderMode = RenderMode.SoftwareOnly; // Must use software only render mode here InitializePosition(); } diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 17e4b55b71e..12c65771b81 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -1520,7 +1520,7 @@ public void Show() Win32Helper.SwitchToEnglishKeyboardLayout(true); } } - + public async void Hide() { lastHistoryIndex = 1;