Skip to content
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
23 changes: 22 additions & 1 deletion src/SwitchifyPc.App/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using SwitchifyPc.Core.Input;
using SwitchifyPc.Core.Pairing;
using SwitchifyPc.Core.Settings;
using SwitchifyPc.Core.SwitchControl;
using SwitchifyPc.Core.AppLifecycle;
using SwitchifyPc.Core.Diagnostics;
using SwitchifyPc.Core.Startup;
Expand Down Expand Up @@ -36,6 +37,7 @@ public partial class App : System.Windows.Application
private WindowsExistingInstanceSignal? existingInstanceSignal;
private NativeTrayIcon? trayIcon;
private SettingsWindow? settingsWindow;
private SwitchControlProfileWindow? switchControlProfileWindow;
private SetupGuideWindow? setupGuideWindow;
private MainWindowViewModel mainWindowViewModel = new();
private SetupGuideViewModel setupGuideViewModel = new();
Expand All @@ -45,6 +47,7 @@ public partial class App : System.Windows.Application
private WindowsBluetoothGattServer? bluetoothServer;
private BluetoothRemoteFrameProcessor? bluetoothFrameProcessor;
private DesktopCommandExecutor? commandExecutor;
private JsonSwitchControlProfileStore? switchControlProfileStore;
private MouseRepeatController? mouseRepeatController;
private WindowsCursorOverlayNotifier? cursorOverlay;
private WindowsModifierKeyOverlayNotifier? modifierOverlay;
Expand Down Expand Up @@ -154,6 +157,7 @@ protected override void OnExit(ExitEventArgs e)
themeManager?.Dispose();
themeManager = null;
commandExecutor = null;
switchControlProfileStore = null;
bluetoothFrameProcessor = null;
bluetoothStatusTracker = null;
pairingApprovalManager = null;
Expand All @@ -164,6 +168,7 @@ protected override void OnExit(ExitEventArgs e)
trayIcon?.Dispose();
trayIcon = null;
settingsWindow = null;
switchControlProfileWindow = null;
setupGuideWindow = null;
telemetryReporter?.Dispose();
telemetryReporter = null;
Expand Down Expand Up @@ -273,7 +278,7 @@ private SetupGuideWindow CreateSetupGuideWindow()

private SettingsWindow CreateSettingsWindow()
{
SettingsWindow window = new(CreateSettingsController());
SettingsWindow window = new(CreateSettingsController(), ShowSwitchControlProfiles);
window.Closing += (_, eventArgs) =>
{
if (isQuitting) return;
Expand All @@ -284,6 +289,22 @@ private SettingsWindow CreateSettingsWindow()
return window;
}

private void ShowSwitchControlProfiles()
{
switchControlProfileStore ??= new JsonSwitchControlProfileStore(
Path.Combine(UserDataDirectory(), "switch-control-profiles.json"));
if (switchControlProfileWindow is null)
{
switchControlProfileWindow = new SwitchControlProfileWindow(
switchControlProfileStore,
() => null);
switchControlProfileWindow.Closed += (_, _) => switchControlProfileWindow = null;
}
switchControlProfileWindow.Owner = settingsWindow;
switchControlProfileWindow.Show();
switchControlProfileWindow.Activate();
}

private static void CenterWindow(Window window)
{
window.Left = SystemParameters.WorkArea.Left + (SystemParameters.WorkArea.Width - window.Width) / 2;
Expand Down
14 changes: 14 additions & 0 deletions src/SwitchifyPc.App/SettingsWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,20 @@
</ItemsControl>
</StackPanel>
</Border>
<Border Margin="0,14,0,0" Style="{StaticResource PanelBorder}">
<StackPanel>
<TextBlock Text="PC Switch Control" Style="{StaticResource SectionTitle}" />
<TextBlock Margin="0,6,0,0"
Text="Map physical switches to Grid 3, keyboard, mouse, scrolling, shortcuts, and media controls."
TextWrapping="Wrap"
Style="{StaticResource MutedText}" />
<Button Margin="0,14,0,0"
HorizontalAlignment="Left"
Content="Manage profiles"
Click="ManageSwitchProfiles_Click"
AutomationProperties.Name="Manage PC Switch Control profiles" />
</StackPanel>
</Border>
</StackPanel>

<StackPanel x:Name="PointerPanel" Visibility="Collapsed">
Expand Down
6 changes: 5 additions & 1 deletion src/SwitchifyPc.App/SettingsWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ public partial class SettingsWindow : Window
private bool isApplyingSettings;
private bool settingsLoaded;
private bool isInstallingUpdate;
private readonly Action? manageSwitchProfiles;

public SettingsWindow(SettingsController controller) : this(controller.ViewModel)
public SettingsWindow(SettingsController controller, Action? manageSwitchProfiles = null) : this(controller.ViewModel)
{
this.controller = controller;
this.manageSwitchProfiles = manageSwitchProfiles;
}

public SettingsWindow(SettingsViewModel? viewModel = null)
Expand Down Expand Up @@ -129,6 +131,8 @@ private void OpenPrivacyPolicy_Click(object sender, RoutedEventArgs e)
}
}

private void ManageSwitchProfiles_Click(object sender, RoutedEventArgs e) => manageSwitchProfiles?.Invoke();

private async void ForgetPairedDevice_Click(object sender, RoutedEventArgs e)
{
if (controller is null || sender is not WpfButton { Tag: string deviceId }) return;
Expand Down
118 changes: 118 additions & 0 deletions src/SwitchifyPc.App/SwitchControlProfileWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<Window x:Class="SwitchifyPc.App.SwitchControlProfileWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="PC Switch Control profiles"
Width="980"
Height="680"
MinWidth="820"
MinHeight="560"
WindowStartupLocation="CenterOwner">
<Grid Margin="20">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<StackPanel>
<TextBlock Text="PC Switch Control" FontSize="24" FontWeight="SemiBold" />
<TextBlock Margin="0,6,0,16"
Text="Create profiles that map up to eight physical switches to Windows input."
TextWrapping="Wrap" />
</StackPanel>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="260" />
<ColumnDefinition Width="18" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<DockPanel>
<TextBlock DockPanel.Dock="Top"
Margin="0,0,0,8"
Text="Profiles"
FontWeight="SemiBold" />
<ListBox x:Name="ProfilesList"
SelectionChanged="ProfilesList_SelectionChanged"
AutomationProperties.Name="Switch control profiles"
DisplayMemberPath="Name" />
</DockPanel>
<ScrollViewer Grid.Column="2" VerticalScrollBarVisibility="Auto">
<StackPanel>
<TextBlock Text="Profile name" FontWeight="SemiBold" />
<TextBox x:Name="ProfileName"
Margin="0,6,0,4"
MaxLength="50"
AutomationProperties.Name="Profile name" />
<TextBlock x:Name="ReadOnlyMessage"
Margin="0,0,0,12"
TextWrapping="Wrap" />
<TextBlock Text="Switch bindings" FontWeight="SemiBold" />
<TextBlock Margin="0,4,0,12"
Text="Choose a suggested value or type one. Each switch row explains the accepted values for its selected action."
TextWrapping="Wrap" />
<ItemsControl x:Name="BindingRows">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid Margin="0,0,0,10">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="90" />
<ColumnDefinition Width="180" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock VerticalAlignment="Center"
Text="{Binding SwitchLabel}"
FontWeight="SemiBold" />
<ComboBox Grid.Column="1"
Margin="0,0,10,0"
ItemsSource="{Binding Types}"
SelectedItem="{Binding SelectedType, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
IsEnabled="{Binding IsEditable}"
AutomationProperties.Name="{Binding TypeAutomationName}" />
<ComboBox x:Name="BindingValueInput"
Grid.Column="2"
ItemsSource="{Binding ValueOptions}"
Text="{Binding Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
IsEditable="True"
IsTextSearchEnabled="True"
IsEnabled="{Binding IsEditable}"
AutomationProperties.Name="{Binding ValueAutomationName}"
AutomationProperties.HelpText="{Binding ValueHelp}" />
<TextBlock Grid.Row="1"
Grid.Column="1"
Grid.ColumnSpan="2"
Margin="0,4,0,0"
Text="{Binding ValueHelp}"
TextWrapping="Wrap"
Foreground="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<TextBlock x:Name="ValidationMessage"
Foreground="DarkRed"
TextWrapping="Wrap"
AutomationProperties.LiveSetting="Assertive" />
</StackPanel>
</ScrollViewer>
</Grid>
<Grid Grid.Row="2" Margin="0,18,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<StackPanel Orientation="Horizontal">
<Button Content="New" MinWidth="84" Click="New_Click" />
<Button Margin="8,0,0,0" Content="Duplicate" MinWidth="84" Click="Duplicate_Click" />
<Button x:Name="DeleteButton" Margin="8,0,0,0" Content="Delete" MinWidth="84" Click="Delete_Click" />
</StackPanel>
<StackPanel Grid.Column="1" Orientation="Horizontal">
<Button x:Name="CancelButton" Content="Cancel changes" MinWidth="110" Click="Cancel_Click" />
<Button x:Name="SaveButton" Margin="8,0,0,0" Content="Save" MinWidth="84" Click="Save_Click" />
<Button Margin="8,0,0,0" Content="Close" MinWidth="84" IsCancel="True" Click="Close_Click" />
</StackPanel>
</Grid>
</Grid>
</Window>
Loading