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

Disable acrylic material (temporarily) when opacity is set to 100% #14193

Merged
5 commits merged into from
Oct 26, 2022
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
20 changes: 6 additions & 14 deletions src/cascadia/TerminalControl/ControlCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,18 +576,15 @@ namespace winrt::Microsoft::Terminal::Control::implementation
}

// Update our runtime opacity value
Opacity(newOpacity);
_runtimeOpacity = newOpacity;

// GH#11285 - If the user is on Windows 10, and they changed the
// transparency of the control s.t. it should be partially opaque, then
// opt them in to acrylic. It's the only way to have transparency on
// Windows 10.
// We'll also turn the acrylic back off when they're fully opaque, which
// is what the Terminal did prior to 1.12.
if (!IsVintageOpacityAvailable())
{
_runtimeUseAcrylic = newOpacity < 1.0;
}
_runtimeUseAcrylic = newOpacity < 1.0 && (!IsVintageOpacityAvailable() || _settings->UseAcrylic());

// Update the renderer as well. It might need to fall back from
// cleartype -> grayscale if the BG is transparent / acrylic.
Expand Down Expand Up @@ -711,16 +708,12 @@ namespace winrt::Microsoft::Terminal::Control::implementation

auto lock = _terminal->LockForWriting();

_runtimeOpacity = std::nullopt;
_runtimeUseAcrylic = std::nullopt;

// GH#11285 - If the user is on Windows 10, and they wanted opacity, but
// didn't explicitly request acrylic, then opt them in to acrylic.
// On Windows 11+, this isn't needed, because we can have vintage opacity.
if (!IsVintageOpacityAvailable() && _settings->Opacity() < 1.0 && !_settings->UseAcrylic())
{
_runtimeUseAcrylic = true;
}
// Instead, disable acrylic while the opacity is 100%
_runtimeUseAcrylic = _settings->Opacity() < 1.0 && (!IsVintageOpacityAvailable() || _settings->UseAcrylic());
_runtimeOpacity = std::nullopt;

const auto sizeChanged = _setFontSizeUnderLock(_settings->FontSize());

Expand Down Expand Up @@ -1972,13 +1965,12 @@ namespace winrt::Microsoft::Terminal::Control::implementation
{
// If we're:
// * Not fully opaque
// * On an acrylic background (of any opacity)
// * rendering on top of an image
//
// then the renderer should not render "default background" text with a
// fully opaque background. Doing that would cover up our nice
// transparency, or our acrylic, or our image.
return Opacity() < 1.0f || UseAcrylic() || !_settings->BackgroundImage().empty() || _settings->UseBackgroundImageForWindow();
return Opacity() < 1.0f || !_settings->BackgroundImage().empty() || _settings->UseBackgroundImageForWindow();
}

uint64_t ControlCore::OwningHwnd()
Expand Down
3 changes: 1 addition & 2 deletions src/cascadia/UnitTests_Control/ControlCoreTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,7 @@ namespace ControlUnitTests
// GH#603: Adjusting opacity shouldn't change whether or not we
// requested acrylic.

auto expectedUseAcrylic = winrt::Microsoft::Terminal::Control::implementation::ControlCore::IsVintageOpacityAvailable() ? true :
(expectedOpacity < 1.0 ? true : false);
auto expectedUseAcrylic = expectedOpacity < 1.0;
VERIFY_ARE_EQUAL(expectedUseAcrylic, core->UseAcrylic());
VERIFY_ARE_EQUAL(true, core->_settings->UseAcrylic());
};
Expand Down
4 changes: 2 additions & 2 deletions src/cascadia/UnitTests_Control/ControlInteractivityTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ namespace ControlUnitTests
// The Settings object's opacity shouldn't be changed
VERIFY_ARE_EQUAL(0.5, settings->Opacity());

auto expectedUseAcrylic = winrt::Microsoft::Terminal::Control::implementation::ControlCore::IsVintageOpacityAvailable() ? useAcrylic :
(expectedOpacity < 1.0 ? true : false);
auto expectedUseAcrylic = expectedOpacity < 1.0 &&
(!winrt::Microsoft::Terminal::Control::implementation::ControlCore::IsVintageOpacityAvailable() || useAcrylic);
VERIFY_ARE_EQUAL(useAcrylic, settings->UseAcrylic());
VERIFY_ARE_EQUAL(expectedUseAcrylic, core->UseAcrylic());
};
Expand Down