Skip to content
Open
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
25 changes: 19 additions & 6 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3786,6 +3786,8 @@ namespace winrt::TerminalApp::implementation

TermControl TerminalPage::_SetupControl(const TermControl& term)
{
term.WindowActivationChanged(_activated);

// GH#12515: ConPTY assumes it's hidden at the start. If we're not, let it know now.
if (_visible)
{
Expand Down Expand Up @@ -5164,9 +5166,7 @@ namespace winrt::TerminalApp::implementation
const auto acrylicBrush = Media::AcrylicBrush();
// Make sure that we use the same backdrop source as TermControl.
// If we don't, it'll cause the same flickering as in GH #14384
acrylicBrush.BackgroundSource(_currentWindowSettings().EnableUnfocusedAcrylic() ?
Media::AcrylicBackgroundSource::Backdrop :
Media::AcrylicBackgroundSource::HostBackdrop);
acrylicBrush.BackgroundSource(Media::AcrylicBackgroundSource::Backdrop);
acrylicBrush.FallbackColor(bgColor);
acrylicBrush.TintColor(bgColor);
acrylicBrush.TintOpacity(0.5);
Expand Down Expand Up @@ -5393,9 +5393,22 @@ namespace winrt::TerminalApp::implementation

void TerminalPage::WindowActivated(const bool activated)
{
// Stash if we're activated. Use that when we reload
// the settings, change active panes, etc.
_activated = activated;
if (_activated != activated)
{
_activated = activated;
for (const auto& tab : _tabs)
{
if (const auto rootPane = _GetTabImpl(tab)->GetRootPane())
{
rootPane->WalkTree([activated](const auto& pane) {
if (const auto control = pane->GetTerminalControl())
{
control.WindowActivationChanged(activated);
}
});
}
}
}
_updateThemeColors();

_adjustProcessPriorityThrottled->Run();
Expand Down
41 changes: 35 additions & 6 deletions src/cascadia/TerminalControl/TermControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1103,27 +1103,28 @@ namespace winrt::Microsoft::Terminal::Control::implementation
// changed from what was in the original settings.
if (_core->UseAcrylic() && !transparentBg)
{
const auto backdropStyle = _windowActivated.has_value() || settings.EnableUnfocusedAcrylic() ?
Media::AcrylicBackgroundSource::Backdrop :
Media::AcrylicBackgroundSource::HostBackdrop;

// See if we've already got an acrylic background brush
// to avoid the flicker when setting up a new one
auto acrylic = RootGrid().Background().try_as<Media::AcrylicBrush>();

// Instantiate a brush if there's not already one there
if (acrylic == nullptr)
if (!acrylic || acrylic.BackgroundSource() != backdropStyle)
{
acrylic = Media::AcrylicBrush{};
acrylic.BackgroundSource(backdropStyle);
}

const auto backdropStyle =
_core->Settings().EnableUnfocusedAcrylic() ? Media::AcrylicBackgroundSource::Backdrop : Media::AcrylicBackgroundSource::HostBackdrop;
acrylic.BackgroundSource(backdropStyle);

// see GH#1082: Initialize background color so we don't get a
// fade/flash when _BackgroundColorChanged is called
acrylic.FallbackColor(bgColor);
acrylic.TintColor(bgColor);

// Apply brush settings
acrylic.TintOpacity(_core->Opacity());
acrylic.AlwaysUseFallback(_ShouldUseAcrylicFallback());

// Apply brush to control if it's not already there
if (RootGrid().Background() != acrylic)
Expand All @@ -1143,6 +1144,11 @@ namespace winrt::Microsoft::Terminal::Control::implementation
BackgroundBrush(RootGrid().Background());
}

bool TermControl::_ShouldUseAcrylicFallback()
{
return !_windowActivated.value_or(true) && !_core->Settings().EnableUnfocusedAcrylic();
}

// Method Description:
// - Handler for the core's BackgroundColorChanged event. Updates the color
// of our background brush to match.
Expand Down Expand Up @@ -2877,6 +2883,29 @@ namespace winrt::Microsoft::Terminal::Control::implementation
_core->WindowVisibilityChanged(showOrHide);
}

void TermControl::WindowActivationChanged(const bool activated)
{
if (_IsClosing() || _windowActivated == activated)
{
return;
}

// HostBackdrop can get the activation state wrong in XAML Islands.
// Use the top-level window's activation instead (GH#20944).
_windowActivated = activated;
if (const auto acrylic = RootGrid().Background().try_as<Media::AcrylicBrush>())
{
if (acrylic.BackgroundSource() == Media::AcrylicBackgroundSource::HostBackdrop)
{
_InitializeBackgroundBrush();
}
else
{
acrylic.AlwaysUseFallback(_ShouldUseAcrylicFallback());
}
}
}

// Method Description:
// - Get the modifier keys that are currently pressed. This can be used to
// find out which modifiers (ctrl, alt, shift) are pressed in events that
Expand Down
3 changes: 3 additions & 0 deletions src/cascadia/TerminalControl/TermControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
double QuickFixButtonCollapsedWidth();

void WindowVisibilityChanged(const bool showOrHide);
void WindowActivationChanged(const bool activated);

void ColorSelection(Control::SelectionColor fg, Control::SelectionColor bg, Core::MatchMode matchMode);

Expand Down Expand Up @@ -290,6 +291,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation

bool _closing{ false };
bool _focused{ false };
std::optional<bool> _windowActivated;
bool _initializedTerminal{ false };
bool _quickFixButtonCollapsible{ false };
bool _quickFixesAvailable{ false };
Expand Down Expand Up @@ -354,6 +356,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
void _SetBackgroundImage(const IControlAppearance& newAppearance);

void _InitializeBackgroundBrush();
bool _ShouldUseAcrylicFallback();
safe_void_coroutine _coreBackgroundColorChanged(const IInspectable& sender, const IInspectable& args);
void _changeBackgroundColor(til::color bg);
static bool _isColorLight(til::color bg) noexcept;
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalControl/TermControl.idl
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ namespace Microsoft.Terminal.Control
Single SnapDimensionToGrid(Boolean widthOrHeight, Single dimension);

void WindowVisibilityChanged(Boolean showOrHide);
void WindowActivationChanged(Boolean activated);

void ScrollViewport(Int32 viewTop);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ namespace winrt::Microsoft::Terminal::Settings
{
const auto settings = _CreateWithProfileCommon(appSettings, windowSettings, profile);
settings->_UseBackgroundImageForWindow = false;
// Preview controls aren't driven by WindowActivationChanged, so keep them
// on Backdrop instead of HostBackdrop (GH#20944).
settings->_EnableUnfocusedAcrylic = true;
return settings;
}

Expand All @@ -75,8 +78,7 @@ namespace winrt::Microsoft::Terminal::Settings
// has no unfocused appearance, this behaves like CreateForPreview (the focused appearance).
winrt::com_ptr<TerminalSettings> TerminalSettings::CreateForPreviewUnfocused(const Model::CascadiaSettings& appSettings, const Model::WindowSettings& windowSettings, const Model::Profile& profile)
{
const auto settings = _CreateWithProfileCommon(appSettings, windowSettings, profile);
settings->_UseBackgroundImageForWindow = false;
const auto settings = CreateForPreview(appSettings, windowSettings, profile);
if (const auto& unfocusedAppearance{ profile.UnfocusedAppearance() })
{
const auto globals = appSettings.GlobalSettings();
Expand Down