Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions Flow.Launcher.Infrastructure/Win32Helper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -517,5 +518,56 @@ public static bool IsNotificationSupported()
}

#endregion

#region Window Freeze

public static Dictionary<UIElement, CacheMode> ClearAllCacheModes(DependencyObject parent)
{
Dictionary<UIElement, CacheMode> cacheModes = new();

foreach (var element in FindVisualChildren<UIElement>(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<T> FindVisualChildren<T>(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<T>(child))
{
yield return childOfChild;
}
}
}
}

#endregion
}
}
2 changes: 1 addition & 1 deletion Flow.Launcher/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions Flow.Launcher/SettingWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion Flow.Launcher/ViewModel/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1520,7 +1520,7 @@ public void Show()
Win32Helper.SwitchToEnglishKeyboardLayout(true);
}
}

public async void Hide()
{
lastHistoryIndex = 1;
Expand Down
Loading