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

Fixed Windows 10 theme #1223

Merged
merged 1 commit into from
Jun 17, 2024
Merged
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
2 changes: 1 addition & 1 deletion src/app/dev/DevToys.Blazor/wwwroot/css/devtoys.g.css

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Windows;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Automation.Peers;
using System.Windows.Automation.Provider;
using System.Windows.Controls;
Expand All @@ -14,6 +15,7 @@
using Windows.Win32.Foundation;
using Windows.Win32.Graphics.Dwm;
using Windows.Win32.UI.Controls;
using Windows.Win32.UI.WindowsAndMessaging;
using Application = System.Windows.Application;
using Button = System.Windows.Controls.Button;
using Color = System.Windows.Media.Color;
Expand Down Expand Up @@ -333,6 +335,36 @@ private void ApplyBackdrop(HWND windowHandle)
int parameter = DwmValues.True;
NativeMethods.SetWindowAttribute(windowHandle, (DWMWINDOWATTRIBUTE)DWMWINDOWATTRIBUTE_EXTENDED.DWMWA_MICA_EFFECT, ref parameter);
}
else
{
uint gradientColor = 0xFF202020;
if (_themeListener.ActualAppTheme == ApplicationTheme.Light)
{
gradientColor = 0xFFFFFFFF;
}

// Effect for Windows 10
var accentPolicy = new AccentPolicy
{
AccentState = AccentState.ACCENT_ENABLE_ACRYLICBLURBEHIND,
GradientColor = gradientColor
};

int accentStructSize = Marshal.SizeOf(accentPolicy);
nint accentPtr = Marshal.AllocHGlobal(accentStructSize);
Marshal.StructureToPtr(accentPolicy, accentPtr, false);

var data = new WindowCompositionAttributeData
{
Attribute = WindowCompositionAttribute.WCA_ACCENT_POLICY,
SizeOfData = accentStructSize,
Data = accentPtr
};

NativeMethods.SetWindowCompositionAttribute(windowHandle, ref data);

Marshal.FreeHGlobal(accentPtr);
}
}

private void ApplyResizeBorderThickness()
Expand Down Expand Up @@ -393,14 +425,6 @@ private void UpdateTheme()
dictionaries.Remove(resourceDictionaryToRemove);
dictionaries.Add(resourceDictionary);
UpdateLayout();

bool isWindow10_17763_OrLower = Environment.OSVersion.Version < new Version(10, 0, 17763);

// If Windows 10 17763 or lower
if (isWindow10_17763_OrLower)
{
// Todo: Based on the app theme, apply a Background color to the Window.
}
}

private nint ShowSnapLayout(nint lParam, ref bool handled)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace DevToys.Windows.Native;

[Flags]
internal enum AccentEdges
{
Left = 0x20,
Top = 0x40,
Right = 0x80,
Bottom = 0x100
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Runtime.InteropServices;

namespace DevToys.Windows.Native;

[StructLayout(LayoutKind.Sequential)]
internal struct AccentPolicy
{
public AccentState AccentState;
public int AccentFlags;
public uint GradientColor;
public int AnimationId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace DevToys.Windows.Native;

internal enum AccentState
{
ACCENT_DISABLED = 0,
ACCENT_ENABLE_GRADIENT = 1,
ACCENT_ENABLE_TRANSPARENTGRADIENT = 2,
ACCENT_ENABLE_BLURBEHIND = 3,
ACCENT_ENABLE_ACRYLICBLURBEHIND = 4,
ACCENT_INVALID_STATE = 5
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,14 @@ internal static void EnableMinimizeAndMaximizeCapabilities(HWND windowHandle)
PInvoke.EnableMenuItem(systemMenuHandle, (uint)PInvoke.SC_MINIMIZE, MENU_ITEM_FLAGS.MF_BYCOMMAND | MENU_ITEM_FLAGS.MF_ENABLED);
#pragma warning restore CA1416 // Validate platform compatibility
}

/// <summary>
/// Sets various information regarding DWM window attributes
/// </summary>
/// <param name="hwnd">The window handle whose information is to be changed</param>
/// <param name="data">Pointer to a structure which both specifies and delivers the attribute data</param>
/// <returns>Nonzero on success, zero otherwise.</returns>
[DllImport("user32.dll")]
internal static extern int SetWindowCompositionAttribute(IntPtr hwnd, ref WindowCompositionAttributeData data);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace DevToys.Windows.Native;

internal enum WindowCompositionAttribute
{
WCA_ACCENT_POLICY = 19
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Runtime.InteropServices;

namespace DevToys.Windows.Native;

[StructLayout(LayoutKind.Sequential)]
internal struct WindowCompositionAttributeData
{
public WindowCompositionAttribute Attribute;
public IntPtr Data;
public int SizeOfData;
}
Loading