Skip to content

Commit

Permalink
Add accelerator keys for MainWindow buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
watfordjc committed Jul 30, 2020
1 parent 866837a commit ce07fa0
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 10 deletions.
8 changes: 4 additions & 4 deletions StreamController/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
<Label Grid.Row="4" Grid.Column="0" x:Name="label_interface_muted" Content="Muted:" Style="{DynamicResource property_label_style}" Visibility="{Binding IsActive, Converter={StaticResource BoolToVisibility}}" />
<TextBlock Grid.Row="4" Grid.Column="1" x:Name="interface_muted" VerticalAlignment="Center" Text="{Binding Muted}" Visibility="{Binding IsActive, Converter={StaticResource BoolToVisibility}}" />
<StackPanel Margin="4 8 4 4" HorizontalAlignment="Left" Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="2" Orientation="Horizontal">
<Button x:Name="btnMakeDefaultRender" Padding="4" Content="Make Default" Visibility="{Binding IsActive, Converter={StaticResource BoolToVisibility}}" Click="BtnMakeDefaultRender_Click" FocusVisualStyle="{DynamicResource {x:Static SystemParameters.FocusVisualStyleKey}}" />
<Button x:Name="btnMakeDefaultRender" Padding="4" Content="Make Default" Visibility="{Binding IsActive, Converter={StaticResource BoolToVisibility}}" Click="BtnMakeDefaultRender_Click" FocusVisualStyle="{DynamicResource {x:Static SystemParameters.FocusVisualStyleKey}}" AutomationProperties.AcceleratorKey="Ctrl+m" />
</StackPanel>
</Grid>
</GroupBox>
Expand Down Expand Up @@ -209,15 +209,15 @@
<Label Grid.Row="4" Grid.Column="0" Content="Capture Device:" Style="{DynamicResource property_label_style}" />
<TextBlock Grid.Row="4" Grid.Column="1" VerticalAlignment="Center" x:Name="app_capture" />
<StackPanel Margin="4 8 4 4" HorizontalAlignment="Left" Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="2" Orientation="Horizontal">
<Button Padding="4" Content="Use Selected Audio Interface" Click="BtnSetApplicationDefault_Click" FocusVisualStyle="{DynamicResource {x:Static SystemParameters.FocusVisualStyleKey}}" />
<Button Padding="4" Content="Use Selected Audio Interface" Click="BtnSetApplicationDefault_Click" FocusVisualStyle="{DynamicResource {x:Static SystemParameters.FocusVisualStyleKey}}" AutomationProperties.AcceleratorKey="Ctrl+u" />
</StackPanel>
</Grid>
</GroupBox>
<GroupBox Header="Custom Audio Interfaces" Margin="8" Padding="8">
<StackPanel Orientation="Horizontal">
<StackPanel Orientation="Vertical">
<Button Margin="8" Padding="4" Content="Reset for All Applications" Click="BtnResetAllApplicationDefault_Click" FocusVisualStyle="{DynamicResource {x:Static SystemParameters.FocusVisualStyleKey}}" />
<Button Margin="8" Padding="4" Content="Toggle for All Applications" Click="BtnToggleAllApplicationDefault_Click" FocusVisualStyle="{DynamicResource {x:Static SystemParameters.FocusVisualStyleKey}}" />
<Button Margin="8" Padding="4" Content="Reset for All Applications" Click="BtnResetAllApplicationDefault_Click" FocusVisualStyle="{DynamicResource {x:Static SystemParameters.FocusVisualStyleKey}}" AutomationProperties.AcceleratorKey="Ctrl+F5" />
<Button Margin="8" Padding="4" Content="Toggle for All Applications" Click="BtnToggleAllApplicationDefault_Click" FocusVisualStyle="{DynamicResource {x:Static SystemParameters.FocusVisualStyleKey}}" AutomationProperties.AcceleratorKey="Ctrl+t" />
</StackPanel>
</StackPanel>
</GroupBox>
Expand Down
60 changes: 54 additions & 6 deletions StreamController/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,35 +101,55 @@ private void OnDefaultDeviceChanged(object sender, DataFlow flow)
}
}

private void BtnMakeDefaultRender_Click(object sender, RoutedEventArgs e)
private void MakeInterfaceDefaultRenderDevice()
{
AudioInterfaceCollection.ChangeDefaultDevice((cb_interfaces.SelectedItem as AudioInterface).ID);
}

private void BtnSetApplicationDefault_Click(object sender, RoutedEventArgs e)
private void SetApplicationDefaultDevice()
{
ObservableProcess process = (cb_applications.SelectedItem as ObservableProcess);
AudioInterface currentInterface = (cb_interfaces.SelectedItem as AudioInterface);
AudioInterfaceCollection.ChangeDefaultApplicationDevice(currentInterface, process);
UpdateApplicationAudioDevices(process);
}

private void BtnResetAllApplicationDefault_Click(object sender, RoutedEventArgs e)
private void ResetCustomAudioDevices()
{
AudioInterfaceCollection.ClearAllApplicationDefaultDevices(DataFlow.All);
UpdateApplicationAudioDevices(cb_applications.SelectedItem as ObservableProcess);
}

private async void BtnToggleAllApplicationDefault_Click(object sender, RoutedEventArgs e)
private static async Task ToggleAllCustomAudioDevices()
{
(e.OriginalSource as Button).IsEnabled = false;
await Task.Run(
() => AudioInterfaceCollection.ToggleAllDefaultApplicationDevice()
).ConfigureAwait(true);
}

private void BtnMakeDefaultRender_Click(object sender, RoutedEventArgs e)
{
MakeInterfaceDefaultRenderDevice();
}

private void BtnSetApplicationDefault_Click(object sender, RoutedEventArgs e)
{
SetApplicationDefaultDevice();
}

private void BtnResetAllApplicationDefault_Click(object sender, RoutedEventArgs e)
{
ResetCustomAudioDevices();
}

private async void BtnToggleAllApplicationDefault_Click(object sender, RoutedEventArgs e)
{
(e.OriginalSource as Button).IsEnabled = false;
await ToggleAllCustomAudioDevices().ConfigureAwait(true);
(e.OriginalSource as Button).IsEnabled = true;
}

private void Window_KeyDown(object sender, KeyEventArgs e)
private async void Window_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.F4)
{
Expand All @@ -139,6 +159,34 @@ private void Window_KeyDown(object sender, KeyEventArgs e)
App.Current.Shutdown();
}
}
else if (e.Key == Key.F5)
{
if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
{
ResetCustomAudioDevices();
}
}
else if (e.Key == Key.M)
{
if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
{
MakeInterfaceDefaultRenderDevice();
}
}
else if (e.Key == Key.T)
{
if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
{
await ToggleAllCustomAudioDevices().ConfigureAwait(true);
}
}
else if (e.Key == Key.U)
{
if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
{
SetApplicationDefaultDevice();
}
}
}
}
}

0 comments on commit ce07fa0

Please sign in to comment.