Skip to content

Commit 493f16c

Browse files
authored
Merge pull request #4513 from Flow-Launcher/fix-theme-issues
Fix blur theme backdrop, corners, margin issues & simplify AutoDropShadow
2 parents 5f9d116 + 7cf0b97 commit 493f16c

3 files changed

Lines changed: 35 additions & 29 deletions

File tree

Flow.Launcher.Core/Resource/Theme.cs

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,11 @@ public void RemoveDropShadowEffectFromCurrentTheme()
554554
ThemeHelper.CopyStyle(windowBorderStyle, newWindowBorderStyle);
555555

556556
// Copy Setters, excluding the Effect setter and updating the Margin setter
557+
// Only adjust margin if there's actually a shadow effect to remove,
558+
// preventing it from shrinking on repeated calls.
559+
bool hasEffect = windowBorderStyle.Setters.OfType<Setter>()
560+
.Any(s => s.Property == UIElement.EffectProperty);
561+
557562
foreach (var setterBase in windowBorderStyle.Setters)
558563
{
559564
if (setterBase is Setter setter)
@@ -562,7 +567,7 @@ public void RemoveDropShadowEffectFromCurrentTheme()
562567
if (setter.Property == UIElement.EffectProperty) continue;
563568

564569
// Update Margin by subtracting the extra margin we added for the shadow
565-
if (setter.Property == FrameworkElement.MarginProperty)
570+
if (hasEffect && setter.Property == FrameworkElement.MarginProperty)
566571
{
567572
var currentMargin = (Thickness)setter.Value;
568573
var newMargin = new Thickness(
@@ -635,20 +640,8 @@ await Application.Current.Dispatcher.InvokeAsync(() =>
635640
// Get the actual backdrop type and drop shadow effect settings
636641
var (backdropType, useDropShadowEffect) = GetActualValue();
637642

638-
// Remove OS minimizing/maximizing animation
639-
// Methods.SetWindowAttribute(new WindowInteropHelper(mainWindow).Handle, DWMWINDOWATTRIBUTE.DWMWA_TRANSITIONS_FORCEDISABLED, 3);
640-
641-
// The timing of adding the shadow effect should vary depending on whether the theme is transparent.
642-
if (BlurEnabled)
643-
{
644-
AutoDropShadow(useDropShadowEffect);
645-
}
646643
SetBlurForWindow(_settings.Theme, backdropType);
647-
648-
if (!BlurEnabled)
649-
{
650-
AutoDropShadow(useDropShadowEffect);
651-
}
644+
AutoDropShadow(useDropShadowEffect);
652645
}, DispatcherPriority.Render);
653646
}
654647

@@ -725,39 +718,42 @@ private void SetBlurForWindow(string theme, BackdropTypes backdropType)
725718
// Apply the blur effect
726719
Win32Helper.DWMSetBackdropForWindow(mainWindow, backdropType);
727720
ColorizeWindow(theme, backdropType);
721+
722+
// DWM renders rounded corners for backdrop windows
723+
SetWindowCornerPreference("Round");
724+
725+
// Clear any stale directly-set WindowBorderStyle that might shadow
726+
// the merged dictionary entry we just modified above.
727+
if (Application.Current.Resources.Contains("WindowBorderStyle"))
728+
Application.Current.Resources.Remove("WindowBorderStyle");
729+
730+
// For blur themes the resize border defaults to the system thickness.
731+
SetResizeBoarderThickness(null);
728732
}
729733
else
730734
{
731735
// Apply default style when Blur is disabled
732736
Win32Helper.DWMSetBackdropForWindow(mainWindow, BackdropTypes.None);
733737
ColorizeWindow(theme, backdropType);
738+
739+
// Non-blur themes use the default window corner preference
740+
SetWindowCornerPreference("Default");
734741
}
735742

736743
UpdateResourceDictionary(dict);
737744
}
738745

739746
private void AutoDropShadow(bool useDropShadowEffect)
740747
{
748+
if (BlurEnabled)
749+
return; // Blur themes have no drop shadow effect
750+
741751
if (useDropShadowEffect)
742752
{
743-
if (BlurEnabled && Win32Helper.IsBackdropSupported())
744-
{
745-
// For themes with blur enabled, the window border is rendered by the system,
746-
// so we set corner preference to round and remove drop shadow effect to avoid rendering issues.
747-
SetWindowCornerPreference("Round");
748-
RemoveDropShadowEffectFromCurrentTheme();
749-
}
750-
else
751-
{
752-
// For themes without blur, we set corner preference to default and add drop shadow effect.
753-
SetWindowCornerPreference("Default");
754-
AddDropShadowEffectToCurrentTheme();
755-
}
753+
AddDropShadowEffectToCurrentTheme();
756754
}
757755
else
758756
{
759-
// When drop shadow effect is disabled, we set corner preference to default and remove drop shadow effect.
760-
SetWindowCornerPreference("Default");
761757
RemoveDropShadowEffectFromCurrentTheme();
762758
}
763759
}

Flow.Launcher.Infrastructure/NativeMethods.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ VIRTUAL_KEY
1414
EnumWindows
1515

1616
DwmSetWindowAttribute
17+
DwmExtendFrameIntoClientArea
1718
DWM_SYSTEMBACKDROP_TYPE
1819
DWM_WINDOW_CORNER_PREFERENCE
1920

Flow.Launcher.Infrastructure/Win32Helper.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
using Windows.Win32.Graphics.Dwm;
2222
using Windows.Win32.System.Power;
2323
using Windows.Win32.System.Threading;
24+
using Windows.Win32.UI.Controls;
2425
using Windows.Win32.UI.Input.KeyboardAndMouse;
2526
using Windows.Win32.UI.Shell.Common;
2627
using Windows.Win32.UI.WindowsAndMessaging;
@@ -61,6 +62,14 @@ public static unsafe bool DWMSetBackdropForWindow(Window window, BackdropTypes b
6162
_ => DWM_SYSTEMBACKDROP_TYPE.DWMSBT_AUTO
6263
};
6364

65+
// The backdrop renders in the non-client frame area. WindowStyle=None
66+
// removes that area, so we extend it across the entire client area.
67+
// This is harmless when backdrop is None or blur not enabled
68+
// as DWM has nothing to render in the extended area.
69+
// https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/nf-dwmapi-dwmextendframeintoclientarea
70+
var margins = new MARGINS { cxLeftWidth = -1, cxRightWidth = -1, cyTopHeight = -1, cyBottomHeight = -1 };
71+
PInvoke.DwmExtendFrameIntoClientArea(GetWindowHandle(window), in margins);
72+
6473
return PInvoke.DwmSetWindowAttribute(
6574
GetWindowHandle(window),
6675
DWMWINDOWATTRIBUTE.DWMWA_SYSTEMBACKDROP_TYPE,

0 commit comments

Comments
 (0)