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

Only access ControlInteractivity through the projection #10051

Merged
merged 46 commits into from
Jul 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
e4478ee
Only access ControlInteractivity through the projection
zadjii-msft Apr 29, 2021
400b35f
Only 24 more errors to go
zadjii-msft Apr 30, 2021
42b970b
Totally upend the control AutomationPeer workings
zadjii-msft Apr 30, 2021
4578c13
some comments that should have been in the previous commit. 16 errors…
zadjii-msft Apr 30, 2021
d8cc047
GetHoveredCell/UpdateHoveredCell. 12 remain.
zadjii-msft Apr 30, 2021
21a97b6
Revert "Revert "Use DComp surface handle for Swap Chain management.""
zadjii-msft May 3, 2021
2e861d8
some minor cleanup
zadjii-msft May 3, 2021
e20caae
Merge branch 'dev/migrie/f/oop/use-dcomp-handle' into dev/migrie/inte…
zadjii-msft May 3, 2021
d667f3b
Use the HANDLE for the swapchainin the core projection
zadjii-msft May 3, 2021
62cbf30
it builds and runs so I guess it's done now
zadjii-msft May 3, 2021
445bdf6
Do the delayload dance
zadjii-msft May 6, 2021
1376721
Merge branch 'dev/migrie/f/oop/use-dcomp-handle' into dev/migrie/inte…
zadjii-msft May 6, 2021
a1ce7cb
What a ridiculous hack
zadjii-msft May 7, 2021
03fb764
fix accessibility
zadjii-msft May 7, 2021
5e7d270
Merge remote-tracking branch 'origin/main' into dev/migrie/interactiv…
zadjii-msft May 7, 2021
6e031e5
I want to get the padding out of interactivity, but the control bound…
zadjii-msft May 7, 2021
47410c9
now this works!
zadjii-msft May 7, 2021
0869456
Some cleanup
zadjii-msft May 7, 2021
dace0c4
a bit more cleanup
zadjii-msft May 7, 2021
12b78f5
Merge remote-tracking branch 'origin/main' into dev/migrie/f/oop/use-…
zadjii-msft May 7, 2021
e340fe9
Merge branch 'dev/migrie/f/oop/use-dcomp-handle' into dev/migrie/inte…
zadjii-msft May 7, 2021
b7b23a8
god I knew I left these behind
zadjii-msft May 7, 2021
086710a
Merge remote-tracking branch 'origin/main' into dev/migrie/interactiv…
zadjii-msft May 12, 2021
21a6370
fix the tests
zadjii-msft May 12, 2021
4efdf39
This fixes nvda, so nowwe just have to polish
zadjii-msft May 13, 2021
59e911d
minor typo cleanup
zadjii-msft May 13, 2021
6f07004
some consts
zadjii-msft May 13, 2021
ff3b808
this is almost exclusively nits
zadjii-msft May 13, 2021
559d1de
simple nits
zadjii-msft May 20, 2021
804a114
this one's easy too
zadjii-msft May 20, 2021
0f0af03
An enum does in fact work across the process boundary
zadjii-msft May 21, 2021
95300d4
Merge remote-tracking branch 'origin/main' into dev/migrie/interactiv…
zadjii-msft May 21, 2021
1de9485
Merge remote-tracking branch 'origin/main' into dev/migrie/interactiv…
zadjii-msft May 24, 2021
1bc27d0
fix the build
zadjii-msft May 24, 2021
3cace60
chances are, this will fix the x86 build
zadjii-msft May 24, 2021
265bd9f
I am ashamed, this should not be there
zadjii-msft May 24, 2021
c8a2957
Port the automation peer crash fix to this branch, @carlos-zamora
zadjii-msft May 24, 2021
074f67c
The comment literally says to put this first. Why didn't I put this f…
zadjii-msft May 25, 2021
5a0840a
Merge remote-tracking branch 'origin/main' into dev/migrie/interactiv…
zadjii-msft May 25, 2021
f5665c5
Merge remote-tracking branch 'origin/main' into dev/migrie/interactiv…
DHowett Jun 10, 2021
056c354
Merge remote-tracking branch 'origin/main' into dev/migrie/interactiv…
zadjii-msft Jul 8, 2021
e643885
minor nits from carlos
zadjii-msft Jul 8, 2021
33653e0
Merge branch 'dev/migrie/interactivity-projection-000' of https://git…
zadjii-msft Jul 8, 2021
3d59a67
Merge remote-tracking branch 'origin/main' into dev/migrie/interactiv…
zadjii-msft Jul 8, 2021
5a598f7
Merge remote-tracking branch 'origin/main' into dev/migrie/interactiv…
zadjii-msft Jul 13, 2021
3797d52
Merge remote-tracking branch 'origin/main' into dev/migrie/interactiv…
zadjii-msft Jul 19, 2021
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
4 changes: 2 additions & 2 deletions src/cascadia/TerminalApp/AppLogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,7 @@ namespace winrt::TerminalApp::implementation
// - Gets the taskbar state value from the last active control
// Return Value:
// - The taskbar state of the last active control
size_t AppLogic::GetLastActiveControlTaskbarState()
uint64_t AppLogic::GetLastActiveControlTaskbarState()
{
if (_root)
{
Expand All @@ -1142,7 +1142,7 @@ namespace winrt::TerminalApp::implementation
// - Gets the taskbar progress value from the last active control
// Return Value:
// - The taskbar progress of the last active control
size_t AppLogic::GetLastActiveControlTaskbarProgress()
uint64_t AppLogic::GetLastActiveControlTaskbarProgress()
{
if (_root)
{
Expand Down
4 changes: 2 additions & 2 deletions src/cascadia/TerminalApp/AppLogic.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ namespace winrt::TerminalApp::implementation

void WindowCloseButtonClicked();

size_t GetLastActiveControlTaskbarState();
size_t GetLastActiveControlTaskbarProgress();
uint64_t GetLastActiveControlTaskbarState();
uint64_t GetLastActiveControlTaskbarProgress();

winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::UI::Xaml::Controls::ContentDialogResult> ShowDialog(winrt::Windows::UI::Xaml::Controls::ContentDialog dialog);

Expand Down
8 changes: 4 additions & 4 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2020,11 +2020,11 @@ namespace winrt::TerminalApp::implementation
// - Gets the taskbar state value from the last active control
// Return Value:
// - The taskbar state of the last active control
size_t TerminalPage::GetLastActiveControlTaskbarState()
uint64_t TerminalPage::GetLastActiveControlTaskbarState()
{
if (auto control{ _GetActiveControl() })
{
return gsl::narrow_cast<size_t>(control.TaskbarState());
return control.TaskbarState();
}
return {};
}
Expand All @@ -2033,11 +2033,11 @@ namespace winrt::TerminalApp::implementation
// - Gets the taskbar progress value from the last active control
// Return Value:
// - The taskbar progress of the last active control
size_t TerminalPage::GetLastActiveControlTaskbarProgress()
uint64_t TerminalPage::GetLastActiveControlTaskbarProgress()
{
if (auto control{ _GetActiveControl() })
{
return gsl::narrow_cast<size_t>(control.TaskbarProgress());
return control.TaskbarProgress();
}
return {};
}
Expand Down
4 changes: 2 additions & 2 deletions src/cascadia/TerminalApp/TerminalPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ namespace winrt::TerminalApp::implementation
winrt::TerminalApp::IDialogPresenter DialogPresenter() const;
void DialogPresenter(winrt::TerminalApp::IDialogPresenter dialogPresenter);

size_t GetLastActiveControlTaskbarState();
size_t GetLastActiveControlTaskbarProgress();
uint64_t GetLastActiveControlTaskbarState();
uint64_t GetLastActiveControlTaskbarProgress();

void ShowKeyboardServiceWarning();
winrt::hstring KeyboardServiceDisabledText();
Expand Down
53 changes: 44 additions & 9 deletions src/cascadia/TerminalControl/ControlCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,16 @@ namespace winrt::Microsoft::Terminal::Control::implementation
// - Updates last hovered cell, renders / removes rendering of hyper-link if required
// Arguments:
// - terminalPosition: The terminal position of the pointer
void ControlCore::UpdateHoveredCell(const std::optional<til::point>& terminalPosition)
void ControlCore::SetHoveredCell(Core::Point pos)
{
_updateHoveredCell(std::optional<til::point>{ pos });
}
void ControlCore::ClearHoveredCell()
{
_updateHoveredCell(std::nullopt);
}

void ControlCore::_updateHoveredCell(const std::optional<til::point> terminalPosition)
{
if (terminalPosition == _lastHoveredCell)
{
Expand Down Expand Up @@ -477,7 +486,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
return winrt::hstring{ _terminal->GetHyperlinkAtPosition(pos) };
}

winrt::hstring ControlCore::GetHoveredUriText() const
winrt::hstring ControlCore::HoveredUriText() const
{
auto lock = _terminal->LockForReading(); // Lock for the duration of our reads.
if (_lastHoveredCell.has_value())
Expand All @@ -487,9 +496,9 @@ namespace winrt::Microsoft::Terminal::Control::implementation
return {};
}

std::optional<til::point> ControlCore::GetHoveredCell() const
Windows::Foundation::IReference<Core::Point> ControlCore::HoveredCell() const
Copy link
Member

Choose a reason for hiding this comment

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

depending on how often this is called, it could be quite expensive. an IReference is a heap allocation for every .. thing.

{
return _lastHoveredCell;
return _lastHoveredCell.has_value() ? Windows::Foundation::IReference<Core::Point>{ _lastHoveredCell.value() } : nullptr;
}

// Method Description:
Expand Down Expand Up @@ -895,6 +904,24 @@ namespace winrt::Microsoft::Terminal::Control::implementation
return _actualFont;
}

winrt::Windows::Foundation::Size ControlCore::FontSize() const noexcept
{
const auto fontSize = GetFont().GetSize();
return {
::base::saturated_cast<float>(fontSize.X),
::base::saturated_cast<float>(fontSize.Y)
};
}
winrt::hstring ControlCore::FontFaceName() const noexcept
{
return winrt::hstring{ GetFont().GetFaceName() };
}

uint16_t ControlCore::FontWeight() const noexcept
{
return static_cast<uint16_t>(GetFont().GetWeight());
}

til::size ControlCore::FontSizeInDips() const
{
const til::size fontSize{ GetFont().GetSize() };
Expand Down Expand Up @@ -1077,10 +1104,18 @@ namespace winrt::Microsoft::Terminal::Control::implementation
return _settings.CopyOnSelect();
}

std::vector<std::wstring> ControlCore::SelectedText(bool trimTrailingWhitespace) const
Windows::Foundation::Collections::IVector<winrt::hstring> ControlCore::SelectedText(bool trimTrailingWhitespace) const
{
// RetrieveSelectedTextFromBuffer will lock while it's reading
return _terminal->RetrieveSelectedTextFromBuffer(trimTrailingWhitespace).text;
const auto internalResult{ _terminal->RetrieveSelectedTextFromBuffer(trimTrailingWhitespace).text };

auto result = winrt::single_threaded_vector<winrt::hstring>();

for (const auto& row : internalResult)
{
result.Append(winrt::hstring{ row });
Copy link
Member

Choose a reason for hiding this comment

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

Idly, I wonder if there's a string-move constructor for hstring. Since we don't need the copy that lives in the vector any longer, if there is it could be a way to save a whole string copy.

Copy link
Member

Choose a reason for hiding this comment

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

It doesn't look like there's a way to make a wstring just move straight into an hstring...

}
return result;
}

::Microsoft::Console::Types::IUiaData* ControlCore::GetUiaData() const
Expand Down Expand Up @@ -1124,7 +1159,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
}
}

void ControlCore::SetBackgroundOpacity(const float opacity)
void ControlCore::SetBackgroundOpacity(const double opacity)
{
if (_renderEngine)
{
Expand Down Expand Up @@ -1176,15 +1211,15 @@ namespace winrt::Microsoft::Terminal::Control::implementation
}
}

HANDLE ControlCore::GetSwapChainHandle() const
uint64_t ControlCore::SwapChainHandle() const
{
// This is called by:
// * TermControl::RenderEngineSwapChainChanged, who is only registered
// after Core::Initialize() is called.
// * TermControl::_InitializeTerminal, after the call to Initialize, for
// _AttachDxgiSwapChainToXaml.
// In both cases, we'll have a _renderEngine by then.
return _renderEngine->GetSwapChainHandle();
return reinterpret_cast<uint64_t>(_renderEngine->GetSwapChainHandle());
}

void ControlCore::_rendererWarning(const HRESULT hr)
Expand Down
18 changes: 12 additions & 6 deletions src/cascadia/TerminalControl/ControlCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,19 @@ namespace winrt::Microsoft::Terminal::Control::implementation
void UpdateAppearance(const IControlAppearance& newAppearance);
void SizeChanged(const double width, const double height);
void ScaleChanged(const double scale);
HANDLE GetSwapChainHandle() const;
uint64_t SwapChainHandle() const;

void AdjustFontSize(int fontSizeDelta);
void ResetFontSize();
FontInfo GetFont() const;
til::size FontSizeInDips() const;

winrt::Windows::Foundation::Size FontSize() const noexcept;
winrt::hstring FontFaceName() const noexcept;
uint16_t FontWeight() const noexcept;

til::color BackgroundColor() const;
void SetBackgroundOpacity(const float opacity);
void SetBackgroundOpacity(const double opacity);

void SendInput(const winrt::hstring& wstr);
void PasteText(const winrt::hstring& hstr);
Expand All @@ -67,10 +71,11 @@ namespace winrt::Microsoft::Terminal::Control::implementation
void ResumeRendering();

void UpdatePatternLocations();
void UpdateHoveredCell(const std::optional<til::point>& terminalPosition);
void SetHoveredCell(Core::Point terminalPosition);
void ClearHoveredCell();
winrt::hstring GetHyperlink(const til::point position) const;
winrt::hstring GetHoveredUriText() const;
std::optional<til::point> GetHoveredCell() const;
winrt::hstring HoveredUriText() const;
Windows::Foundation::IReference<Core::Point> HoveredCell() const;

::Microsoft::Console::Types::IUiaData* GetUiaData() const;

Expand Down Expand Up @@ -119,7 +124,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation

bool HasSelection() const;
bool CopyOnSelect() const;
std::vector<std::wstring> SelectedText(bool trimTrailingWhitespace) const;
Windows::Foundation::Collections::IVector<winrt::hstring> SelectedText(bool trimTrailingWhitespace) const;
void SetSelectionAnchor(til::point const& position);
void SetEndSelectionPoint(til::point const& position);

Expand Down Expand Up @@ -232,6 +237,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
void _raiseReadOnlyWarning();
void _updateAntiAliasingMode(::Microsoft::Console::Render::DxEngine* const dxEngine);
void _connectionOutputHandler(const hstring& hstr);
void _updateHoveredCell(const std::optional<til::point> terminalPosition);

friend class ControlUnitTests::ControlCoreTests;
friend class ControlUnitTests::ControlInteractivityTests;
Expand Down
88 changes: 88 additions & 0 deletions src/cascadia/TerminalControl/ControlCore.idl
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,97 @@ import "EventArgs.idl";
namespace Microsoft.Terminal.Control
{

// This is a mirror of
// ::Microsoft::Console::VirtualTerminal::TerminalInput::MouseButtonState,
// but projectable.
// !! LOAD BEARING !! If you make this a struct with Booleans (like they
// make the most sense as), then the app will crash trying to toss one of
// these across the process boundary. I haven't the damndest idea why.
Copy link
Member

Choose a reason for hiding this comment

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

Well that's weird.

[flags]
enum MouseButtonState
{
IsLeftButtonDown = 0x1,
IsMiddleButtonDown = 0x2,
IsRightButtonDown = 0x4
};

[default_interface] runtimeclass ControlCore : ICoreState
{
ControlCore(IControlSettings settings,
Microsoft.Terminal.TerminalConnection.ITerminalConnection connection);

Boolean Initialize(Double actualWidth,
Double actualHeight,
Double compositionScale);

void UpdateSettings(IControlSettings settings);
void UpdateAppearance(IControlAppearance appearance);

UInt64 SwapChainHandle { get; };

Windows.Foundation.Size FontSize { get; };
String FontFaceName { get; };
UInt16 FontWeight { get; };

Boolean TrySendKeyEvent(Int16 vkey,
Int16 scanCode,
Microsoft.Terminal.Core.ControlKeyStates modifiers,
Boolean keyDown);
Boolean SendCharEvent(Char ch,
Int16 scanCode,
Microsoft.Terminal.Core.ControlKeyStates modifiers);
void SendInput(String text);
void PasteText(String text);

void SetHoveredCell(Microsoft.Terminal.Core.Point terminalPosition);
void ClearHoveredCell();

void ResetFontSize();
void AdjustFontSize(Int32 fontSizeDelta);
void SizeChanged(Double width, Double height);
void ScaleChanged(Double scale);

void ToggleShaderEffects();
void ToggleReadOnlyMode();

Microsoft.Terminal.Core.Point CursorPosition { get; };
void ResumeRendering();
void BlinkAttributeTick();
void UpdatePatternLocations();
void Search(String text, Boolean goForward, Boolean caseSensitive);
void SetBackgroundOpacity(Double opacity);
Microsoft.Terminal.Core.Color BackgroundColor { get; };

Boolean HasSelection { get; };
IVector<String> SelectedText(Boolean trimTrailingWhitespace);

String HoveredUriText { get; };
Windows.Foundation.IReference<Microsoft.Terminal.Core.Point> HoveredCell { get; };

void Close();
void BlinkCursor();
Boolean IsInReadOnlyMode { get; };
Boolean CursorOn;
void EnablePainting();

event FontSizeChangedEventArgs FontSizeChanged;

event Windows.Foundation.TypedEventHandler<Object, CopyToClipboardEventArgs> CopyToClipboard;
event Windows.Foundation.TypedEventHandler<Object, TitleChangedEventArgs> TitleChanged;
event Windows.Foundation.TypedEventHandler<Object, Object> WarningBell;
event Windows.Foundation.TypedEventHandler<Object, Object> TabColorChanged;
event Windows.Foundation.TypedEventHandler<Object, Object> BackgroundColorChanged;
event Windows.Foundation.TypedEventHandler<Object, ScrollPositionChangedArgs> ScrollPositionChanged;
event Windows.Foundation.TypedEventHandler<Object, Object> CursorPositionChanged;
event Windows.Foundation.TypedEventHandler<Object, Object> TaskbarProgressChanged;
event Windows.Foundation.TypedEventHandler<Object, Object> ConnectionStateChanged;
event Windows.Foundation.TypedEventHandler<Object, Object> HoveredHyperlinkChanged;
event Windows.Foundation.TypedEventHandler<Object, Object> RendererEnteredErrorState;
event Windows.Foundation.TypedEventHandler<Object, Object> SwapChainChanged;
event Windows.Foundation.TypedEventHandler<Object, RendererWarningArgs> RendererWarning;
event Windows.Foundation.TypedEventHandler<Object, NoticeEventArgs> RaiseNotice;
event Windows.Foundation.TypedEventHandler<Object, TransparencyChangedEventArgs> TransparencyChanged;
event Windows.Foundation.TypedEventHandler<Object, Object> ReceivedOutput;

};
}
Loading