Skip to content
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

Reduce the frequency of AccentColor change event #144

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions FluentWPF/FluentWPF.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,35 @@
<PackagePath></PackagePath>
</None>
</ItemGroup>
<ItemGroup>
<Reference Include="System.Runtime.WindowsRuntime">
<HintPath>$(MSBuildProgramFiles32)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5\System.Runtime.WindowsRuntime.dll</HintPath>
</Reference>
<Reference Include="Windows">
<HintPath>$(MSBuildProgramFiles32)\Windows Kits\10\UnionMetadata\10.0.19041.0\Windows.winmd</HintPath>
<IsWinMDFile>true</IsWinMDFile>
</Reference>
</ItemGroup>

<ItemGroup>
<Resource Include="Assets\Images\noise.png" />
<Resource Include="Assets\Images\noiseBlack.png" />
<Resource Include="Assets\Images\noiseWhite.png" />
</ItemGroup>

<ItemGroup>
<Compile Update="Properties\Settings.Designer.cs">
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
<None Update="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>

</Project>
10 changes: 5 additions & 5 deletions FluentWPF/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 34 additions & 10 deletions FluentWPF/Resources/AccentColors.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
using SourceChord.FluentWPF.Utility;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
using System.Windows.Threading;
using Windows.UI.ViewManagement;

namespace SourceChord.FluentWPF
{
Expand All @@ -22,12 +20,16 @@ public class AccentColors : ThemeHandler


private static readonly int WM_DWMCOLORIZATIONCOLORCHANGED = 0x0320;

private static readonly UISettings settings = new UISettings();


static AccentColors()
{
AccentColors.Instance = new AccentColors();
if (SystemInfo.IsWin10())
{
settings.ColorValuesChanged += OnWin10AccentColorChanged;
}
Initialize();
}

Expand All @@ -36,11 +38,20 @@ public AccentColors()

}

private static void OnWin10AccentColorChanged(UISettings sender, object args)
{
Dispatcher.CurrentDispatcher.Invoke(() =>
{
Initialize();
});
}

protected override IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
if (msg == WM_DWMCOLORIZATIONCOLORCHANGED)
if (!SystemInfo.IsWin10() && msg == WM_DWMCOLORIZATIONCOLORCHANGED)
{
// 再取得
//Console.WriteLine("WM_DWMCOLORIZATIONCOLORCHANGED");
Initialize();
}

Expand Down Expand Up @@ -157,12 +168,20 @@ public static Brush ImmersiveSystemAccentLight3Brush
}
#endregion



internal static void Initialize()
{
// 各種Color定義
if (!SystemInfo.IsWin7())
if (SystemInfo.IsWin10())
{
ImmersiveSystemAccent = TranslateColor(settings.GetColorValue(UIColorType.Accent));
ImmersiveSystemAccentDark1 = TranslateColor(settings.GetColorValue(UIColorType.AccentDark1));
ImmersiveSystemAccentDark2 = TranslateColor(settings.GetColorValue(UIColorType.AccentDark2));
ImmersiveSystemAccentDark3 = TranslateColor(settings.GetColorValue(UIColorType.AccentDark3));
ImmersiveSystemAccentLight1 = TranslateColor(settings.GetColorValue(UIColorType.AccentLight1));
ImmersiveSystemAccentLight2 = TranslateColor(settings.GetColorValue(UIColorType.AccentLight1));
ImmersiveSystemAccentLight3 = TranslateColor(settings.GetColorValue(UIColorType.AccentLight2));
}
else if (!SystemInfo.IsWin7())
{
ImmersiveSystemAccent = GetColorByTypeName("ImmersiveSystemAccent");
ImmersiveSystemAccentDark1 = GetColorByTypeName("ImmersiveSystemAccentDark1");
Expand Down Expand Up @@ -194,6 +213,11 @@ internal static void Initialize()
ImmersiveSystemAccentLight3Brush = CreateBrush(ImmersiveSystemAccentLight3);
}

internal static Color TranslateColor(Windows.UI.Color color)
{
return Color.FromArgb(color.A, color.R, color.G, color.B);
}

internal static Brush CreateBrush(Color color)
{
var brush = new SolidColorBrush(color);
Expand All @@ -203,7 +227,7 @@ internal static Brush CreateBrush(Color color)


public static event EventHandler<PropertyChangedEventArgs> StaticPropertyChanged;
protected static void OnStaticPropertyChanged([CallerMemberName]string propertyName = null)
protected static void OnStaticPropertyChanged([CallerMemberName] string propertyName = null)
{
StaticPropertyChanged?.Invoke(null, new PropertyChangedEventArgs(propertyName));
}
Expand Down