From ea7d4b752c2afa27f76e9c35bb89163ab198dda8 Mon Sep 17 00:00:00 2001 From: Orbmu2k Date: Tue, 24 Mar 2026 16:09:16 +0100 Subject: [PATCH] mica snapshot win11 still broken --- .../Native/WINAPI/WindowBackdropHelper.cs | 62 +++++++++++++++++-- .../UI/Themes/SlateLightTheme.xaml | 2 +- 2 files changed, 59 insertions(+), 5 deletions(-) diff --git a/nvidiaProfileInspector/Native/WINAPI/WindowBackdropHelper.cs b/nvidiaProfileInspector/Native/WINAPI/WindowBackdropHelper.cs index a1f35f7..73d6d3a 100644 --- a/nvidiaProfileInspector/Native/WINAPI/WindowBackdropHelper.cs +++ b/nvidiaProfileInspector/Native/WINAPI/WindowBackdropHelper.cs @@ -6,6 +6,7 @@ namespace nvidiaProfileInspector.Native.WINAPI using System.Windows; using System.Windows.Interop; using System.Windows.Media; + using System.Windows.Shell; using nvidiaProfileInspector.Common.Helper; using nvidiaProfileInspector.Native.NVAPI2; using nvidiaProfileInspector.UI.Controls; @@ -35,6 +36,7 @@ namespace nvidiaProfileInspector.Native.WINAPI private const int Windows11Build = 22000; private const int Windows11BackdropBuild = 22621; private const int TitleBarFrameHeight = 48; + private const int MinimumWin11TitleBarFrameHeight = 54; public static void TryApplyTo(Window window) { @@ -52,6 +54,7 @@ namespace nvidiaProfileInspector.Native.WINAPI var backdropConfig = ResolveBackdropConfig(window); var win11Mode = GetWin11BackdropMode(); ApplyTitleBarBackground(window, version, win11Mode); + SyncWindowChromeCaptionHeight(window, version); if (ShouldSkipNativeBackdropInitialization(window, handle, win11Mode)) return; @@ -60,7 +63,7 @@ namespace nvidiaProfileInspector.Native.WINAPI if (version.Build >= Windows11Build) { - ExtendFrameIntoTitleBar(handle); + ExtendFrameIntoTitleBar(window, handle, version); if (!TryEnableWindows11Mica(handle, version, win11Mode)) { @@ -79,7 +82,7 @@ namespace nvidiaProfileInspector.Native.WINAPI return; } - ExtendFrameIntoTitleBar(handle); + ExtendFrameIntoTitleBar(window, handle, version); TryEnableWindows10Backdrop(handle, backdropConfig.GradientColor); } } @@ -193,19 +196,37 @@ namespace nvidiaProfileInspector.Native.WINAPI } } - private static void ExtendFrameIntoTitleBar(IntPtr handle) + private static void ExtendFrameIntoTitleBar(Window window, IntPtr handle, Version version) { + var topMargin = GetTitleBarFrameHeight(window, version); var margins = new Margins { Left = 0, Right = 0, - Top = TitleBarFrameHeight, + Top = topMargin, Bottom = 0 }; DwmExtendFrameIntoClientArea(handle, ref margins); } + private static int GetTitleBarFrameHeight(Window window, Version version) + { + var frameHeight = TitleBarFrameHeight; + + if (window?.FindName("AppTitleBar") is FrameworkElement titleBar) + { + var actualHeight = titleBar.ActualHeight; + if (actualHeight > 0) + frameHeight = Math.Max(frameHeight, (int)Math.Ceiling(actualHeight)); + } + + if (version.Build >= Windows11Build) + frameHeight = Math.Max(frameHeight, MinimumWin11TitleBarFrameHeight); + + return frameHeight; + } + private static void ApplyTitleBarBackground(Window window, Version version, Win11BackdropMode mode) { if (!(window.FindName("AppTitleBar") is TitleBar titleBar)) @@ -262,6 +283,39 @@ namespace nvidiaProfileInspector.Native.WINAPI } } + private static void SyncWindowChromeCaptionHeight(Window window, Version version) + { + if (version.Build < Windows11Build) + return; + + if (!(window?.FindName("AppTitleBar") is FrameworkElement titleBar)) + return; + + var actualHeight = titleBar.ActualHeight; + if (actualHeight <= 0) + return; + + var chrome = WindowChrome.GetWindowChrome(window); + if (chrome == null) + return; + + var captionHeight = Math.Ceiling(actualHeight); + if (captionHeight <= 0 || Math.Abs(chrome.CaptionHeight - captionHeight) <= 0.5) + return; + + var updatedChrome = new WindowChrome + { + CaptionHeight = captionHeight, + CornerRadius = chrome.CornerRadius, + GlassFrameThickness = chrome.GlassFrameThickness, + NonClientFrameEdges = chrome.NonClientFrameEdges, + ResizeBorderThickness = chrome.ResizeBorderThickness, + UseAeroCaptionButtons = chrome.UseAeroCaptionButtons + }; + + WindowChrome.SetWindowChrome(window, updatedChrome); + } + private static void TrySetImmersiveDarkMode(IntPtr handle, Version version, bool enabledValue) { if (version.Build < Windows10DarkModeBuild) diff --git a/nvidiaProfileInspector/UI/Themes/SlateLightTheme.xaml b/nvidiaProfileInspector/UI/Themes/SlateLightTheme.xaml index e734e7f..a8e163c 100644 --- a/nvidiaProfileInspector/UI/Themes/SlateLightTheme.xaml +++ b/nvidiaProfileInspector/UI/Themes/SlateLightTheme.xaml @@ -9,7 +9,7 @@ #F0F2F5 #E8EAED #FFFFFF - #33F7F7F7 + #22FFFFFF #EEF9FAFB #F8FCFCFD #AFC7CCD3