Skip to content

Commit

Permalink
Update TwoPaneView for API changes (#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
teaP committed Jan 18, 2019
1 parent 39c5777 commit 042a332
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 32 deletions.
2 changes: 1 addition & 1 deletion SdkVersion.props
Expand Up @@ -6,7 +6,7 @@
<SDKVersionRS3>10.0.16299.0</SDKVersionRS3>
<SDKVersionRS4>10.0.17134.0</SDKVersionRS4>
<SDKVersionRS5>10.0.17763.0</SDKVersionRS5>
<SDKVersion19H1Insider>10.0.18283.0</SDKVersion19H1Insider>
<SDKVersion19H1Insider>10.0.18312.0</SDKVersion19H1Insider>
</PropertyGroup>
<PropertyGroup>
<!-- By default we use the publicly shipped SDK version which is RS5 now -->
Expand Down
49 changes: 23 additions & 26 deletions dev/TwoPaneView/DisplayRegionHelper.cpp
Expand Up @@ -49,42 +49,39 @@ DisplayRegionHelperInfo DisplayRegionHelper::GetRegionInfo()
}
}
#ifdef USE_INSIDER_SDK
else if (SharedHelpers::IsDisplayRegionGetForCurrentViewAvailable())
else if (SharedHelpers::IsApplicationViewGetDisplayRegionsAvailable())
{
// TODO: remove try/catch after bug 14084372 is fixed. These APIs currently throw on failure.
winrt::WindowingEnvironment environment{ nullptr };
// ApplicationView::GetForCurrentView throws on failure; in that case we just won't do anything.
winrt::ApplicationView view{ nullptr };
try
{
environment = winrt::Windows::UI::ViewManagement::ApplicationView::GetForCurrentView().WindowingEnvironment();
view = winrt::ApplicationView::GetForCurrentView();
} catch(...) {}

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

// More than one region
if (info.RegionCount == 2)
{
winrt::IVectorView<winrt::Windows::UI::WindowManagement::DisplayRegion> regions = winrt::Windows::UI::ViewManagement::ApplicationView::GetForCurrentView().GetDisplayRegions();
info.RegionCount = std::min(regions.Size(), c_maxRegions);
winrt::Rect windowRect = WindowRect();

// More than one region
if (info.RegionCount == 2)
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
{
winrt::Rect windowRect = WindowRect();

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
{
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.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 };
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions dev/dll/SharedHelpers.cpp
Expand Up @@ -161,12 +161,12 @@ bool SharedHelpers::IsFrameworkElementInvalidateViewportAvailable()
return s_isFrameworkElementInvalidateViewportAvailable;
}

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

bool SharedHelpers::IsTranslationFacadeAvailable(const winrt::UIElement& element)
Expand Down
2 changes: 1 addition & 1 deletion dev/inc/SharedHelpers.h
Expand Up @@ -43,7 +43,7 @@ class SharedHelpers

static bool IsFrameworkElementInvalidateViewportAvailable();

static bool IsDisplayRegionGetForCurrentViewAvailable();
static bool IsApplicationViewGetDisplayRegionsAvailable();

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

Expand Down

0 comments on commit 042a332

Please sign in to comment.