Skip to content

Commit

Permalink
- add, about Projection Window, full screen as a feature
Browse files Browse the repository at this point in the history
- add, about Projection Window, always on top feature
- refactor
  • Loading branch information
louangr committed Dec 18, 2022
1 parent 77f5c94 commit fced749
Show file tree
Hide file tree
Showing 11 changed files with 293 additions and 24 deletions.
33 changes: 14 additions & 19 deletions MediaSharer/MediaSharer/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
using System;
using MediaSharer.Core;
using MediaSharer.Repositories.Interfaces;
using MediaSharer.Strings;
using MediaSharer.Utils;
using MediaSharer.Views;
using MediaSharer.Windows;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.UI.Windowing;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Media.Animation;
using WinRT;
using WinUIEx;

namespace MediaSharer
{
public sealed partial class MainWindow : Window
{
private readonly string ICON_FILE_NAME = "icon.ico";

private ProjectionWindow projectionWindow;
private ISettingsRepository settingsRepository;

public MainWindow()
{
InitializeComponent();
LoadIcon("icon.ico");

settingsRepository = App.Current.Services.GetService<ISettingsRepository>();

WinApi.LoadIcon(this, ICON_FILE_NAME);
Navigate(typeof(DashboardPage));
RenderProjectionWindow();

Expand Down Expand Up @@ -50,25 +57,13 @@ private void RenderProjectionWindow()
{
projectionWindow = new ProjectionWindow();
projectionWindow.Title = LocalizedStrings.GetString("AppName");

SetProjectionWindowPosition(projectionWindow.As<IWindowNative>().WindowHandle);
projectionWindow.SetWindowPresenter(AppWindowPresenterKind.FullScreen);
projectionWindow.SetPosition();
WinApi.LoadIcon(projectionWindow, ICON_FILE_NAME);
projectionWindow.Maximize();
if (settingsRepository.IsProjectionWindowFullScreenEnabled) projectionWindow.SetWindowPresenter(AppWindowPresenterKind.FullScreen);
projectionWindow.Activate();
}

private void SetProjectionWindowPosition(IntPtr hwnd)
{
var xPosition = DisplayArea.Primary.WorkArea.Width;
PInvoke.User32.SetWindowPos(hwnd, PInvoke.User32.SpecialWindowHandles.HWND_TOP, xPosition, 0, 0, 0, PInvoke.User32.SetWindowPosFlags.SWP_NOSIZE);
}

private void LoadIcon(string iconName)
{
var hwnd = this.As<IWindowNative>().WindowHandle;
IntPtr hIcon = PInvoke.User32.LoadImage(IntPtr.Zero, iconName, PInvoke.User32.ImageType.IMAGE_ICON, 16, 16, PInvoke.User32.LoadImageFlags.LR_LOADFROMFILE);
PInvoke.User32.SendMessage(hwnd, PInvoke.User32.WindowMessage.WM_SETICON, (IntPtr)0, hIcon);
}

#endregion Private methods
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ public bool AutoPlay
set => TrySetLocalValue(nameof(AutoPlay), value);
}

public bool IsProjectionWindowFullScreenEnabled
{
get => TryGetLocalValue(nameof(IsProjectionWindowFullScreenEnabled), false);
set => TrySetLocalValue(nameof(IsProjectionWindowFullScreenEnabled), value);
}

public bool IsProjectionWindowAlwaysOnTopWhenSharing
{
get => TryGetLocalValue(nameof(IsProjectionWindowAlwaysOnTopWhenSharing), true);
set => TrySetLocalValue(nameof(IsProjectionWindowAlwaysOnTopWhenSharing), value);
}

#endregion Publics Properties

#region Private Methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@
public interface ISettingsRepository
{
bool AutoPlay { get; set; }

bool IsProjectionWindowFullScreenEnabled { get; set; }

bool IsProjectionWindowAlwaysOnTopWhenSharing { get; set; }
}
}
36 changes: 36 additions & 0 deletions MediaSharer/MediaSharer/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@
<data name="DefaultToggleSwitch.OnContent" xml:space="preserve">
<value>On</value>
</data>
<data name="SettingsPage_AlwaysOnTopLabel.Text" xml:space="preserve">
<value>Always on top</value>
</data>
<data name="SettingsPage_AlwaysOnTopSublabel.Text" xml:space="preserve">
<value>Allow to put the projection screen in the front when sharing</value>
</data>
<data name="SettingsPage_AutoPlayLabel.Text" xml:space="preserve">
<value>AutoPlay</value>
</data>
Expand All @@ -141,6 +147,36 @@
<data name="SettingsPage_ExternalPlayerControlsLabel.Text" xml:space="preserve">
<value>External player controls</value>
</data>
<data name="SettingsPage_FullScreenLabel.Text" xml:space="preserve">
<value>Full screen</value>
</data>
<data name="SettingsPage_FullScreenSublabel.Text" xml:space="preserve">
<value>Allow to put the projection screen in full screen</value>
</data>
<data name="SettingsPage_PlayerLabel.Text" xml:space="preserve">
<value>Player</value>
</data>
<data name="SettingsPage_ProjectionWindowInfoLabel1.Text" xml:space="preserve">
<value>If both are needed, a workaround is to enable</value>
</data>
<data name="SettingsPage_ProjectionWindowInfoLabel2.Text" xml:space="preserve">
<value>Always on top</value>
</data>
<data name="SettingsPage_ProjectionWindowInfoLabel3.Text" xml:space="preserve">
<value>and in the</value>
</data>
<data name="SettingsPage_ProjectionWindowInfoLabel4.Text" xml:space="preserve">
<value>Taskbar</value>
</data>
<data name="SettingsPage_ProjectionWindowInfoLabel5.Text" xml:space="preserve">
<value>section of the Settings, disable</value>
</data>
<data name="SettingsPage_ProjectionWindowInfoLabel6.Text" xml:space="preserve">
<value>Show my taskbar on all screens</value>
</data>
<data name="SettingsPage_ProjectionWindowLabel.Text" xml:space="preserve">
<value>Projection screen</value>
</data>
<data name="SettingsPage_TitleTextBlock.Text" xml:space="preserve">
<value>Settings</value>
</data>
Expand Down
36 changes: 36 additions & 0 deletions MediaSharer/MediaSharer/Strings/fr-FR/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@
<data name="DefaultToggleSwitch.OnContent" xml:space="preserve">
<value>Activé</value>
</data>
<data name="SettingsPage_AlwaysOnTopLabel.Text" xml:space="preserve">
<value>Toujours au premier plan</value>
</data>
<data name="SettingsPage_AlwaysOnTopSublabel.Text" xml:space="preserve">
<value>Permet de mettre au premier plan l'écran de projection lors d'un partage</value>
</data>
<data name="SettingsPage_AutoPlayLabel.Text" xml:space="preserve">
<value>AutoPlay</value>
</data>
Expand All @@ -141,6 +147,36 @@
<data name="SettingsPage_ExternalPlayerControlsLabel.Text" xml:space="preserve">
<value>Commandes du player externe</value>
</data>
<data name="SettingsPage_FullScreenLabel.Text" xml:space="preserve">
<value>Plein écran</value>
</data>
<data name="SettingsPage_FullScreenSublabel.Text" xml:space="preserve">
<value>Permet de mettre l'écran de projection en plein écran</value>
</data>
<data name="SettingsPage_PlayerLabel.Text" xml:space="preserve">
<value>Player multimédia</value>
</data>
<data name="SettingsPage_ProjectionWindowInfoLabel1.Text" xml:space="preserve">
<value>Si les deux sont nécessaires, une solution de contournement consiste à activer</value>
</data>
<data name="SettingsPage_ProjectionWindowInfoLabel2.Text" xml:space="preserve">
<value>Toujours au premier plan</value>
</data>
<data name="SettingsPage_ProjectionWindowInfoLabel3.Text" xml:space="preserve">
<value>et dans la section</value>
</data>
<data name="SettingsPage_ProjectionWindowInfoLabel4.Text" xml:space="preserve">
<value>Barre des tâches</value>
</data>
<data name="SettingsPage_ProjectionWindowInfoLabel5.Text" xml:space="preserve">
<value>des Paramètres, désactiver</value>
</data>
<data name="SettingsPage_ProjectionWindowInfoLabel6.Text" xml:space="preserve">
<value>Afficher ma barre des tâches sur tous les affichages</value>
</data>
<data name="SettingsPage_ProjectionWindowLabel.Text" xml:space="preserve">
<value>Écran de projection</value>
</data>
<data name="SettingsPage_TitleTextBlock.Text" xml:space="preserve">
<value>Paramètres</value>
</data>
Expand Down
17 changes: 17 additions & 0 deletions MediaSharer/MediaSharer/Utils/WinApi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using MediaSharer.Core;
using Microsoft.UI.Xaml;
using System;
using WinRT;

namespace MediaSharer.Utils
{
public static class WinApi
{
public static void LoadIcon(Window window, string iconName)
{
var hwnd = window.As<IWindowNative>().WindowHandle;
IntPtr hIcon = PInvoke.User32.LoadImage(IntPtr.Zero, iconName, PInvoke.User32.ImageType.IMAGE_ICON, 16, 16, PInvoke.User32.LoadImageFlags.LR_LOADFROMFILE);
PInvoke.User32.SendMessage(hwnd, PInvoke.User32.WindowMessage.WM_SETICON, (IntPtr)0, hIcon);
}
}
}
90 changes: 89 additions & 1 deletion MediaSharer/MediaSharer/Views/SettingsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<Expander HorizontalAlignment="Stretch"
HorizontalContentAlignment="Stretch">
<Expander.Header>
<TextBlock x:Uid="SettingsPage_AutoPlayLabel"
<TextBlock x:Uid="SettingsPage_PlayerLabel"
FontSize="16" />
</Expander.Header>

Expand Down Expand Up @@ -92,6 +92,94 @@
Foreground="{StaticResource SettingSublabelColorBrush}" />
</Grid>
</Expander>

<Expander Grid.Row="2"
HorizontalAlignment="Stretch"
HorizontalContentAlignment="Stretch">
<Expander.Header>
<TextBlock x:Uid="SettingsPage_ProjectionWindowLabel"
FontSize="16" />
</Expander.Header>

<Grid HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200" />
<ColumnDefinition Width="72" />
<ColumnDefinition />
</Grid.ColumnDefinitions>

<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="24" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>

<Button Grid.Column="2"
Background="Transparent"
Padding="0"
BorderThickness="0"
HorizontalAlignment="Right"
VerticalAlignment="Top">
<Button.Flyout>
<Flyout>
<StackPanel Width="300">
<TextBlock TextWrapping="Wrap">
<Run x:Uid="SettingsPage_ProjectionWindowInfoLabel1" />
<Run x:Uid="SettingsPage_ProjectionWindowInfoLabel2"
FontStyle="Italic" />
<Run x:Uid="SettingsPage_ProjectionWindowInfoLabel3" />
<Hyperlink Click="ProjectionWindowInfoLabelHyperlinkClick">
<Run x:Uid="SettingsPage_ProjectionWindowInfoLabel4" />
</Hyperlink>
<Run x:Uid="SettingsPage_ProjectionWindowInfoLabel5" />
<Run x:Uid="SettingsPage_ProjectionWindowInfoLabel6"
FontStyle="Italic" />
</TextBlock>
</StackPanel>
</Flyout>
</Button.Flyout>

<FontIcon FontFamily="{StaticResource SymbolThemeFontFamily}"
Margin="2,2,0,0"
Glyph="&#xE946;"
FontSize="20" />
</Button>

<TextBlock x:Uid="SettingsPage_FullScreenLabel"
HorizontalAlignment="Right"
VerticalAlignment="Center"
FontSize="16" />

<ToggleSwitch x:Uid="DefaultToggleSwitch"
Grid.Column="2"
IsOn="{x:Bind PageViewModel.IsProjectionWindowFullScreenEnabled, Mode=TwoWay}" />

<TextBlock x:Uid="SettingsPage_FullScreenSublabel"
Grid.Row="1"
TextWrapping="Wrap"
TextAlignment="Right"
Foreground="{StaticResource SettingSublabelColorBrush}" />

<TextBlock x:Uid="SettingsPage_AlwaysOnTopLabel"
HorizontalAlignment="Right"
VerticalAlignment="Center"
FontSize="16"
Grid.Row="3" />

<ToggleSwitch x:Uid="DefaultToggleSwitch"
Grid.Column="2"
Grid.Row="3"
IsOn="{x:Bind PageViewModel.IsProjectionWindowAlwaysOnTopWhenSharing, Mode=TwoWay}" />

<TextBlock x:Uid="SettingsPage_AlwaysOnTopSublabel"
Grid.Row="4"
TextWrapping="Wrap"
TextAlignment="Right"
Foreground="{StaticResource SettingSublabelColorBrush}" />
</Grid>
</Expander>
</Grid>
</ScrollViewer>

Expand Down
11 changes: 10 additions & 1 deletion MediaSharer/MediaSharer/Views/SettingsPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using MediaSharer.Core;
using System;
using MediaSharer.Core;
using Microsoft.UI.Xaml.Documents;
using Windows.System;

namespace MediaSharer.Views
{
Expand All @@ -16,5 +19,11 @@ public SettingsPageViewModel PageViewModel
=> DataContext as SettingsPageViewModel;

#endregion Properties

#region Private methods

private async void ProjectionWindowInfoLabelHyperlinkClick(Hyperlink sender, HyperlinkClickEventArgs args) => await Launcher.LaunchUriAsync(new Uri("ms-settings:taskbar"));

#endregion Private methods
}
}
30 changes: 30 additions & 0 deletions MediaSharer/MediaSharer/Views/SettingsPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,36 @@ public bool AutoPlay
}
}

public bool IsProjectionWindowFullScreenEnabled
{
get => settingsRepository.IsProjectionWindowFullScreenEnabled;
set
{
if (value)
{
settingsRepository.IsProjectionWindowAlwaysOnTopWhenSharing = false;
OnPropertyChanged(nameof(IsProjectionWindowAlwaysOnTopWhenSharing));
}

settingsRepository.IsProjectionWindowFullScreenEnabled = value;
}
}

public bool IsProjectionWindowAlwaysOnTopWhenSharing
{
get => settingsRepository.IsProjectionWindowAlwaysOnTopWhenSharing;
set
{
if (value)
{
settingsRepository.IsProjectionWindowFullScreenEnabled = false;
OnPropertyChanged(nameof(IsProjectionWindowFullScreenEnabled));
}

settingsRepository.IsProjectionWindowAlwaysOnTopWhenSharing = value;
}
}

public RelayCommand GoBackCommand
=> goBackCommand ?? (goBackCommand = new RelayCommand(() => GoBack()));

Expand Down
5 changes: 4 additions & 1 deletion MediaSharer/MediaSharer/Windows/ProjectionWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<Grid Background="#000000"
<Grid Background="Black"
DoubleTapped="GridContainerDoubleTapped">
<Border x:Name="titleBar"
VerticalAlignment="Top" />

<Image x:Name="imageElement"
Stretch="Uniform"
Visibility="Collapsed" />
Expand Down
Loading

0 comments on commit fced749

Please sign in to comment.