-
-
Notifications
You must be signed in to change notification settings - Fork 564
Refactor drop shadow handling for window border style #4318
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -477,76 +477,113 @@ | |||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| public void AddDropShadowEffectToCurrentTheme() | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| var dict = GetCurrentResourceDictionary(); | ||||||||||||||||||||||||||||
| // Get current theme's WindowBorderStyle | ||||||||||||||||||||||||||||
| var theme = _settings.Theme; | ||||||||||||||||||||||||||||
| var dict = GetThemeResourceDictionary(theme); | ||||||||||||||||||||||||||||
| var windowBorderStyle = dict.Contains("WindowBorderStyle") ? dict["WindowBorderStyle"] as Style : null; | ||||||||||||||||||||||||||||
| if (windowBorderStyle == null) return; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| var windowBorderStyle = dict["WindowBorderStyle"] as Style; | ||||||||||||||||||||||||||||
| // Get a new unsealed style based on the old one, and copy Resources and Triggers | ||||||||||||||||||||||||||||
| var newWindowBorderStyle = new Style(typeof(Border)); | ||||||||||||||||||||||||||||
| CopyStyle(windowBorderStyle, newWindowBorderStyle); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| var effectSetter = new Setter | ||||||||||||||||||||||||||||
| // Identify existing Margin to calculate new Margin, and copy other setters | ||||||||||||||||||||||||||||
| Setter existingMarginSetter = null; | ||||||||||||||||||||||||||||
| foreach (var setterBase in windowBorderStyle.Setters) | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| Property = UIElement.EffectProperty, | ||||||||||||||||||||||||||||
| Value = new DropShadowEffect | ||||||||||||||||||||||||||||
| if (setterBase is Setter setter) | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| Opacity = 0.3, | ||||||||||||||||||||||||||||
| ShadowDepth = 12, | ||||||||||||||||||||||||||||
| Direction = 270, | ||||||||||||||||||||||||||||
| BlurRadius = 30 | ||||||||||||||||||||||||||||
| // Skip existing Margin (we'll replace it) | ||||||||||||||||||||||||||||
| if (setter.Property == FrameworkElement.MarginProperty) | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| existingMarginSetter = setter; | ||||||||||||||||||||||||||||
| continue; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| // Skip existing Effect (we'll ensure strictly one is added) | ||||||||||||||||||||||||||||
| if (setter.Property == UIElement.EffectProperty) continue; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| if (windowBorderStyle.Setters.FirstOrDefault(setterBase => setterBase is Setter setter && setter.Property == FrameworkElement.MarginProperty) is not Setter marginSetter) | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| var margin = new Thickness(ShadowExtraMargin, 12, ShadowExtraMargin, ShadowExtraMargin); | ||||||||||||||||||||||||||||
| marginSetter = new Setter() | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| Property = FrameworkElement.MarginProperty, | ||||||||||||||||||||||||||||
| Value = margin, | ||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||
| windowBorderStyle.Setters.Add(marginSetter); | ||||||||||||||||||||||||||||
| // Add other setters (e.g. Background, BorderThickness) | ||||||||||||||||||||||||||||
| newWindowBorderStyle.Setters.Add(setterBase); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
Comment on lines
+486
to
+509
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| SetResizeBoarderThickness(margin); | ||||||||||||||||||||||||||||
| // Calculate new Margin | ||||||||||||||||||||||||||||
| Thickness newMargin; | ||||||||||||||||||||||||||||
| if (existingMarginSetter == null) | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| newMargin = new Thickness(ShadowExtraMargin, 12, ShadowExtraMargin, ShadowExtraMargin); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| var baseMargin = (Thickness)marginSetter.Value; | ||||||||||||||||||||||||||||
| var newMargin = new Thickness( | ||||||||||||||||||||||||||||
| var baseMargin = (Thickness)existingMarginSetter.Value; | ||||||||||||||||||||||||||||
| newMargin = new Thickness( | ||||||||||||||||||||||||||||
| baseMargin.Left + ShadowExtraMargin, | ||||||||||||||||||||||||||||
| baseMargin.Top + ShadowExtraMargin, | ||||||||||||||||||||||||||||
| baseMargin.Right + ShadowExtraMargin, | ||||||||||||||||||||||||||||
| baseMargin.Bottom + ShadowExtraMargin); | ||||||||||||||||||||||||||||
| marginSetter.Value = newMargin; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| SetResizeBoarderThickness(newMargin); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| windowBorderStyle.Setters.Add(effectSetter); | ||||||||||||||||||||||||||||
| // Add new Margin Setter | ||||||||||||||||||||||||||||
| newWindowBorderStyle.Setters.Add(new Setter(FrameworkElement.MarginProperty, newMargin)); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| UpdateResourceDictionary(dict); | ||||||||||||||||||||||||||||
| // Add Drop Shadow Effect Setter | ||||||||||||||||||||||||||||
| newWindowBorderStyle.Setters.Add(new Setter | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| Property = UIElement.EffectProperty, | ||||||||||||||||||||||||||||
| Value = new DropShadowEffect | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| Opacity = 0.3, | ||||||||||||||||||||||||||||
| ShadowDepth = 12, | ||||||||||||||||||||||||||||
| Direction = 270, | ||||||||||||||||||||||||||||
| BlurRadius = 30 | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| SetResizeBoarderThickness(newMargin); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| Application.Current.Resources["WindowBorderStyle"] = newWindowBorderStyle; | ||||||||||||||||||||||||||||
|
Comment on lines
+543
to
+545
|
||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| public void RemoveDropShadowEffectFromCurrentTheme() | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| var dict = GetCurrentResourceDictionary(); | ||||||||||||||||||||||||||||
| var windowBorderStyle = dict["WindowBorderStyle"] as Style; | ||||||||||||||||||||||||||||
| // Get current theme's WindowBorderStyle | ||||||||||||||||||||||||||||
| var theme = _settings.Theme; | ||||||||||||||||||||||||||||
| var dict = GetThemeResourceDictionary(theme); | ||||||||||||||||||||||||||||
| var windowBorderStyle = dict.Contains("WindowBorderStyle") ? dict["WindowBorderStyle"] as Style : null; | ||||||||||||||||||||||||||||
| if (windowBorderStyle == null) return; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| if (windowBorderStyle.Setters.FirstOrDefault(setterBase => setterBase is Setter setter && setter.Property == UIElement.EffectProperty) is Setter effectSetter) | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| windowBorderStyle.Setters.Remove(effectSetter); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| // Get a new unsealed style based on the old one, and copy Resources and Triggers | ||||||||||||||||||||||||||||
| var newWindowBorderStyle = new Style(typeof(Border)); | ||||||||||||||||||||||||||||
| CopyStyle(windowBorderStyle, newWindowBorderStyle); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| if (windowBorderStyle.Setters.FirstOrDefault(setterBase => setterBase is Setter setter && setter.Property == FrameworkElement.MarginProperty) is Setter marginSetter) | ||||||||||||||||||||||||||||
| // Copy Setters, excluding the Effect setter and updating the Margin setter | ||||||||||||||||||||||||||||
| foreach (var setterBase in windowBorderStyle.Setters) | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| var currentMargin = (Thickness)marginSetter.Value; | ||||||||||||||||||||||||||||
| var newMargin = new Thickness( | ||||||||||||||||||||||||||||
| currentMargin.Left - ShadowExtraMargin, | ||||||||||||||||||||||||||||
| currentMargin.Top - ShadowExtraMargin, | ||||||||||||||||||||||||||||
| currentMargin.Right - ShadowExtraMargin, | ||||||||||||||||||||||||||||
| currentMargin.Bottom - ShadowExtraMargin); | ||||||||||||||||||||||||||||
| marginSetter.Value = newMargin; | ||||||||||||||||||||||||||||
| if (setterBase is Setter setter) | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| // Skip existing Effect (We'll remove it) | ||||||||||||||||||||||||||||
| if (setter.Property == UIElement.EffectProperty) continue; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| // Update Margin by subtracting the extra margin we added for the shadow | ||||||||||||||||||||||||||||
| if (setter.Property == FrameworkElement.MarginProperty) | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| var currentMargin = (Thickness)setter.Value; | ||||||||||||||||||||||||||||
| var newMargin = new Thickness( | ||||||||||||||||||||||||||||
| currentMargin.Left - ShadowExtraMargin, | ||||||||||||||||||||||||||||
| currentMargin.Top - ShadowExtraMargin, | ||||||||||||||||||||||||||||
| currentMargin.Right - ShadowExtraMargin, | ||||||||||||||||||||||||||||
| currentMargin.Bottom - ShadowExtraMargin); | ||||||||||||||||||||||||||||
| newWindowBorderStyle.Setters.Add(new Setter(FrameworkElement.MarginProperty, newMargin)); | ||||||||||||||||||||||||||||
|
Comment on lines
+569
to
+577
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don’t subtract shadow margin from the baseline theme margin. At Lines 573-576, ✅ Minimal fix- var newMargin = new Thickness(
- currentMargin.Left - ShadowExtraMargin,
- currentMargin.Top - ShadowExtraMargin,
- currentMargin.Right - ShadowExtraMargin,
- currentMargin.Bottom - ShadowExtraMargin);
- newWindowBorderStyle.Setters.Add(new Setter(FrameworkElement.MarginProperty, newMargin));
+ newWindowBorderStyle.Setters.Add(new Setter(FrameworkElement.MarginProperty, currentMargin));📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||
| continue; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| newWindowBorderStyle.Setters.Add(setterBase); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
Comment on lines
+556
to
582
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| SetResizeBoarderThickness(null); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| UpdateResourceDictionary(dict); | ||||||||||||||||||||||||||||
| Application.Current.Resources["WindowBorderStyle"] = newWindowBorderStyle; | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
| Application.Current.Resources["WindowBorderStyle"] = newWindowBorderStyle; | |
| // Update the current theme's resource dictionary instead of overriding the | |
| // application-level resource, so later theme updates keep correct precedence. | |
| dict["WindowBorderStyle"] = newWindowBorderStyle; | |
| UpdateResourceDictionary(dict); |
Check warning on line 642 in Flow.Launcher.Core/Resource/Theme.cs
GitHub Actions / Check Spelling
`FORCEDISABLED` is not a recognized word. (unrecognized-spelling)
Check warning on line 642 in Flow.Launcher.Core/Resource/Theme.cs
GitHub Actions / Check Spelling
`DWMWA` is not a recognized word. (unrecognized-spelling)
Check warning on line 686 in Flow.Launcher.Core/Resource/Theme.cs
GitHub Actions / Check Spelling
`dropshadow` is not a recognized word. (unrecognized-spelling)
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: This re-adds setters that were already copied by
CopyStyle, creating duplicate property setters inWindowBorderStyle.Prompt for AI agents