Skip to content

Commit

Permalink
fix: clear state when swapping transparency providers
Browse files Browse the repository at this point in the history
  • Loading branch information
sophie authored and sophie-gilbert committed Jan 23, 2024
1 parent 40a8171 commit d9d9e02
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
6 changes: 6 additions & 0 deletions FoxTunes.UI.Windows/Behaviours/WindowAcrylicBlurBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ protected override void OnRefresh()
}
}

protected override void OnDisabled()
{
this.AccentColors.Clear();
base.OnDisabled();
}

public override IEnumerable<ConfigurationSection> GetConfigurationSections()
{
return WindowAcrylicBlurBehaviourConfiguration.GetConfigurationSections();
Expand Down
18 changes: 16 additions & 2 deletions FoxTunes.UI.Windows/Behaviours/WindowBlurProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,17 @@ protected virtual void OnActiveChanged(object sender, EventArgs e)

protected virtual void OnValueChanged(object sender, EventArgs e)
{
this.IsEnabled = this.Transparency.Value && string.Equals(this.Provider.Value.Id, this.Id, StringComparison.OrdinalIgnoreCase);
this.Refresh();
var enabled = this.Transparency.Value && string.Equals(this.Provider.Value.Id, this.Id, StringComparison.OrdinalIgnoreCase);
if (enabled && !this.IsEnabled)
{
this.IsEnabled = true;
this.Refresh();
}
else
{
this.IsEnabled = false;
this.OnDisabled();
}
}

public void Refresh()
Expand All @@ -56,6 +65,11 @@ public void Refresh()

protected abstract void OnRefresh();

protected virtual void OnDisabled()
{
//Nothing to do.
}

public abstract IEnumerable<ConfigurationSection> GetConfigurationSections();

public bool IsDisposed { get; private set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ protected override async void OnRefresh()
var outputStream = this.PlaybackManager.CurrentStream;
if (outputStream == null)
{
await this.Refresh(WindowExtensions.DefaultAccentColor).ConfigureAwait(false);
return;
}
var fileData = default(IFileData);
Expand Down Expand Up @@ -128,6 +129,12 @@ protected virtual Color GetAccentColor(string fileName)
return Color.FromArgb(color.A, color.R, color.G, color.B);
}

protected override void OnDisabled()
{
this.AccentColors.Clear();
base.OnDisabled();
}

public override IEnumerable<ConfigurationSection> GetConfigurationSections()
{
return WindowCoverArtAccentBehaviourConfiguration.GetConfigurationSections();
Expand Down
3 changes: 0 additions & 3 deletions FoxTunes.UI.Windows/Extensions/Window_AllowsTransparency.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,6 @@ public static void EnableBlur(IntPtr handle)
}
}

public static Color CurrentAccentColor;

public static void EnableAcrylicBlur(IntPtr handle, Color color)
{
var accent = new AccentPolicy()
Expand All @@ -168,7 +166,6 @@ public static void EnableAcrylicBlur(IntPtr handle, Color color)
{
Marshal.FreeHGlobal(accentPtr);
}
CurrentAccentColor = color;
}

public struct DwmColors
Expand Down

0 comments on commit d9d9e02

Please sign in to comment.