Skip to content

Commit 4b0bbd8

Browse files
authored
Merge pull request #1201 from unchihugo/feat/update-session-control
Add session switcher functionality to taskbar widget context menu Update media flyout layout (slightly increase size of cover image, and width when media session is enabled) Update media flyout session switcher UI to use SplitButton; remove right click functionality
2 parents cf59555 + 72f0461 commit 4b0bbd8

6 files changed

Lines changed: 120 additions & 63 deletions

File tree

‎FluentFlyoutWPF/Controls/TaskbarWidgetControl.xaml‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@
7979
</Grid>
8080
</Border>
8181
<Grid.ContextMenu>
82-
<ContextMenu Style="{StaticResource UiContextMenu}">
82+
<ContextMenu Style="{StaticResource UiContextMenu}" Opened="TaskbarContextMenu_Opened">
83+
<ui:MenuItem x:Name="ContextMenuSessionSwitcher" Header="Switch sessions">
84+
<ui:MenuItem Header="{DynamicResource ContextMenuSessionSwitcher}" IsEnabled="False" />
85+
</ui:MenuItem>
8386
<ui:MenuItem x:Name="ContextMenuMediaPlayer" Header="{DynamicResource OpenMediaPlayerText}" Click="ContextMenuMediaPlayer_Click">
8487
<ui:MenuItem.Icon>
8588
<ui:SymbolIcon Symbol="Open20"/>

‎FluentFlyoutWPF/Controls/TaskbarWidgetControl.xaml.cs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,11 @@ private async void ContextMenuMediaPlayer_Click(object sender, RoutedEventArgs e
734734
_ = _mainWindow.TryOpenMediaPlayerAsync();
735735
}
736736

737+
private void TaskbarContextMenu_Opened(object sender, RoutedEventArgs e)
738+
{
739+
_mainWindow?.PopulateSessionSwitcherMenu(ContextMenuSessionSwitcher);
740+
}
741+
737742
private void ContextMenuSettings_Click(object sender, RoutedEventArgs e)
738743
{
739744
SettingsWindow.ShowInstance();

‎FluentFlyoutWPF/MainWindow.SessionSwitcher.cs‎

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using FluentFlyout.Classes.Settings;
55
using FluentFlyout.Classes.Utils;
66
using System.Windows;
7-
using System.Windows.Input;
87
using System.Windows.Media;
98
using Windows.Media.Control;
109
using static WindowsMediaController.MediaManager;
@@ -24,26 +23,30 @@ public void PinSession(string? sessionId)
2423
RefreshFilteredMedia();
2524
}
2625

27-
private void MediaIdButton_RightClick(object sender, MouseButtonEventArgs e)
26+
private void ShowSessionSwitcherMenu()
2827
{
29-
if (!SettingsManager.Current.PlayerInfoEnabled || SettingsManager.Current.CompactLayout) return;
30-
e.Handled = true;
28+
var menu = new System.Windows.Controls.ContextMenu
29+
{
30+
PlacementTarget = MediaIdButton,
31+
Placement = System.Windows.Controls.Primitives.PlacementMode.Top
32+
};
3133

32-
ShowSessionSwitcherMenu();
34+
PopulateSessionSwitcherMenu(menu);
35+
menu.IsOpen = true;
3336
}
3437

35-
private void ShowSessionSwitcherMenu()
38+
internal void PopulateSessionSwitcherMenu(System.Windows.Controls.ItemsControl menu)
3639
{
3740
var sessions = GetSwitchableSessions();
38-
3941
string pinnedId = SettingsManager.Current.PinnedSessionId;
4042
string autoText = TryFindResource("SessionSwitcherAuto") as string ?? string.Empty;
4143

42-
var menu = new System.Windows.Controls.ContextMenu
44+
// Clear existing items and events
45+
foreach (var item in menu.Items.OfType<System.Windows.Controls.MenuItem>())
4346
{
44-
PlacementTarget = MediaIdButton,
45-
Placement = System.Windows.Controls.Primitives.PlacementMode.Top
46-
};
47+
item.Click -= SessionMenuItem_Click;
48+
}
49+
menu.Items.Clear();
4750

4851
var autoItem = new System.Windows.Controls.MenuItem
4952
{
@@ -102,8 +105,6 @@ private void ShowSessionSwitcherMenu()
102105
item.Click += SessionMenuItem_Click;
103106
menu.Items.Add(item);
104107
}
105-
106-
menu.IsOpen = true;
107108
}
108109

109110
private void SessionMenuItem_Click(object sender, RoutedEventArgs e)

‎FluentFlyoutWPF/MainWindow.xaml‎

Lines changed: 86 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,41 @@
1919
d:DataContext="{d:DesignInstance viewModels:UserSettings}"
2020
>
2121
<controls:MicaWindow.Resources>
22+
<Style x:Key="DefaultSplitButtonToggleButtonStyle" TargetType="{x:Type ToggleButton}">
23+
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
24+
<Setter Property="Foreground" Value="{DynamicResource ButtonForeground}" />
25+
<Setter Property="Background" Value="Transparent" />
26+
<Setter Property="BorderBrush" Value="Transparent" />
27+
<Setter Property="BorderThickness" Value="0" />
28+
<Setter Property="Border.CornerRadius" Value="0" />
29+
<Setter Property="Padding" Value="4,0" />
30+
<Setter Property="SnapsToDevicePixels" Value="True" />
31+
<Setter Property="OverridesDefaultStyle" Value="True" />
32+
<Setter Property="Template">
33+
<Setter.Value>
34+
<ControlTemplate TargetType="{x:Type ToggleButton}">
35+
<Border
36+
x:Name="ContentBorder"
37+
Padding="{TemplateBinding Padding}"
38+
Background="{TemplateBinding Background}"
39+
BorderBrush="{TemplateBinding BorderBrush}"
40+
BorderThickness="{TemplateBinding BorderThickness}"
41+
CornerRadius="{TemplateBinding Border.CornerRadius}">
42+
<ContentPresenter
43+
x:Name="PART_ContentHost"
44+
Content="{TemplateBinding Content}"
45+
ContentTemplate="{TemplateBinding ContentTemplate}"
46+
ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}"
47+
RenderTransformOrigin="0.5,0.5">
48+
<ContentPresenter.RenderTransform>
49+
<RotateTransform Angle="-90" />
50+
</ContentPresenter.RenderTransform>
51+
</ContentPresenter>
52+
</Border>
53+
</ControlTemplate>
54+
</Setter.Value>
55+
</Setter>
56+
</Style>
2257
<!--
2358
Same appearance as MicaWPF.Styles.AccentedButton, but the hover/pressed states dim the accent
2459
color instead of animating it to the system accent shade, so the album art accent color
@@ -136,79 +171,85 @@
136171
<RowDefinition Height="Auto"/>
137172
<RowDefinition Height="Auto"/>
138173
</Grid.RowDefinitions>
139-
<StackPanel Grid.Row="0" Margin="12" Orientation="Horizontal">
140-
<Border Name="SongImageBorder" CornerRadius="6" BorderThickness="1" BorderBrush="#26FFFFFF" Margin="0" ClipToBounds="True" Width="78" Height="78">
141-
<ui:SymbolIcon Name="SongImagePlaceholder" Symbol="MusicNote220" FontSize="40" Filled="True" Foreground="{DynamicResource MicaWPF.Brushes.SystemAccentColorSecondary}" Visibility="Collapsed" />
142-
<Border.Background>
143-
<ImageBrush x:Name="SongImage" Stretch="UniformToFill"/>
144-
</Border.Background>
145-
</Border>
146-
<StackPanel Name="BodyStackPanel" Orientation="Vertical" VerticalAlignment="Center" Width="194">
147-
<StackPanel Orientation="Horizontal">
148-
<StackPanel Name="SongInfoStackPanel" Margin="12,0,0,0" Orientation="Vertical" VerticalAlignment="Center" Width="182"
174+
<StackPanel Grid.Row="0" Margin="10" Orientation="Horizontal">
175+
<Border Name="SongImageBorder" CornerRadius="4" Margin="0" ClipToBounds="True" Width="82" Height="82">
176+
<ui:SymbolIcon Name="SongImagePlaceholder" Symbol="MusicNote220" FontSize="40" Filled="True" Foreground="{DynamicResource MicaWPF.Brushes.SystemAccentColorSecondary}" Visibility="Collapsed" />
177+
<Border.Background>
178+
<ImageBrush x:Name="SongImage" Stretch="UniformToFill"/>
179+
</Border.Background>
180+
</Border>
181+
<StackPanel Name="BodyStackPanel" Orientation="Vertical" VerticalAlignment="Center" Width="194">
182+
<StackPanel Orientation="Horizontal">
183+
<StackPanel Name="SongInfoStackPanel" Margin="8,0,0,0" Orientation="Vertical" VerticalAlignment="Center" Width="182"
149184
ToolTipService.InitialShowDelay="800"
150185
ToolTipService.Placement="Top"
151186
ToolTipService.VerticalOffset="-16">
152-
<TextBlock Name="SongTitle" Text="Song Title" FontSize="14" FontWeight="Medium" TextTrimming="CharacterEllipsis" />
153-
<TextBlock Name="SongArtist" Text="Artist Name" FontSize="14" FontWeight="Medium" Opacity="0.5" TextTrimming="CharacterEllipsis" />
187+
<TextBlock Name="SongTitle" Text="Song Title" FontSize="14" FontWeight="Medium" TextTrimming="CharacterEllipsis" />
188+
<TextBlock Name="SongArtist" Text="Artist Name" FontSize="14" FontWeight="Medium" Opacity="0.5" TextTrimming="CharacterEllipsis" />
189+
</StackPanel>
154190
</StackPanel>
155-
</StackPanel>
156-
<Grid Name="ControlsStackPanelContainer" HorizontalAlignment="Stretch" Height="35" Margin="12,8,0,0">
157-
<StackPanel Name="ControlsStackPanel" Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Center">
158-
<!--<ui:Button Name="ControlBack" Icon="{ui:SymbolIcon Previous20, Filled=True}" Width="28" Height="28" Padding="0" CornerRadius="999" Margin="0,0,8,0" Click="Back_Click" Focusable="False"/>-->
159-
<controls:Button
191+
<Grid Name="ControlsStackPanelContainer" HorizontalAlignment="Stretch" Height="35" Margin="8,8,0,0">
192+
<Grid.ColumnDefinitions>
193+
<ColumnDefinition Width="*" />
194+
<ColumnDefinition Width="Auto" />
195+
</Grid.ColumnDefinitions>
196+
<StackPanel Name="ControlsStackPanel" Grid.Column="0" Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Center">
197+
<!--<ui:Button Name="ControlBack" Icon="{ui:SymbolIcon Previous20, Filled=True}" Width="28" Height="28" Padding="0" CornerRadius="999" Margin="0,0,8,0" Click="Back_Click" Focusable="False"/>-->
198+
<controls:Button
160199
Height="28" Width="28" Name="ControlBack"
161200
Margin="0" Click="Back_Click" Focusable="False"
162201
Style="{StaticResource MicaWPF.Styles.TransparentButton}" VerticalAlignment="Center">
163-
<ui:SymbolIcon Name="SymbolBack" Symbol="Previous20" Filled="True"/>
164-
</controls:Button>
165-
<controls:Button
202+
<ui:SymbolIcon Name="SymbolBack" Symbol="Previous20" Filled="True"/>
203+
</controls:Button>
204+
<controls:Button
166205
Height="32" Width="32" Name="ControlPlayPause"
167206
Margin="8,0,0,0" Click="PlayPause_Click" Focusable="False"
168207
Style="{StaticResource PlayPauseButtonStyle}" VerticalAlignment="Center">
169-
<ui:SymbolIcon Name="SymbolPlayPause" Symbol="Pause16" Filled="True"/>
170-
</controls:Button>
171-
<controls:Button
208+
<ui:SymbolIcon Name="SymbolPlayPause" Symbol="Pause16" Filled="True"/>
209+
</controls:Button>
210+
<controls:Button
172211
Height="28" Width="28" Name="ControlForward"
173212
Margin="8,0,0,0" Click="Forward_Click" Focusable="False"
174213
Style="{StaticResource MicaWPF.Styles.TransparentButton}" VerticalAlignment="Center">
175-
<ui:SymbolIcon Name="SymbolForward" Symbol="Next20" Filled="True"/>
176-
</controls:Button>
177-
<controls:Button
214+
<ui:SymbolIcon Name="SymbolForward" Symbol="Next20" Filled="True"/>
215+
</controls:Button>
216+
<controls:Button
178217
Width="28" Height="28" Name="ControlClose"
179218
Margin="8,0,0,0" Click="MediaFlyoutCloseButton_Click"
180219
Style="{StaticResource MicaWPF.Styles.TransparentButton}" VerticalAlignment="Center"
181220
Visibility="Collapsed">
182-
<ui:SymbolIcon Symbol="Dismiss20" Filled="True"/>
183-
</controls:Button>
184-
<controls:Button
221+
<ui:SymbolIcon Symbol="Dismiss20" Filled="True"/>
222+
</controls:Button>
223+
<controls:Button
185224
Height="28" Width="28" Name="ControlRepeat"
186225
Margin="8,0,0,0" Click="Repeat_Click" Focusable="False"
187226
Style="{StaticResource MicaWPF.Styles.TransparentButton}" VerticalAlignment="Center">
188-
<ui:SymbolIcon Name="SymbolRepeat" Symbol="ArrowRepeatAllOff24" Filled="false" Opacity="0.5" FontSize="18"/>
189-
</controls:Button>
227+
<ui:SymbolIcon Name="SymbolRepeat" Symbol="ArrowRepeatAllOff24" Filled="false" Opacity="0.5" FontSize="18"/>
228+
</controls:Button>
190229
<controls:Button
191230
Height="28" Width="28" Name="ControlShuffle"
192231
Margin="8,0,0,0" Click="Shuffle_Click" Focusable="False"
193232
Style="{StaticResource MicaWPF.Styles.TransparentButton}" VerticalAlignment="Center">
194233
<ui:SymbolIcon Name="SymbolShuffle" Symbol="ArrowShuffleOff24" Filled="false" Opacity="0.5" FontSize="18"/>
195234
</controls:Button>
196-
197-
<controls:Button Name="MediaIdButton" Padding="0" Height="28" Width="70"
198-
Margin="8,0,0,0"
199-
Style="{StaticResource MicaWPF.Styles.TransparentButton}"
200-
Click="MediaIdButton_Click"
201-
MouseRightButtonUp="MediaIdButton_RightClick">
202-
<StackPanel Orientation="Horizontal" Margin="2,0">
203-
<Image x:Name="MediaIdIcon" Width="14" Height="14"/>
204-
<TextBlock Name="MediaId" VerticalAlignment="Center" FontSize="10" Width="48" Margin="4,0,0,0" FontWeight="Regular" Opacity="0.25" TextWrapping="Wrap" TextTrimming="CharacterEllipsis"/>
205-
</StackPanel>
206-
</controls:Button>
207-
208235
</StackPanel>
209-
</Grid>
236+
237+
<ui:SplitButton Name="MediaIdButton" Grid.Column="1" Padding="0" Height="28" Width="Auto" MaxWidth="90"
238+
Margin="8,0,0,0"
239+
Background="Transparent"
240+
BorderThickness="0"
241+
HorizontalAlignment="Right"
242+
VerticalAlignment="Center"
243+
Click="MediaIdButton_Click">
244+
<StackPanel Orientation="Horizontal" Margin="4,0">
245+
<Image x:Name="MediaIdIcon" Width="14" Height="14"/>
246+
<TextBlock Name="MediaId" VerticalAlignment="Center" FontSize="10" Width="Auto" MaxWidth="48" Margin="4,0,0,0" FontWeight="Regular" Opacity="0.5" TextWrapping="Wrap" TextTrimming="CharacterEllipsis"/>
247+
</StackPanel>
248+
</ui:SplitButton>
249+
250+
</Grid>
251+
</StackPanel>
210252
</StackPanel>
211-
</StackPanel>
212253
<DockPanel Grid.Row="1" x:Name="SeekbarWrapper" HorizontalAlignment="Stretch" Margin="16,0,16,12" LastChildFill="True" VerticalAlignment="Center">
213254
<TextBlock Name="SeekbarCurrentDuration" Text="-:--" Opacity="0.5" FontSize="12" DockPanel.Dock="Left" Width="45" Margin="0,0,2,0" TextAlignment="Left" VerticalAlignment="Center" Height="18"/>
214255
<TextBlock Name="SeekbarMaxDuration" Text="-:--" Opacity="0.5" FontSize="12" DockPanel.Dock="Right" Width="45" Margin="2,0,0,0" TextAlignment="Right" VerticalAlignment="Center" Height="18"/>

‎FluentFlyoutWPF/MainWindow.xaml.cs‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,7 +1295,7 @@ private void UpdateUILayout() // update the layout based on the settings
12951295
{
12961296
int extraWidth = SettingsManager.Current.RepeatEnabled ? 36 : 0;
12971297
extraWidth += SettingsManager.Current.ShuffleEnabled ? 36 : 0;
1298-
extraWidth += SettingsManager.Current.PlayerInfoEnabled ? 72 : 0;
1298+
extraWidth += SettingsManager.Current.PlayerInfoEnabled ? 90 : 0;
12991299
// keep minimum width at 72 even if all extra features are disabled to prevent the widget from being too small
13001300
extraWidth = Math.Max(extraWidth, 72);
13011301

@@ -1329,14 +1329,14 @@ private void UpdateUILayout() // update the layout based on the settings
13291329
Width = 310 - 72 + extraWidth;
13301330
BodyStackPanel.Orientation = Orientation.Vertical;
13311331
BodyStackPanel.Width = 194 - 72 + extraWidth;
1332-
ControlsStackPanelContainer.Margin = new Thickness(12, 8, 0, 0);
1332+
ControlsStackPanelContainer.Margin = new Thickness(8, 8, 0, 0);
13331333
ControlsStackPanelContainer.Width = double.NaN;
13341334
ControlsStackPanelContainer.HorizontalAlignment = HorizontalAlignment.Stretch;
13351335
ControlsStackPanel.HorizontalAlignment = centerControlsWithSongInfo ? HorizontalAlignment.Center : HorizontalAlignment.Left;
13361336
MediaIdButton.Visibility = Visibility.Visible;
13371337
SongImageBorder.Margin = new Thickness(6);
1338-
SongImageBorder.Height = 78;
1339-
SongInfoStackPanel.Margin = new Thickness(12, 0, 0, 0);
1338+
SongImageBorder.Height = 82;
1339+
SongInfoStackPanel.Margin = new Thickness(8, 0, 0, 0);
13401340
SongInfoStackPanel.Width = 182 - 72 + extraWidth;
13411341
}
13421342

@@ -1361,6 +1361,12 @@ private async void MediaIdButton_Click(object sender, RoutedEventArgs e)
13611361
if (!SettingsManager.Current.PlayerInfoEnabled || SettingsManager.Current.CompactLayout) return;
13621362
e.Handled = true;
13631363

1364+
if (e.OriginalSource is ToggleButton dropdownButton)
1365+
{
1366+
ShowSessionSwitcherMenu();
1367+
return;
1368+
}
1369+
13641370
_ = TryOpenMediaPlayerAsync();
13651371
}
13661372

‎FluentFlyoutWPF/Resources/Localization/Dictionary-en-US.xaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ hides repeat, shuffle and player info</System:String>
4141
<System:String x:Key="CenterTitleArtistTitle">Center Title and Artist</System:String>
4242
<System:String x:Key="CenterTitleArtistDescription">Align text to the center instead of the left</System:String>
4343
<System:String x:Key="ShowMediaPlayerNameTitle">Show Media Player name</System:String>
44+
<System:String x:Key="ContextMenuSessionSwitcher">Switch sessions</System:String>
4445
<System:String x:Key="SessionSwitcherAuto">Automatic</System:String>
4546
<System:String x:Key="RepeatButtonTitle">Repeat Button*</System:String>
4647
<System:String x:Key="RepeatButtonDescription">Choose between repeat all or repeat one, increases flyout width</System:String>

0 commit comments

Comments
 (0)