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

Allow ThrottledFunc to work on different types of dispatcher #10187

Merged
60 commits merged into from
Aug 9, 2021

Conversation

zadjii-msft
Copy link
Member

⚠️ targets #10051

Summary of the Pull Request

This updates our ThrottledFuncs to take a dispatcher parameter. This means that we can use the Windows::UI::Core::CoreDispatcher in the TermControl, where there's always a CoreDispatcher, and use a Windows::System::DispatcherQueue in ControlCore/ControlInteractivity. When running in-proc, these are always the same thing. However, out-of-proc, the core needs a dispatcher queue that's not tied to a UI thread (because the content proces doesn't have a UI thread!).

This lets us get rid of the output event, because we don't need to bubble that event out to the TermControl to let it throttle that update anymore.

References

PR Checklist

Detailed Description of the Pull Request / Additional comments

Fortunately, winrt::resume_foreground works the same on both a CoreDispatcher and a DispatcherQueue, so this wasn't too hard!

Validation Steps Performed

This was validated in dev/migrie/oop/the-whole-thing (or dev/migrie/oop/connection-factory, I forget which), and I made sure that it worked both in-proc and x-proc. Not only that, it wasn't any slower!This reverts commit 04b751f.

  Now we have an InteractivityAutomationPeer, which acts like the implementation for TermControlAutomationPeer.

  TermControlAutomationPeer is still needed though, because it implements FrameworkElementAutomationPeer, which is needed to hook up the AP to the actual UIA tree.

  So we split up the work into two halves, the bit that should be done by the core (the ITextProvider, the IControlAccessibilityInfo), vs the stuff that needs to be in the control (FrameworkElementAutomationPeer). IUiaEventDispatcher should probably be in the control as well, but that's a problem for future us.
…ity-projection-000

# Conflicts:
#	src/cascadia/TerminalControl/ControlInteractivity.cpp
#	src/cascadia/TerminalControl/ControlInteractivity.h
#	src/cascadia/TerminalControl/TermControl.cpp
#	src/cascadia/UnitTests_Control/ControlInteractivityTests.cpp
Comment on lines +1158 to +1160
// When the buffer's cursor moves, start the throttled func to
// eventually dispatch a CursorPositionChanged event.
_tsfTryRedrawCanvas->Run();
Copy link
Member

@lhecker lhecker Jul 19, 2021

Choose a reason for hiding this comment

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

So if I understand it correctly, this starts a throttled func to throw an CursorPositionChanged event every 100ms, right? But TermControl also got a _tsfTryRedrawCanvas which only triggers the update every 100ms. Now it's only updating every 200-300ms (depending on the race between the two timers). Shouldn't we remove either of the two throttled funcs then?

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay so you have a point here. I'm gonna keep the throttling on the core side, not the control side. The Core will want to throttle how often it hops across the COM boundary to tell the UI to update. The UI doesn't care so much - it should just update whenever the Core tells it to.

@zadjii-msft
Copy link
Member Author

note to self:

Unittests are now failing because ControlCore::_terminalScrollPositionChanged triggers a throttledfunc to fire the ScrollPositionChanged callback. In real life, this is good - the user won't notice the delay. In the tests, this is bad - we want the callback firing instantly so we can check the value matches what we'd expect. Might need to introduce a delay in the tests to account for this. Unless I can think of a more clever solution.

@zadjii-msft zadjii-msft added AutoMerge Marked for automatic merge by the bot when requirements are met and removed Area-TerminalControl Issues pertaining to the terminal control (input, selection, keybindings, mouse interaction, etc.) labels Aug 9, 2021
@ghost
Copy link

ghost commented Aug 9, 2021

Hello @zadjii-msft!

Because this pull request has the AutoMerge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@ghost ghost merged commit 9f2d406 into main Aug 9, 2021
@ghost ghost deleted the dev/migrie/oop/throttled-funcs branch August 9, 2021 15:22
ghost pushed a commit that referenced this pull request Aug 26, 2021
This is on me. When I got rid of the `_updatePatternLocations` `ThrottledFunc` in the `TermControl`, I didn't add a matching call to `_updatePatternLocations->Run()` in this method.

In #9820, in `TermControl::_ScrollPositionChanged`, there was still a call to `_updatePatternLocations->Run();`. (TermControl.cpp:1655 on the right) https://github.com/microsoft/terminal/pull/9820/files#diff-c10bb023995e88dac6c1d786129284c454c2df739ea547ce462129dc86dc2697R1654

#10051 didn't change this

In #10187 I moved the `_updatePatternLocations` throttled func from termcontrol to controlcore. Places it existed before:
* [x] `TermControl::_coreReceivedOutput`: already matched by ControlCore::_connectionOutputHandler
* [x] `TermControl::_ScrollbarChangeHandler` -> added in c20eb9d
* [x] `TermControl::_ScrollPositionChanged` -> `ControlCore::_terminalScrollPositionChanged`

## Validation Steps Performed
Print a URL, scroll the wheel: it still works.

Closes #11055
DHowett pushed a commit that referenced this pull request Aug 26, 2021
This is on me. When I got rid of the `_updatePatternLocations` `ThrottledFunc` in the `TermControl`, I didn't add a matching call to `_updatePatternLocations->Run()` in this method.

In #9820, in `TermControl::_ScrollPositionChanged`, there was still a call to `_updatePatternLocations->Run();`. (TermControl.cpp:1655 on the right) https://github.com/microsoft/terminal/pull/9820/files#diff-c10bb023995e88dac6c1d786129284c454c2df739ea547ce462129dc86dc2697R1654

#10051 didn't change this

In #10187 I moved the `_updatePatternLocations` throttled func from termcontrol to controlcore. Places it existed before:
* [x] `TermControl::_coreReceivedOutput`: already matched by ControlCore::_connectionOutputHandler
* [x] `TermControl::_ScrollbarChangeHandler` -> added in c20eb9d
* [x] `TermControl::_ScrollPositionChanged` -> `ControlCore::_terminalScrollPositionChanged`

## Validation Steps Performed
Print a URL, scroll the wheel: it still works.

Closes #11055

(cherry picked from commit 7423734)
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AutoMerge Marked for automatic merge by the bot when requirements are met Issue-Task It's a feature request, but it doesn't really need a major design. Needs-Second It's a PR that needs another sign-off Product-Terminal The new Windows Terminal.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants