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

Add new Desktop Acrylic kind (Base and Thin) #1354

Merged
merged 4 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 5 additions & 0 deletions WinUIGallery/ControlPages/SystemBackdropsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
<Button Click="createBuiltInAcrylicWindow_Click">Create Window with built-in Acrylic</Button>
</local:ControlExample>

<local:ControlExample HeaderText="Create a window with a customizable Desktop Acrylic system backdrop."
CSharpSource="SystemBackdrops\SystemBackdropsSample2.txt">
karkarl marked this conversation as resolved.
Show resolved Hide resolved
<Button Click="createCustomDesktopAcrylicWindow_Click">Create Window with customizable Desktop Acrylic</Button>
</local:ControlExample>

<local:ControlExample HeaderText="Helper class to ensure a Windows.System.DispatcherQueue exists."
CSharpSource="SystemBackdrops\SystemBackdropsEnsureSystemDQC.txt">
<TextBlock Text="A Windows.System.DispatcherQueue must exist on the thread to use MicaController or DesktopAcrylicController. This helper class exposes and uses the underlying create function." TextWrapping="WrapWholeWords" />
Expand Down
9 changes: 8 additions & 1 deletion WinUIGallery/ControlPages/SystemBackdropsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,14 @@ private void createCustomMicaWindow_Click(object sender, RoutedEventArgs e)
private void createBuiltInAcrylicWindow_Click(object sender, RoutedEventArgs e)
{
var newWindow = new AppUIBasics.SamplePages.SampleSystemBackdropsWindow();
newWindow.SetBackdrop(AppUIBasics.SamplePages.SampleSystemBackdropsWindow.BackdropType.DesktopAcrylic);
newWindow.SetBackdrop(AppUIBasics.SamplePages.SampleSystemBackdropsWindow.BackdropType.DesktopAcrylicBase);
newWindow.Activate();
}

private void createCustomDesktopAcrylicWindow_Click(object sender, RoutedEventArgs e)
{
var newWindow = new AppUIBasics.SamplePages.SampleSystemBackdropsWindow();
newWindow.SetBackdrop(AppUIBasics.SamplePages.SampleSystemBackdropsWindow.BackdropType.DesktopAcrylicBase);
newWindow.Activate();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ WindowsSystemDispatcherQueueHelper m_wsdqHelper; // See separate sample below fo
Microsoft.UI.Composition.SystemBackdrops.MicaController m_micaController;
Microsoft.UI.Composition.SystemBackdrops.SystemBackdropConfiguration m_configurationSource;

bool TrySetMicaBackdrop()
bool TrySetMicaBackdrop(bool useMicaAlt)
{
if (Microsoft.UI.Composition.SystemBackdrops.MicaController.IsSupported())
{
Expand All @@ -24,6 +24,8 @@ bool TrySetMicaBackdrop()

m_micaController = new Microsoft.UI.Composition.SystemBackdrops.MicaController();

m_micaController.Kind = useMicaAlt ? Microsoft.UI.Composition.SystemBackdrops.MicaKind.BaseAlt : Microsoft.UI.Composition.SystemBackdrops.MicaKind.Base;

// Enable the system backdrop.
// Note: Be sure to have "using WinRT;" to support the Window.As<...>() call.
m_micaController.AddSystemBackdropTarget(this.As<Microsoft.UI.Composition.ICompositionSupportsSystemBackdrop>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ WindowsSystemDispatcherQueueHelper m_wsdqHelper; // See separate sample below fo
Microsoft.UI.Composition.SystemBackdrops.DesktopAcrylicController m_acrylicController;
Microsoft.UI.Composition.SystemBackdrops.SystemBackdropConfiguration m_configurationSource;

bool TrySetAcrylicBackdrop()
bool TrySetAcrylicBackdrop(bool useAcrylicThin)
{
if (Microsoft.UI.Composition.SystemBackdrops.DesktopAcrylicController.IsSupported())
{
Expand All @@ -24,6 +24,8 @@ bool TrySetAcrylicBackdrop()

m_acrylicController = new Microsoft.UI.Composition.SystemBackdrops.DesktopAcrylicController();

m_acrylicController.Kind = useAcrylicThin ? Microsoft.UI.Composition.SystemBackdrops.DesktopAcrylicKind.Thin : Microsoft.UI.Composition.SystemBackdrops.DesktopAcrylicKind.Base;

// Enable the system backdrop.
// Note: Be sure to have "using WinRT;" to support the Window.As<...>() call.
m_acrylicController.AddSystemBackdropTarget(this.As<Microsoft.UI.Composition.ICompositionSupportsSystemBackdrop>());
Expand Down
38 changes: 28 additions & 10 deletions WinUIGallery/SamplePages/SampleSystemBackdropsWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ public enum BackdropType
{
Mica,
MicaAlt,
DesktopAcrylic,
DesktopAcrylicBase,
DesktopAcrylicThin,
DefaultColor,
}

Expand Down Expand Up @@ -112,7 +113,7 @@ public void SetBackdrop(BackdropType type)
else
{
// Mica isn't supported. Try Acrylic.
type = BackdropType.DesktopAcrylic;
type = BackdropType.DesktopAcrylicBase;
tbChangeStatus.Text += " Mica isn't supported. Trying Acrylic.";
}
}
Expand All @@ -126,23 +127,37 @@ public void SetBackdrop(BackdropType type)
else
{
// MicaAlt isn't supported. Try Acrylic.
type = BackdropType.DesktopAcrylic;
type = BackdropType.DesktopAcrylicBase;
tbChangeStatus.Text += " MicaAlt isn't supported. Trying Acrylic.";
}
}
if (type == BackdropType.DesktopAcrylic)
if (type == BackdropType.DesktopAcrylicBase)
{
if (TrySetAcrylicBackdrop())
if (TrySetAcrylicBackdrop(false))
{
tbCurrentBackdrop.Text = "Custom Acrylic";
tbCurrentBackdrop.Text = "Custom Acrylic (Base)";
m_currentBackdrop = type;
}
else
{
// Acrylic isn't supported, so take the next option, which is DefaultColor, which is already set.
tbChangeStatus.Text += " Acrylic isn't supported. Switching to default color.";
tbChangeStatus.Text += " Acrylic Base isn't supported. Switching to default color.";
}
}
if (type == BackdropType.DesktopAcrylicThin)
{
if (TrySetAcrylicBackdrop(true))
{
tbCurrentBackdrop.Text = "Custom Acrylic (Thin)";
m_currentBackdrop = type;
}
else
{
// Acrylic isn't supported, so take the next option, which is DefaultColor, which is already set.
tbChangeStatus.Text += " Acrylic Thin isn't supported. Switching to default color.";
}
}

// announce visual change to automation
UIHelper.AnnounceActionForAccessibility(btnChangeBackdrop, $"Background changed to {tbCurrentBackdrop.Text}", "BackgroundChangedNotificationActivityId");
}
Expand Down Expand Up @@ -175,7 +190,7 @@ bool TrySetMicaBackdrop(bool useMicaAlt)
return false; // Mica is not supported on this system.
}

bool TrySetAcrylicBackdrop()
bool TrySetAcrylicBackdrop(bool useAcrylicThin)
{
if (Microsoft.UI.Composition.SystemBackdrops.DesktopAcrylicController.IsSupported())
{
Expand All @@ -191,6 +206,8 @@ bool TrySetAcrylicBackdrop()

m_acrylicController = new Microsoft.UI.Composition.SystemBackdrops.DesktopAcrylicController();

m_acrylicController.Kind = useAcrylicThin ? Microsoft.UI.Composition.SystemBackdrops.DesktopAcrylicKind.Thin : Microsoft.UI.Composition.SystemBackdrops.DesktopAcrylicKind.Base;

// Enable the system backdrop.
// Note: Be sure to have "using WinRT;" to support the Window.As<...>() call.
m_acrylicController.AddSystemBackdropTarget(this.As<Microsoft.UI.Composition.ICompositionSupportsSystemBackdrop>());
Expand Down Expand Up @@ -248,8 +265,9 @@ void ChangeBackdropButton_Click(object sender, RoutedEventArgs e)
switch (m_currentBackdrop)
{
case BackdropType.Mica: newType = BackdropType.MicaAlt; break;
case BackdropType.MicaAlt: newType = BackdropType.DesktopAcrylic; break;
case BackdropType.DesktopAcrylic: newType = BackdropType.DefaultColor; break;
case BackdropType.MicaAlt: newType = BackdropType.DesktopAcrylicBase; break;
case BackdropType.DesktopAcrylicBase: newType = BackdropType.DesktopAcrylicThin; break;
case BackdropType.DesktopAcrylicThin: newType = BackdropType.DefaultColor; break;
default:
case BackdropType.DefaultColor: newType = BackdropType.Mica; break;
}
Expand Down