Skip to content

Commit

Permalink
Added some optimizations for Xbox UI (jenius-apps#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
dpaulino authored Nov 9, 2020
1 parent 116f136 commit 4716ef4
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/AmbientSounds.Uwp/AmbientSounds.Uwp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
<Compile Include="Services\MediaPlayerService.cs" />
<Compile Include="Services\SoundDataProvider.cs" />
<Compile Include="Services\TimerService.cs" />
<Compile Include="StateTriggers\TenFootTrigger.cs" />
<Compile Include="Views\MainPage.xaml.cs">
<DependentUpon>MainPage.xaml</DependentUpon>
</Compile>
Expand Down
10 changes: 10 additions & 0 deletions src/AmbientSounds.Uwp/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System;
using Windows.ApplicationModel.Activation;
using Windows.ApplicationModel.Core;
using Windows.System.Profile;
using Windows.UI;
using Windows.UI.ViewManagement;
using Windows.UI.Xaml;
Expand All @@ -21,6 +22,7 @@ namespace AmbientSounds
/// </summary>
sealed partial class App : Application
{
private static readonly bool _isTenFootPc = false;
private IServiceProvider? _serviceProvider;

/// <summary>
Expand All @@ -29,8 +31,16 @@ sealed partial class App : Application
public App()
{
this.InitializeComponent();

if (IsTenFoot)
{
// Ref: https://docs.microsoft.com/en-us/windows/uwp/xbox-apps/how-to-disable-mouse-mode
this.RequiresPointerMode = ApplicationRequiresPointerMode.WhenRequested;
}
}

public static bool IsTenFoot => AnalyticsInfo.VersionInfo.DeviceFamily == "Windows.Xbox" || _isTenFootPc;

/// <summary>
/// Gets the <see cref="IServiceProvider"/> instance for the current application instance.
/// </summary>
Expand Down
16 changes: 16 additions & 0 deletions src/AmbientSounds.Uwp/StateTriggers/TenFootTrigger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Windows.UI.Xaml;

namespace AmbientSounds.StateTriggers
{
/// <summary>
/// State trigger for whether or not
/// the current device is in ten foot mode.
/// </summary>
public class TenFootTrigger : StateTriggerBase
{
public TenFootTrigger()
{
SetActive(App.IsTenFoot);
}
}
}
30 changes: 22 additions & 8 deletions src/AmbientSounds.Uwp/Views/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
xmlns:statetriggers="using:AmbientSounds.StateTriggers"
xmlns:viewmodels="using:AmbientSounds.ViewModels"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
mc:Ignorable="d">
Expand All @@ -22,18 +23,22 @@

<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="120" />
<RowDefinition Height="auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>

<Grid Background="{ThemeResource SystemControlChromeHighAcrylicElementMediumBrush}" Canvas.ZIndex="1">
<Grid
x:Name="HeaderGrid"
Padding="40,28"
Background="{ThemeResource SystemControlChromeHighAcrylicElementMediumBrush}"
Canvas.ZIndex="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="auto" />
</Grid.ColumnDefinitions>

<controls:PlayerControl Margin="40,0,0,0" />
<controls:PlayerControl />

<controls:LogoControl
x:Name="TitleCentre"
Expand All @@ -42,15 +47,13 @@
VerticalAlignment="Center"
Visibility="Collapsed" />

<StackPanel
Grid.Column="2"
Margin="0,0,40,0"
Orientation="Horizontal">
<controls:MoreButton Margin="4,0,0,0" />
<StackPanel Grid.Column="2" Orientation="Horizontal">
<controls:MoreButton />
</StackPanel>
</Grid>

<ScrollViewer
x:Name="SoundsViewer"
Grid.Row="1"
Padding="40,32,40,0"
CanContentRenderOutsideBounds="True">
Expand Down Expand Up @@ -148,6 +151,17 @@
<Setter Target="TitleCentre.Visibility" Value="Visible" />
</VisualState.Setters>
</VisualState>

<VisualState>
<VisualState.StateTriggers>
<statetriggers:TenFootTrigger />
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="TitleCentre.Visibility" Value="Visible" />
<Setter Target="HeaderGrid.Padding" Value="88,55,88,28" />
<Setter Target="SoundsViewer.Padding" Value="88,32,88,0" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Grid>
Expand Down
7 changes: 7 additions & 0 deletions src/AmbientSounds.Uwp/Views/MainPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using AmbientSounds.ViewModels;
using Microsoft.Extensions.DependencyInjection;
using System.Numerics;
using Windows.UI.ViewManagement;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Hosting;
Expand All @@ -16,6 +17,12 @@ public MainPage()
{
this.InitializeComponent();
this.DataContext = App.Services.GetRequiredService<MainPageViewModel>();

if (App.IsTenFoot)
{
// Ref: https://docs.microsoft.com/en-us/windows/uwp/xbox-apps/turn-off-overscan
ApplicationView.GetForCurrentView().SetDesiredBoundsMode(ApplicationViewBoundsMode.UseCoreWindow);
}
}

public MainPageViewModel ViewModel => (MainPageViewModel)this.DataContext;
Expand Down

0 comments on commit 4716ef4

Please sign in to comment.