feat(windows): add DWM window chrome and system theme watcher
DwmWindow sets dark mode (attribute 20, 19 on older Windows 10), Mica/none backdrop, corner preference and caption/border colours, returning false for null or stale windows and unsupported builds. SystemTheme reads AppsUseLightTheme and the accent colour (DWM AccentColor, else DwmGetColorizationColor); SystemThemeWatcher raises Changed from a RegNotifyChangeKeyValue thread when either value actually changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
5 files changed
+266
No files matched your search
@@ -0,0 +1,52 @@
|
||||
using Titano.Core.Windows.Window;
|
||||
using Titano.Testing;
|
||||
|
||||
namespace Titano.Core.Windows.Tests.Window;
|
||||
|
||||
public sealed class WindowTests
|
||||
{
|
||||
private static readonly nint StaleWindow = 0x0BAD_F00D;
|
||||
|
||||
[Test]
|
||||
[WindowsOnly]
|
||||
public void DwmCallsWithoutAValidWindowReturnFalse()
|
||||
{
|
||||
foreach (var window in new[] { (nint)0, StaleWindow })
|
||||
{
|
||||
Assert.False(DwmWindow.SetDarkMode(window, true));
|
||||
Assert.False(DwmWindow.SetBackdrop(window, SystemBackdrop.Mica));
|
||||
Assert.False(DwmWindow.SetCornerPreference(window, WindowCornerPreference.Round));
|
||||
Assert.False(DwmWindow.SetCaptionColor(window, new RgbColor(0x20, 0x20, 0x20)));
|
||||
Assert.False(DwmWindow.SetBorderColor(window, null));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
[WindowsOnly]
|
||||
public void SystemThemeReadsWithoutThrowing()
|
||||
{
|
||||
Assert.DoesNotThrow(() => _ = SystemTheme.AppsUseLightTheme);
|
||||
Assert.DoesNotThrow(() => _ = SystemTheme.AccentColor);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[WindowsOnly]
|
||||
[Timeout(30_000)]
|
||||
public void ThemeWatcherStartsAndStops()
|
||||
{
|
||||
var watcher = new SystemThemeWatcher();
|
||||
watcher.Changed += (_, _) => { };
|
||||
watcher.Dispose();
|
||||
watcher.Dispose();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ColoursConvertBetweenWin32Layouts()
|
||||
{
|
||||
var accent = RgbColor.FromAbgr(0xFFD77800);
|
||||
Assert.Equal(new RgbColor(0x00, 0x78, 0xD7), accent);
|
||||
Assert.Equal("#0078D7", accent.ToString());
|
||||
Assert.Equal(0x00D77800u, accent.ToColorRef());
|
||||
Assert.Equal(accent, RgbColor.FromArgb(0xFF0078D7));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user