Skip to content

Commit 042a332

Browse files
authored
Update TwoPaneView for API changes (#193)
1 parent 39c5777 commit 042a332

File tree

4 files changed

+29
-32
lines changed

4 files changed

+29
-32
lines changed

SdkVersion.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<SDKVersionRS3>10.0.16299.0</SDKVersionRS3>
77
<SDKVersionRS4>10.0.17134.0</SDKVersionRS4>
88
<SDKVersionRS5>10.0.17763.0</SDKVersionRS5>
9-
<SDKVersion19H1Insider>10.0.18283.0</SDKVersion19H1Insider>
9+
<SDKVersion19H1Insider>10.0.18312.0</SDKVersion19H1Insider>
1010
</PropertyGroup>
1111
<PropertyGroup>
1212
<!-- By default we use the publicly shipped SDK version which is RS5 now -->

dev/TwoPaneView/DisplayRegionHelper.cpp

+23-26
Original file line numberDiff line numberDiff line change
@@ -49,42 +49,39 @@ DisplayRegionHelperInfo DisplayRegionHelper::GetRegionInfo()
4949
}
5050
}
5151
#ifdef USE_INSIDER_SDK
52-
else if (SharedHelpers::IsDisplayRegionGetForCurrentViewAvailable())
52+
else if (SharedHelpers::IsApplicationViewGetDisplayRegionsAvailable())
5353
{
54-
// TODO: remove try/catch after bug 14084372 is fixed. These APIs currently throw on failure.
55-
winrt::WindowingEnvironment environment{ nullptr };
54+
// ApplicationView::GetForCurrentView throws on failure; in that case we just won't do anything.
55+
winrt::ApplicationView view{ nullptr };
5656
try
5757
{
58-
environment = winrt::Windows::UI::ViewManagement::ApplicationView::GetForCurrentView().WindowingEnvironment();
58+
view = winrt::ApplicationView::GetForCurrentView();
5959
} catch(...) {}
6060

6161
// Verify that the window is Tiled
62-
if (environment)
62+
if (view)
6363
{
64-
if (environment.Kind() == winrt::WindowingEnvironmentKind::Tiled)
64+
auto regions = view.GetDisplayRegions();
65+
info.RegionCount = std::min(regions.Size(), c_maxRegions);
66+
67+
// More than one region
68+
if (info.RegionCount == 2)
6569
{
66-
winrt::IVectorView<winrt::Windows::UI::WindowManagement::DisplayRegion> regions = winrt::Windows::UI::ViewManagement::ApplicationView::GetForCurrentView().GetDisplayRegions();
67-
info.RegionCount = std::min(regions.Size(), c_maxRegions);
70+
winrt::Rect windowRect = WindowRect();
6871

69-
// More than one region
70-
if (info.RegionCount == 2)
72+
if (windowRect.Width > windowRect.Height)
73+
{
74+
info.Mode = winrt::TwoPaneViewMode::Wide;
75+
float width = windowRect.Width / 2;
76+
info.Regions[0] = { 0, 0, width, windowRect.Height };
77+
info.Regions[1] = { width, 0, width, windowRect.Height };
78+
}
79+
else
7180
{
72-
winrt::Rect windowRect = WindowRect();
73-
74-
if (windowRect.Width > windowRect.Height)
75-
{
76-
info.Mode = winrt::TwoPaneViewMode::Wide;
77-
float width = windowRect.Width / 2;
78-
info.Regions[0] = { 0, 0, width, windowRect.Height };
79-
info.Regions[1] = { width, 0, width, windowRect.Height };
80-
}
81-
else
82-
{
83-
info.Mode = winrt::TwoPaneViewMode::Tall;
84-
float height = windowRect.Height / 2;
85-
info.Regions[0] = { 0, 0, windowRect.Width, height };
86-
info.Regions[1] = { 0, height, windowRect.Width, height };
87-
}
81+
info.Mode = winrt::TwoPaneViewMode::Tall;
82+
float height = windowRect.Height / 2;
83+
info.Regions[0] = { 0, 0, windowRect.Width, height };
84+
info.Regions[1] = { 0, height, windowRect.Width, height };
8885
}
8986
}
9087
}

dev/dll/SharedHelpers.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,12 @@ bool SharedHelpers::IsFrameworkElementInvalidateViewportAvailable()
161161
return s_isFrameworkElementInvalidateViewportAvailable;
162162
}
163163

164-
bool SharedHelpers::IsDisplayRegionGetForCurrentViewAvailable()
164+
bool SharedHelpers::IsApplicationViewGetDisplayRegionsAvailable()
165165
{
166-
static bool s_isDisplayRegionGetForCurrentViewAvailable =
166+
static bool s_isApplicationViewGetDisplayRegionsAvailable =
167167
Is19H1OrHigher() ||
168-
winrt::ApiInformation::IsMethodPresent(L"Windows.ApplicationModel.Core.DisplayRegion", L"GetForCurrentView");
169-
return s_isDisplayRegionGetForCurrentViewAvailable;
168+
winrt::ApiInformation::IsMethodPresent(L"Windows.UI.ViewManagement.ApplicationView", L"GetDisplayRegions");
169+
return s_isApplicationViewGetDisplayRegionsAvailable;
170170
}
171171

172172
bool SharedHelpers::IsTranslationFacadeAvailable(const winrt::UIElement& element)

dev/inc/SharedHelpers.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class SharedHelpers
4343

4444
static bool IsFrameworkElementInvalidateViewportAvailable();
4545

46-
static bool IsDisplayRegionGetForCurrentViewAvailable();
46+
static bool IsApplicationViewGetDisplayRegionsAvailable();
4747

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

0 commit comments

Comments
 (0)