From fb69aecb19776e7fc07bb92d9b90f27be8f3b4fe Mon Sep 17 00:00:00 2001 From: Chester Liu Date: Tue, 20 Jul 2021 22:05:45 +0800 Subject: [PATCH] Defer cursor winrt event triggering (#10685) ## Summary of the Pull Request ## References ## PR Checklist * [X] Supports #10563 * [ ] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA * [ ] Tests added/passed * [ ] Documentation updated. If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/terminal) and link it here: #xxx * [ ] Schema updated. * [ ] I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: #xxx ## Detailed Description of the Pull Request / Additional comments ## Validation Steps Performed --- src/buffer/out/cursor.cpp | 5 +++++ src/buffer/out/cursor.h | 1 + src/cascadia/TerminalCore/Terminal.cpp | 7 ++++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/buffer/out/cursor.cpp b/src/buffer/out/cursor.cpp index 46f0208f8..1d050a215 100644 --- a/src/buffer/out/cursor.cpp +++ b/src/buffer/out/cursor.cpp @@ -315,6 +315,11 @@ void Cursor::StartDeferDrawing() noexcept _fDeferCursorRedraw = true; } +bool Cursor::IsDeferDrawing() noexcept +{ + return _fDeferCursorRedraw; +} + void Cursor::EndDeferDrawing() noexcept { if (_fHaveDeferredCursorRedraw) diff --git a/src/buffer/out/cursor.h b/src/buffer/out/cursor.h index 7ac93359a..dbd05f535 100644 --- a/src/buffer/out/cursor.h +++ b/src/buffer/out/cursor.h @@ -55,6 +55,7 @@ public: const COLORREF GetColor() const noexcept; void StartDeferDrawing() noexcept; + bool IsDeferDrawing() noexcept; void EndDeferDrawing() noexcept; void SetHasMoved(const bool fHasMoved) noexcept; diff --git a/src/cascadia/TerminalCore/Terminal.cpp b/src/cascadia/TerminalCore/Terminal.cpp index 666068cb0..9cc4aea47 100644 --- a/src/cascadia/TerminalCore/Terminal.cpp +++ b/src/cascadia/TerminalCore/Terminal.cpp @@ -1070,7 +1070,12 @@ void Terminal::_AdjustCursorPosition(const COORD proposedPosition) _buffer->GetRenderTarget().TriggerScroll(&delta); } - _NotifyTerminalCursorPositionChanged(); + // Firing the CursorPositionChanged event is very expensive so we try not to do that when + // the cursor does not need to be redrawn. + if (!cursor.IsDeferDrawing()) + { + _NotifyTerminalCursorPositionChanged(); + } } void Terminal::UserScrollViewport(const int viewTop)