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

Flash the pane dark when BEL is emitted in a light terminal #13707

Merged
4 commits merged into from
Aug 11, 2022
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
37 changes: 33 additions & 4 deletions src/cascadia/TerminalControl/TermControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,17 @@ namespace winrt::Microsoft::Terminal::Control::implementation
// Firing it manually makes sure it does.
_BackgroundBrush = RootGrid().Background();
_PropertyChangedHandlers(*this, Windows::UI::Xaml::Data::PropertyChangedEventArgs{ L"BackgroundBrush" });

_isBackgroundLight = _isColorLight(bg);
}

bool TermControl::_isColorLight(til::color bg) noexcept
{
// GH#13450 function to check if the current background color is light
// enough to need a dark version of the visual bell indicator
// This is a poor man's Rec. 601 luma.
const auto l = 30 * bg.r + 59 * bg.g + 11 * bg.b;
return l > 12750;
}

// Method Description:
Expand Down Expand Up @@ -2699,15 +2710,25 @@ namespace winrt::Microsoft::Terminal::Control::implementation
// Initialize the animation if it does not exist
// We only initialize here instead of in the ctor because depending on the bell style setting,
// we may never need this animation
if (!_bellLightAnimation)
if (!_bellLightAnimation && !_isBackgroundLight)
{
_bellLightAnimation = Window::Current().Compositor().CreateScalarKeyFrameAnimation();
// Add key frames and a duration to our bell light animation
_bellLightAnimation.InsertKeyFrame(0.0, 2.0);
_bellLightAnimation.InsertKeyFrame(1.0, 1.0);
_bellLightAnimation.InsertKeyFrame(0.0, 4.0);
Copy link
Member

Choose a reason for hiding this comment

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

oh, right, okay, I get it. I was all confused why the current animation was moved to the light-colored BGs.

Before, we had a White light, that we animated from 2->1 Intensity. Now we've got a Gray light, so for dark BGs, we need a different animation. It's coincidental that the light BG version of the animation just so happens to use 1->2 Intensity (but now that I've typed it, I'm better realizing that's not even the same values as before 😅)

_bellLightAnimation.InsertKeyFrame(1.0, 1.9);
_bellLightAnimation.Duration(winrt::Windows::Foundation::TimeSpan(std::chrono::milliseconds(TerminalWarningBellInterval)));
}

// Likewise, initialize the dark version of the animation only if required
if (!_bellDarkAnimation && _isBackgroundLight)
{
_bellDarkAnimation = Window::Current().Compositor().CreateScalarKeyFrameAnimation();
// reversing the order of the intensity values produces a similar effect as the light version
_bellDarkAnimation.InsertKeyFrame(0.0, 1.0);
_bellDarkAnimation.InsertKeyFrame(1.0, 2.0);
_bellDarkAnimation.Duration(winrt::Windows::Foundation::TimeSpan(std::chrono::milliseconds(TerminalWarningBellInterval)));
}

// Similar to the animation, only initialize the timer here
if (!_bellLightTimer)
{
Expand All @@ -2726,7 +2747,15 @@ namespace winrt::Microsoft::Terminal::Control::implementation

// Switch on the light and animate the intensity to fade out
VisualBellLight::SetIsTarget(RootGrid(), true);
BellLight().CompositionLight().StartAnimation(L"Intensity", _bellLightAnimation);

if (_isBackgroundLight)
{
BellLight().CompositionLight().StartAnimation(L"Intensity", _bellDarkAnimation);
}
else
{
BellLight().CompositionLight().StartAnimation(L"Intensity", _bellLightAnimation);
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/cascadia/TerminalControl/TermControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
bool _pointerPressedInBounds{ false };

winrt::Windows::UI::Composition::ScalarKeyFrameAnimation _bellLightAnimation{ nullptr };
winrt::Windows::UI::Composition::ScalarKeyFrameAnimation _bellDarkAnimation{ nullptr };
Windows::UI::Xaml::DispatcherTimer _bellLightTimer{ nullptr };

std::optional<Windows::UI::Xaml::DispatcherTimer> _cursorTimer;
Expand All @@ -209,6 +210,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
winrt::Windows::UI::Xaml::Controls::SwapChainPanel::LayoutUpdated_revoker _layoutUpdatedRevoker;
bool _showMarksInScrollbar{ false };

bool _isBackgroundLight{ false };

inline bool _IsClosing() const noexcept
{
#ifndef NDEBUG
Expand All @@ -230,6 +233,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
void _InitializeBackgroundBrush();
winrt::fire_and_forget _coreBackgroundColorChanged(const IInspectable& sender, const IInspectable& args);
void _changeBackgroundColor(til::color bg);
static bool _isColorLight(til::color bg) noexcept;
void _changeBackgroundOpacity();

bool _InitializeTerminal();
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/TerminalControl/XamlLights.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
if (!CompositionLight())
{
auto spotLight{ Window::Current().Compositor().CreateAmbientLight() };
spotLight.Color(Windows::UI::Colors::White());
spotLight.Color(Windows::UI::Colors::Gray());
CompositionLight(spotLight);
}
}
Expand Down