Skip to content

Commit

Permalink
Limit terminal warning bells to one per second (#9812)
Browse files Browse the repository at this point in the history
<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist
* [x] Closes #9776
* [x] CLA signed.
* [ ] Tests added/passed
* [ ] Documentation updated. 
* [ ] Schema updated.
* [ ] I've discussed this with core contributors already. 

## Detailed Description of the Pull Request / Additional comments
Use `ThrottledFunc` in `TermControl` to limit bell emission callback to one per second.
  • Loading branch information
Don-Vito committed Apr 14, 2021
1 parent 7478248 commit 9a2d27e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
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

0 comments on commit 9a2d27e

Please sign in to comment.