Skip to content

Commit

Permalink
Add auto acrylic api detection
Browse files Browse the repository at this point in the history
  • Loading branch information
NotYoojun committed Jun 28, 2024
1 parent 8c97c94 commit e79c477
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion samples/WpfApp1/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Title="MainWindow" Height="450" Width="800"
ResizeMode="CanMinimize"
ui:ThemeManager.IsThemeAware="True"
ui:TitleBar.ExtendViewIntoTitleBar="False" ui:WindowHelper.SystemBackdropType="Acrylic11"
ui:TitleBar.ExtendViewIntoTitleBar="False" ui:WindowHelper.SystemBackdropType="Acrylic"
ui:WindowHelper.ApplyNoise="False"
ui:WindowHelper.UseModernWindowStyle="True"
Loaded="Window_Loaded" Background="{x:Null}">
Expand Down
6 changes: 5 additions & 1 deletion source/iNKORE.UI.WPF.Modern/Controls/Helpers/WindowHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,11 @@ public static WindowChrome UpdateWindowChrome(this Window window)
// -----------------------------

var glassFrameThickness = new Thickness(-1);
switch (GetSystemBackdropType(window))
var actualBackdrop = GetSystemBackdropType(window);

if (actualBackdrop == BackdropType.Acrylic) actualBackdrop = BackdropHelper.IsSupported(BackdropType.Acrylic11) ? BackdropType.Acrylic11 : BackdropType.Acrylic10;

switch (actualBackdrop)
{
case BackdropType.None:
glassFrameThickness = new Thickness(-1);
Expand Down
9 changes: 5 additions & 4 deletions source/iNKORE.UI.WPF.Modern/Helpers/Styles/BackdropHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@ public enum BackdropType
{
None = 1,
Mica = 2,
Acrylic11 = 3,
Acrylic = 3,
Tabbed = 4,
Acrylic10,

[Obsolete("Use Acrylic11 or Acrylic10 instead.")]
Acrylic = 3
Acrylic10,
Acrylic11,
}

public static class BackdropHelper
Expand All @@ -45,6 +44,7 @@ public static bool IsSupported(this BackdropType type)
BackdropType.Mica => OSVersionHelper.OSVersion >= new Version(10, 0, 21996),
BackdropType.Acrylic11 => OSVersionHelper.OSVersion >= new Version(10, 0, 22523),
BackdropType.Acrylic10 => true,
BackdropType.Acrylic => IsSupported(BackdropType.Acrylic10) || IsSupported(BackdropType.Acrylic11),
_ => false
};
}
Expand Down Expand Up @@ -86,6 +86,7 @@ public static bool Apply(IntPtr handle, BackdropType type, bool force = false, C
BackdropType.Mica => TryApplyMica(handle),
BackdropType.Acrylic11 => TryApplyAcrylic(handle),
BackdropType.Acrylic10 => Acrylic10Helper.TryApplyAcrylic(handle, acrylic10Color ?? Colors.Transparent),
BackdropType.Acrylic => IsSupported(BackdropType.Acrylic11) ? Apply(handle, BackdropType.Acrylic11, force, acrylic10Color) : Apply(handle, BackdropType.Acrylic10, force, acrylic10Color),
BackdropType.Tabbed => TryApplyTabbed(handle),
_ => false
};
Expand Down

0 comments on commit e79c477

Please sign in to comment.