mirror of
https://github.com/QL-Win/QuickLook.git
synced 2026-05-17 01:01:29 +08:00
Fix DPI jump on window close in net462 #1626
This commit is contained in:
+14
-5
@@ -20,6 +20,7 @@ using QuickLook.Common.Helpers;
|
||||
using QuickLook.Helpers;
|
||||
using QuickLook.NativeMethods;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
@@ -28,13 +29,9 @@ using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using Wpf.Ui.Appearance;
|
||||
using Wpf.Ui.Violeta.Appearance;
|
||||
using Wpf.Ui.Violeta.Win32;
|
||||
|
||||
namespace QuickLook;
|
||||
|
||||
/// <summary>
|
||||
/// Interaction logic for App.xaml
|
||||
/// </summary>
|
||||
public partial class App : Application
|
||||
{
|
||||
public static readonly string LocalDataPath = SettingHelper.LocalDataPath;
|
||||
@@ -51,6 +48,19 @@ public partial class App : Application
|
||||
private bool _cleanExit = true;
|
||||
private Mutex _isRunning;
|
||||
|
||||
static App()
|
||||
{
|
||||
// Explicitly set to PerMonitor to avoid being overridden by the system
|
||||
if (SHCore.SetProcessDpiAwareness(SHCore.PROCESS_DPI_AWARENESS.PROCESS_PER_MONITOR_DPI_AWARE) is uint result)
|
||||
{
|
||||
Debug.WriteLine(
|
||||
result == 0 ?
|
||||
"DPI Awareness applied successfully" :
|
||||
$"DPI Awareness manual setup failed. Error Code: {result}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnStartup(StartupEventArgs e)
|
||||
{
|
||||
AppDomain.CurrentDomain.UnhandledException += (sender, args) =>
|
||||
@@ -71,7 +81,6 @@ public partial class App : Application
|
||||
ThemeManager.Apply(OSThemeHelper.AppsUseDarkTheme() ? ApplicationTheme.Dark : ApplicationTheme.Light);
|
||||
UxTheme.ApplyPreferredAppMode();
|
||||
|
||||
DpiAware.SetProcessDpiAwareness();
|
||||
base.OnStartup(e);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace QuickLook.NativeMethods;
|
||||
|
||||
internal static class SHCore
|
||||
{
|
||||
public enum PROCESS_DPI_AWARENESS
|
||||
{
|
||||
PROCESS_DPI_UNAWARE,
|
||||
PROCESS_SYSTEM_DPI_AWARE,
|
||||
PROCESS_PER_MONITOR_DPI_AWARE
|
||||
}
|
||||
|
||||
[DllImport("shcore.dll")]
|
||||
public static extern uint SetProcessDpiAwareness(PROCESS_DPI_AWARENESS awareness);
|
||||
}
|
||||
@@ -111,7 +111,7 @@
|
||||
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="UnblockZoneIdentifier " Version="1.0.0">
|
||||
<PackageReference Include="UnblockZoneIdentifier" Version="1.0.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
@@ -20,6 +20,7 @@ using QuickLook.Common.Helpers;
|
||||
using QuickLook.Common.Plugin;
|
||||
using QuickLook.Helpers;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media.Animation;
|
||||
@@ -108,6 +109,15 @@ public partial class ViewerWindow : Window
|
||||
buttonShare.ToolTip = TranslationHelper.Get("MW_Share");
|
||||
}
|
||||
|
||||
public new void Close()
|
||||
{
|
||||
// Workaround to prevent DPI jump animation when closing window in .NET Framework 4.6.2
|
||||
// Safe to remove this line if QuickLook no longer targets .NET Framework 4.6.2
|
||||
Hide();
|
||||
|
||||
base.Close();
|
||||
}
|
||||
|
||||
public override void OnApplyTemplate()
|
||||
{
|
||||
base.OnApplyTemplate();
|
||||
|
||||
Reference in New Issue
Block a user