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

Limit terminal warning bells to one per second #9812

Merged
1 commit merged into from
Apr 14, 2021
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
17 changes: 16 additions & 1 deletion src/cascadia/TerminalControl/TermControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ constexpr const auto TsfRedrawInterval = std::chrono::milliseconds(100);
// The minimum delay between updating the locations of regex patterns
constexpr const auto UpdatePatternLocationsInterval = std::chrono::milliseconds(500);

// The minimum delay between emitting warning bells
constexpr const auto TerminalWarningBellInterval = std::chrono::milliseconds(1000);

DEFINE_ENUM_FLAG_OPERATORS(winrt::Microsoft::Terminal::Control::CopyFormat);

namespace winrt::Microsoft::Terminal::Control::implementation
Expand Down Expand Up @@ -91,7 +94,9 @@ namespace winrt::Microsoft::Terminal::Control::implementation
// GH#8969: pre-seed working directory to prevent potential races
_terminal->SetWorkingDirectory(_settings.StartingDirectory());

auto pfnWarningBell = std::bind(&TermControl::_TerminalWarningBell, this);
auto pfnWarningBell = [this]() {
_playWarningBell->Run();
};
_terminal->SetWarningBellCallback(pfnWarningBell);

auto pfnTitleChanged = std::bind(&TermControl::_TerminalTitleChanged, this, std::placeholders::_1);
Expand Down Expand Up @@ -167,6 +172,16 @@ namespace winrt::Microsoft::Terminal::Control::implementation
UpdatePatternLocationsInterval,
Dispatcher());

_playWarningBell = std::make_shared<ThrottledFunc<>>(
[weakThis = get_weak()]() {
if (auto control{ weakThis.get() })
{
control->_TerminalWarningBell();
}
},
TerminalWarningBellInterval,
Dispatcher());

_updateScrollBar = std::make_shared<ThrottledFunc<ScrollBarUpdate>>(
[weakThis = get_weak()](const auto& update) {
if (auto control{ weakThis.get() })
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalControl/TermControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation

std::shared_ptr<ThrottledFunc<>> _updatePatternLocations;

std::shared_ptr<ThrottledFunc<>> _playWarningBell;

struct ScrollBarUpdate
{
std::optional<double> newValue;
Expand Down