Skip to content

Commit

Permalink
I promise this is the last time I touch the dark title bar code
Browse files Browse the repository at this point in the history
  • Loading branch information
ScrubN committed Oct 15, 2023
1 parent 3f7b79e commit 193b0ca
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
4 changes: 2 additions & 2 deletions TwitchDownloaderWPF/Services/NativeFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace TwitchDownloaderWPF.Services
{
[SupportedOSPlatform("windows")]
public static class NativeFunctions
public static unsafe class NativeFunctions
{
[DllImport("dwmapi.dll", EntryPoint = "DwmSetWindowAttribute", PreserveSig = true)]
public static extern int SetWindowAttribute(IntPtr handle, int attribute, [In] ref int attributeValue, int attributeSize);
public static extern int SetWindowAttribute(IntPtr handle, int attribute, void* attributeValue, uint attributeSize);
}
}
8 changes: 7 additions & 1 deletion TwitchDownloaderWPF/Services/ThemeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,13 @@ public void SetTitleBarTheme(WindowCollection windows)
foreach (Window window in windows)
{
var windowHandle = new WindowInteropHelper(window).Handle;
NativeFunctions.SetWindowAttribute(windowHandle, darkTitleBarAttribute, ref shouldUseDarkTitleBar, sizeof(int));
if (windowHandle == IntPtr.Zero)
continue;

unsafe
{
_ = NativeFunctions.SetWindowAttribute(windowHandle, darkTitleBarAttribute, &shouldUseDarkTitleBar, sizeof(int));
}
}

Window wnd = new()
Expand Down
1 change: 1 addition & 0 deletions TwitchDownloaderWPF/TwitchDownloaderWPF.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
<EnableNETAnalyzers>false</EnableNETAnalyzers>
<Platforms>AnyCPU;x64</Platforms>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<!--TODO: <Nullable>enable</Nullable> once we have required keyword-->
</PropertyGroup>
<PropertyGroup>
Expand Down

0 comments on commit 193b0ca

Please sign in to comment.