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

Update to use new SpanningRects API instead of DisplayRegions. #1822

Merged
merged 2 commits into from
Jan 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
42 changes: 18 additions & 24 deletions dev/TwoPaneView/DisplayRegionHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,29 @@ DisplayRegionHelperInfo DisplayRegionHelper::GetRegionInfo()
auto instance = LifetimeHandler::GetDisplayRegionHelperInstance();

DisplayRegionHelperInfo info;
info.RegionCount = 1;
info.Mode = winrt::TwoPaneViewMode::SinglePane;

if (instance->m_simulateDisplayRegions)
{
// Create fake rectangles for test app
if (instance->m_simulateMode == winrt::TwoPaneViewMode::Wide)
{
info.RegionCount = 2;
info.Regions[0] = m_simulateWide0;
info.Regions[1] = m_simulateWide1;
info.Mode = winrt::TwoPaneViewMode::Wide;
}
else if (instance->m_simulateMode == winrt::TwoPaneViewMode::Tall)
{
info.RegionCount = 2;
info.Regions[0] = m_simulateTall0;
info.Regions[1] = m_simulateTall1;
info.Mode = winrt::TwoPaneViewMode::Tall;
}
else
{
info.RegionCount = 1;
info.Regions[0] = m_simulateWide0;
}
}
else if (SharedHelpers::IsApplicationViewGetDisplayRegionsAvailable())
else
{
// ApplicationView::GetForCurrentView throws on failure; in that case we just won't do anything.
winrt::ApplicationView view{ nullptr };
Expand All @@ -49,30 +45,28 @@ DisplayRegionHelperInfo DisplayRegionHelper::GetRegionInfo()
view = winrt::ApplicationView::GetForCurrentView();
} catch(...) {}

// Verify that the window is Tiled
if (view)
{
auto regions = view.GetDisplayRegions();
info.RegionCount = std::min(regions.Size(), c_maxRegions);

// More than one region
if (info.RegionCount == 2)
if (const auto appView = view.try_as<winrt::IApplicationViewSpanningRects>())
{
winrt::Rect windowRect = WindowRect();
winrt::IVectorView<winrt::Rect> rects = appView.GetSpanningRects();

if (windowRect.Width > windowRect.Height)
{
info.Mode = winrt::TwoPaneViewMode::Wide;
float width = windowRect.Width / 2;
info.Regions[0] = { 0, 0, width, windowRect.Height };
info.Regions[1] = { width, 0, width, windowRect.Height };
}
else
if (rects.Size() == 2)
{
info.Mode = winrt::TwoPaneViewMode::Tall;
float height = windowRect.Height / 2;
info.Regions[0] = { 0, 0, windowRect.Width, height };
info.Regions[1] = { 0, height, windowRect.Width, height };
info.Regions[0] = rects.GetAt(0);
info.Regions[1] = rects.GetAt(1);

// Determine orientation. If neither of these are true, default to doing nothing.
if (info.Regions[0].X < info.Regions[1].X && info.Regions[0].Y == info.Regions[1].Y)
{
// Double portrait
info.Mode = winrt::TwoPaneViewMode::Wide;
}
else if (info.Regions[0].X == info.Regions[1].X && info.Regions[0].Y < info.Regions[1].Y)
{
// Double landscape
info.Mode = winrt::TwoPaneViewMode::Tall;
}
}
}
}
Expand Down
1 change: 0 additions & 1 deletion dev/TwoPaneView/DisplayRegionHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ struct DisplayRegionHelperInfo
{
winrt::TwoPaneViewMode Mode{ winrt::TwoPaneViewMode::SinglePane };
std::array<winrt::Rect, c_maxRegions> Regions{};
uint32_t RegionCount{ 0 };
};

class DisplayRegionHelper:
Expand Down
6 changes: 6 additions & 0 deletions dev/TwoPaneView/TwoPaneView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ TwoPaneView::TwoPaneView()
SetDefaultStyleKey(this);

SizeChanged({ this, &TwoPaneView::OnSizeChanged });
winrt::Window::Current().SizeChanged({ this, &TwoPaneView::OnWindowSizeChanged });
Copy link
Contributor

Choose a reason for hiding this comment

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

winrt::Window::Current().SizeChanged({ this, &TwoPaneView::OnWindowSizeChanged }); [](start = 4, length = 82)

I think this is not island friendly, I think we need to use appwindow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The dual-screen part of TwoPaneView doesn't work in islands, because we are tied to app view. Comp/shell work needs to be done in order for us to be able to be island-friendly.


EnsureProperties();
}
Expand Down Expand Up @@ -99,6 +100,11 @@ void TwoPaneView::OnScrollViewerLoaded(const winrt::IInspectable& sender, const
}
}

void TwoPaneView::OnWindowSizeChanged(const winrt::IInspectable& sender, const winrt::WindowSizeChangedEventArgs& args)
{
UpdateMode();
}

void TwoPaneView::OnSizeChanged(const winrt::IInspectable& sender, const winrt::SizeChangedEventArgs& args)
{
UpdateMode();
Expand Down
1 change: 1 addition & 0 deletions dev/TwoPaneView/TwoPaneView.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class TwoPaneView :
void OnScrollViewerLoaded(const winrt::IInspectable& sender, const winrt::RoutedEventArgs& args);

void OnSizeChanged(const winrt::IInspectable& sender, const winrt::SizeChangedEventArgs& args);
void OnWindowSizeChanged(const winrt::IInspectable& sender, const winrt::WindowSizeChangedEventArgs& args);

void UpdateRowsColumns(ViewMode newMode, DisplayRegionHelperInfo info, winrt::Rect rcControl);
void UpdateMode();
Expand Down
11 changes: 10 additions & 1 deletion dev/TwoPaneView/TwoPaneView.idl
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,13 @@ unsealed runtimeclass TwoPaneView : Windows.UI.Xaml.Controls.Control
static Windows.UI.Xaml.DependencyProperty MinTallModeHeightProperty { get; };
}

}
// TODO: Once IApplicationViewSpanningRects is available in the official SDK, remove this.
[WUXC_VERSION_INTERNAL]
[webhosthidden]
[uuid(645737E4-A882-4E16-B289-FD860560106A)]
interface IApplicationViewSpanningRects : IInspectable
{
Windows.Foundation.Collections.IVectorView<Windows.Foundation.Rect> GetSpanningRects();
}

}
8 changes: 0 additions & 8 deletions dev/dll/SharedHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,6 @@ bool SharedHelpers::IsFrameworkElementInvalidateViewportAvailable()
return s_isFrameworkElementInvalidateViewportAvailable;
}

bool SharedHelpers::IsApplicationViewGetDisplayRegionsAvailable()
{
static bool s_isApplicationViewGetDisplayRegionsAvailable =
Is19H1OrHigher() ||
winrt::ApiInformation::IsMethodPresent(L"Windows.UI.ViewManagement.ApplicationView", L"GetDisplayRegions");
return s_isApplicationViewGetDisplayRegionsAvailable;
}

bool SharedHelpers::IsControlCornerRadiusAvailable()
{
static bool s_isControlCornerRadiusAvailable =
Expand Down
1 change: 0 additions & 1 deletion dev/dll/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ void specialize_guids()
#endif

#ifdef TWOPANEVIEW_INCLUDED
winrt::guid_of<struct winrt::Windows::Foundation::IReference<enum winrt::Microsoft::UI::Xaml::Controls::TreeViewSelectionMode>>();
winrt::guid_of<struct winrt::Windows::Foundation::IReference<enum winrt::Microsoft::UI::Xaml::Controls::TwoPaneViewMode>>();
winrt::guid_of<struct winrt::Windows::Foundation::IReference<enum winrt::Microsoft::UI::Xaml::Controls::TwoPaneViewPriority>>();
winrt::guid_of<struct winrt::Windows::Foundation::IReference<enum winrt::Microsoft::UI::Xaml::Controls::TwoPaneViewTallModeConfiguration>>();
Expand Down
2 changes: 0 additions & 2 deletions dev/inc/SharedHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ class SharedHelpers

static bool IsFrameworkElementInvalidateViewportAvailable();

static bool IsApplicationViewGetDisplayRegionsAvailable();

static bool IsControlCornerRadiusAvailable();

static bool IsTranslationFacadeAvailable(const winrt::UIElement& element);
Expand Down