-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: set window accent color from album artwork
- Loading branch information
1 parent
50aa705
commit bcc55dd
Showing
16 changed files
with
448 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
using FoxTunes.Interfaces; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Windows.Media; | ||
|
||
namespace FoxTunes | ||
{ | ||
[WindowsUserInterfaceDependency] | ||
//Requires Windows 11 22H2. | ||
[PlatformDependency(Major = 6, Minor = 2, Build = 22621)] | ||
public class WindowAccentBehaviour : StandardBehaviour | ||
{ | ||
public WindowAccentBehaviour() | ||
{ | ||
this.AccentColors = new Dictionary<IntPtr, Color>(); | ||
} | ||
|
||
public IDictionary<IntPtr, Color> AccentColors { get; private set; } | ||
|
||
public IConfiguration Configuration { get; private set; } | ||
|
||
public BooleanConfigurationElement Transparency { get; private set; } | ||
|
||
public TextConfigurationElement AccentColor { get; private set; } | ||
|
||
public override void InitializeComponent(ICore core) | ||
{ | ||
WindowBase.ActiveChanged += this.OnActiveChanged; | ||
this.Configuration = core.Components.Configuration; | ||
this.Transparency = this.Configuration.GetElement<BooleanConfigurationElement>( | ||
WindowsUserInterfaceConfiguration.SECTION, | ||
WindowsUserInterfaceConfiguration.TRANSPARENCY | ||
); | ||
this.AccentColor = this.Configuration.GetElement<TextConfigurationElement>( | ||
WindowsUserInterfaceConfiguration.SECTION, | ||
WindowsUserInterfaceConfiguration.ACCENT_COLOR | ||
); | ||
this.AccentColor.ValueChanged += this.OnValueChanged; | ||
base.InitializeComponent(core); | ||
} | ||
|
||
protected virtual void OnActiveChanged(object sender, EventArgs e) | ||
{ | ||
this.Refresh(); | ||
} | ||
|
||
protected virtual void OnValueChanged(object sender, EventArgs e) | ||
{ | ||
this.Refresh(); | ||
} | ||
|
||
protected virtual void Refresh() | ||
{ | ||
if (!this.Transparency.Value) | ||
{ | ||
return; | ||
} | ||
var color = default(Color); | ||
if (!string.IsNullOrEmpty(this.AccentColor.Value)) | ||
{ | ||
color = this.AccentColor.Value.ToColor(); | ||
} | ||
else | ||
{ | ||
color = WindowExtensions.DefaultAccentColor; | ||
} | ||
this.Refresh(color); | ||
} | ||
|
||
protected virtual void Refresh(Color color) | ||
{ | ||
var windows = new HashSet<IntPtr>(); | ||
foreach (var window in WindowBase.Active) | ||
{ | ||
windows.Add(window.Handle); | ||
var currentColor = default(Color); | ||
if (AccentColors.TryGetValue(window.Handle, out currentColor) && currentColor == color) | ||
{ | ||
continue; | ||
} | ||
this.Refresh(window, color); | ||
this.AccentColors[window.Handle] = color; | ||
} | ||
foreach (var handle in AccentColors.Keys.ToArray()) | ||
{ | ||
if (!windows.Contains(handle)) | ||
{ | ||
AccentColors.Remove(handle); | ||
} | ||
} | ||
} | ||
|
||
protected virtual void Refresh(WindowBase window, Color color) | ||
{ | ||
WindowExtensions.EnableAcrylicBlur(window.Handle, color); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using FoxTunes.Interfaces; | ||
using System; | ||
|
||
namespace FoxTunes | ||
{ | ||
[WindowsUserInterfaceDependency] | ||
//TODO: Not sure of the exact required platform. | ||
//TODO: SetWindowCompositionAttribute is undocumented. | ||
//TODO: Assuming Windows 8. | ||
[PlatformDependency(Major = 6, Minor = 2)] | ||
public class WindowBlurBehaviour : StandardBehaviour | ||
{ | ||
public IConfiguration Configuration { get; private set; } | ||
|
||
public BooleanConfigurationElement Transparency { get; private set; } | ||
|
||
public override void InitializeComponent(ICore core) | ||
{ | ||
WindowBase.ActiveChanged += this.OnActiveChanged; | ||
this.Configuration = core.Components.Configuration; | ||
this.Transparency = this.Configuration.GetElement<BooleanConfigurationElement>( | ||
WindowsUserInterfaceConfiguration.SECTION, | ||
WindowsUserInterfaceConfiguration.TRANSPARENCY | ||
); | ||
base.InitializeComponent(core); | ||
} | ||
|
||
protected virtual void OnActiveChanged(object sender, EventArgs e) | ||
{ | ||
this.Refresh(); | ||
} | ||
|
||
protected virtual void Refresh() | ||
{ | ||
if (!this.Transparency.Value) | ||
{ | ||
return; | ||
} | ||
foreach (var window in WindowBase.Active) | ||
{ | ||
WindowExtensions.EnableBlur(window.Handle); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.