Skip to content

Commit

Permalink
All this witchcraft is necessary to make XAML+MUX work right
Browse files Browse the repository at this point in the history
  • Loading branch information
zadjii-msft committed Jun 6, 2019
1 parent d2248b9 commit fabd1cd
Show file tree
Hide file tree
Showing 6 changed files with 285 additions and 26 deletions.
3 changes: 3 additions & 0 deletions OpenConsole.sln
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Types.Unit.Tests", "src\types\ut_types\Types.Unit.Tests.vcxproj", "{34DE34D3-1CD6-4EE3-8BD9-A26B5B27EC73}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UnitTests_TerminalApp", "src\cascadia\ut_app\TerminalApp.UnitTests.vcxproj", "{CA5CAD1A-9333-4D05-B12A-1905CBF112F9}"
ProjectSection(ProjectDependencies) = postProject
{CA5CAD1A-9A12-429C-B551-8562EC954746} = {CA5CAD1A-9A12-429C-B551-8562EC954746}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TerminalAppLib", "src\cascadia\TerminalApp\lib\TerminalAppLib.vcxproj", "{CA5CAD1A-9A12-429C-B551-8562EC954746}"
ProjectSection(ProjectDependencies) = postProject
Expand Down
23 changes: 15 additions & 8 deletions src/cascadia/TerminalControl/TermControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,21 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
{
_closing = true;
// Don't let anyone else do something to the buffer.
auto lock = _terminal->LockForWriting();
std::unique_lock<std::shared_mutex> lock;
if (_terminal)
{
lock = _terminal->LockForWriting();
}

if (_connection != nullptr)
{
_connection.Close();
}

_renderer->TriggerTeardown();
if (_renderer != nullptr)
{
_renderer->TriggerTeardown();
}

_swapChainPanel = nullptr;
_root = nullptr;
Expand Down Expand Up @@ -551,9 +558,9 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation

if (ptr.PointerDeviceType() == Windows::Devices::Input::PointerDeviceType::Mouse)
{
// Ignore mouse events while the terminal does not have focus.
// This prevents the user from selecting and copying text if they
// click inside the current tab to refocus the terminal window.
// Ignore mouse events while the terminal does not have focus.
// This prevents the user from selecting and copying text if they
// click inside the current tab to refocus the terminal window.
if (!_focused)
{
args.Handled(true);
Expand Down Expand Up @@ -1046,7 +1053,7 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
// - Scrolls the viewport of the terminal and updates the scroll bar accordingly
// Arguments:
// - viewTop: the viewTop to scroll to
// The difference between this function and ScrollViewport is that this one also
// The difference between this function and ScrollViewport is that this one also
// updates the _scrollBar after the viewport scroll. The reason _scrollBar is not updated in
// ScrollViewport is because ScrollViewport is being called by _ScrollbarChangeHandler
void TermControl::KeyboardScrollViewport(int viewTop)
Expand Down Expand Up @@ -1240,11 +1247,11 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
static_cast<SHORT>(cursorPosition.X - _root.Padding().Left),
static_cast<SHORT>(cursorPosition.Y - _root.Padding().Top)
};

const auto fontSize = _actualFont.GetSize();
FAIL_FAST_IF(fontSize.X == 0);
FAIL_FAST_IF(fontSize.Y == 0);

// Normalize to terminal coordinates by using font size
terminalPosition.X /= fontSize.X;
terminalPosition.Y /= fontSize.Y;
Expand Down
62 changes: 44 additions & 18 deletions src/cascadia/ut_app/TabTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,46 +19,72 @@ namespace TerminalAppUnitTests
class TabTests
{
BEGIN_TEST_CLASS(TabTests)
TEST_CLASS_PROPERTY(L"ActivationContext", L"TerminalApp.Unit.Tests.manifest")
TEST_CLASS_PROPERTY(L"UAP:AppXManifest", L"PackagedCwaFullTrust")
// TEST_CLASS_PROPERTY(L"ActivationContext", L"TerminalApp.Unit.Tests.manifest")
// TEST_CLASS_PROPERTY(L"UAP:AppXManifest", L"PackagedCwaFullTrust")
TEST_CLASS_PROPERTY(L"RunAs", L"UAP")
TEST_CLASS_PROPERTY(L"UAP:AppXManifest", L"TerminalApp.Unit.Tests.AppxManifest.xml")
END_TEST_CLASS()

TEST_METHOD(CreateDummyTab);
TEST_METHOD(TryInitXamlIslands);
TEST_METHOD(CreateLocalWinRTType);
TEST_METHOD(CreateXamlObjects);
TEST_METHOD(CreateDummyTab);

TEST_CLASS_SETUP(ClassSetup)
{
reader = std::unique_ptr<Json::CharReader>(Json::CharReaderBuilder::CharReaderBuilder().newCharReader());
// TODO: init xaml islands here, once we're sure that it works

winrt::init_apartment(winrt::apartment_type::single_threaded);
// Initialize the Xaml Hosting Manager
_manager = winrt::Windows::UI::Xaml::Hosting::WindowsXamlManager::InitializeForCurrentThread();
_source = winrt::Windows::UI::Xaml::Hosting::DesktopWindowXamlSource{};

return true;
}

Json::Value VerifyParseSucceeded(std::string content);
void VerifyParseFailed(std::string content);

private:
std::unique_ptr<Json::CharReader> reader;
// TODO: Add this back as a member variable, once the test works
// winrt::Windows::UI::Xaml::Hosting::DesktopWindowXamlSource _source{ nullptr };

winrt::Windows::UI::Xaml::Hosting::WindowsXamlManager _manager{ nullptr };
winrt::Windows::UI::Xaml::Hosting::DesktopWindowXamlSource _source{ nullptr };
};

void TabTests::TryInitXamlIslands()
{
// DebugBreak();
winrt::Windows::UI::Xaml::Hosting::DesktopWindowXamlSource _source{ nullptr };
winrt::init_apartment(winrt::apartment_type::single_threaded);
// Initialize the Xaml Hosting Manager
auto manager = winrt::Windows::UI::Xaml::Hosting::WindowsXamlManager::InitializeForCurrentThread();
_source = winrt::Windows::UI::Xaml::Hosting::DesktopWindowXamlSource{};
// Ensures that XAML Islands was initialized correctly
VERIFY_IS_NOT_NULL(_manager);
VERIFY_IS_NOT_NULL(_source);
}

void TabTests::CreateLocalWinRTType()
{
// Verify we can create a WinRT type we authored
winrt::Microsoft::Terminal::Settings::TerminalSettings settings{};
VERIFY_IS_NOT_NULL(settings);
auto oldFontSize = settings.FontSize();
settings.FontSize(oldFontSize + 5);
auto newFontSize = settings.FontSize();
VERIFY_ARE_NOT_EQUAL(oldFontSize, newFontSize);
}

void TabTests::CreateXamlObjects()
{
// Verify we can create a some XAML objects
winrt::Windows::UI::Xaml::Controls::UserControl controlRoot;
VERIFY_IS_NOT_NULL(controlRoot);
winrt::Windows::UI::Xaml::Controls::Grid root;
VERIFY_IS_NOT_NULL(root);
winrt::Windows::UI::Xaml::Controls::SwapChainPanel swapChainPanel;
VERIFY_IS_NOT_NULL(swapChainPanel);
winrt::Windows::UI::Xaml::Controls::Primitives::ScrollBar scrollBar;
VERIFY_IS_NOT_NULL(scrollBar);
}

void TabTests::CreateDummyTab()
{
// This test won't work if the TryInitXamlIslands test fails. We'll
// remove that test once we have xaml islands working.
const auto profileGuid{ Utils::CreateGuid() };
winrt::Microsoft::Terminal::TerminalControl::TermControl term{ nullptr };
winrt::Microsoft::Terminal::TerminalControl::TermControl term{};
VERIFY_IS_NOT_NULL(term);

auto newTab = std::make_shared<Tab>(profileGuid, term);

Expand Down
Loading

0 comments on commit fabd1cd

Please sign in to comment.