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

Fix Opacity in Windows 10, again #12255

Merged
2 commits merged into from
Jan 26, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions src/cascadia/TerminalControl/ControlCore.idl
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ namespace Microsoft.Terminal.Control
String FontFaceName { get; };
UInt16 FontWeight { get; };
Double Opacity { get; };
Boolean UseAcrylic { get; };

Boolean TrySendKeyEvent(Int16 vkey,
Int16 scanCode,
Expand Down
22 changes: 21 additions & 1 deletion src/cascadia/TerminalControl/TermControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,9 @@ namespace winrt::Microsoft::Terminal::Control::implementation
{
auto settings{ _core.Settings() };
auto bgColor = til::color{ _core.FocusedAppearance().DefaultBackground() };
if (settings.UseAcrylic())
// GH#11743: Make sure to use the Core's current UseAcrylic value, not
// the one from the settings.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: It's clear from the code that it's using the core and not the settings UseAcrylic value. This comment can be improved by summarizing why this is important.

if (_core.UseAcrylic())
{
// See if we've already got an acrylic background brush
// to avoid the flicker when setting up a new one
Expand Down Expand Up @@ -536,12 +538,30 @@ namespace winrt::Microsoft::Terminal::Control::implementation
void TermControl::_changeBackgroundOpacity()
{
const auto opacity{ _core.Opacity() };
const auto useAcrylic{ _core.UseAcrylic() };

// GH#11743, #11619: If we're changing whether or not acrylic is used,
// then just entirely reinitialize the brush. The primary way that this
// happens is on Windows 10, where we need to enable acrylic when the
// user asks for <100% opacity. Even when we remove this Windows 10
// fallback, we may still need this for something like changing if
// acrylic is enabled at runtime (GH#2531)
if (auto acrylic = RootGrid().Background().try_as<Media::AcrylicBrush>())
{
if (!useAcrylic)
{
_InitializeBackgroundBrush();
return;
}
acrylic.TintOpacity(opacity);
}
else if (auto solidColor = RootGrid().Background().try_as<Media::SolidColorBrush>())
{
if (useAcrylic)
{
_InitializeBackgroundBrush();
return;
}
solidColor.Opacity(opacity);
}
}
Expand Down