Skip to content

Commit

Permalink
Mpv LivelyProperties scaler change and refactoring
Browse files Browse the repository at this point in the history
Resolved: #2194
  • Loading branch information
rocksdanister committed Apr 15, 2024
1 parent c3048d0 commit e330d74
Show file tree
Hide file tree
Showing 12 changed files with 167 additions and 149 deletions.
11 changes: 11 additions & 0 deletions src/Lively/Lively.Common/API/IpcMessage.cs
Expand Up @@ -28,6 +28,7 @@ public enum MessageType
lp_button,
lp_cpicker,
lp_chekbox,
lp_dropdown_scaler,
}

public enum ConsoleMessageType
Expand Down Expand Up @@ -195,6 +196,16 @@ public LivelyDropdown() : base(MessageType.lp_dropdown)
}
}

[Serializable]
public class LivelyDropdownScaler : IpcMessage
{
public string Name { get; set; }
public int Value { get; set; }
public LivelyDropdownScaler() : base(MessageType.lp_dropdown_scaler)
{
}
}

[Serializable]
public class LivelyFolderDropdown : IpcMessage
{
Expand Down
1 change: 1 addition & 0 deletions src/Lively/Lively.Common/API/IpcMessageConverter.cs
Expand Up @@ -35,6 +35,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
MessageType.msg_hwnd => jo.ToObject<LivelyMessageHwnd>(serializer),
MessageType.msg_screenshot => jo.ToObject<LivelyMessageScreenshot>(serializer),
MessageType.msg_wploaded => jo.ToObject<LivelyMessageWallpaperLoaded>(serializer),
MessageType.lp_dropdown_scaler => jo.ToObject<LivelyDropdownScaler>(serializer),
_ => null,
};
}
Expand Down
6 changes: 6 additions & 0 deletions src/Lively/Lively.UI.WinUI/ViewModels/SettingsViewModel.cs
Expand Up @@ -455,13 +455,19 @@ public bool MouseMoveOnDesktop
[ObservableProperty]
private bool isSelectedVideoPlayerAvailable;

[ObservableProperty]
private bool isBackwardCompatibilityWallpaperScaler;

private int _selectedVideoPlayerIndex;
public int SelectedVideoPlayerIndex
{
get => _selectedVideoPlayerIndex;
set
{
IsSelectedVideoPlayerAvailable = IsVideoPlayerAvailable((LivelyMediaPlayer)value);
// Only mpv supports scaler settings in customise menu, enable global scaler menu for older players.
IsBackwardCompatibilityWallpaperScaler = IsSelectedVideoPlayerAvailable && (LivelyMediaPlayer)value != LivelyMediaPlayer.mpv;

if (userSettings.Settings.VideoPlayer != (LivelyMediaPlayer)value && IsSelectedVideoPlayerAvailable)
{
userSettings.Settings.VideoPlayer = (LivelyMediaPlayer)value;
Expand Down
Expand Up @@ -24,6 +24,7 @@
using Lively.UI.WinUI.UserControls;
using Microsoft.UI.Xaml.Media.Imaging;
using Lively.Common.Helpers.Shell;
using Windows.ApplicationModel.Resources;
//using CommunityToolkit.WinUI.UI.Controls;


Expand All @@ -48,6 +49,8 @@ public sealed partial class LivelyPropertiesView : Page
private readonly IDisplayManagerClient displayManager;
private readonly DispatcherQueue dispatcherQueue;

private readonly ResourceLoader languageResource;

public LivelyPropertiesView() // Default constructor for OnNavigatedTo
{
this.InitializeComponent();
Expand All @@ -56,6 +59,8 @@ public sealed partial class LivelyPropertiesView : Page
displayManager = App.Services.GetRequiredService<IDisplayManagerClient>();
//MainWindow dispatcher may not be ready yet, creating our own instead..
dispatcherQueue = DispatcherQueue.GetForCurrentThread() ?? DispatcherQueueController.CreateOnCurrentThread().DispatcherQueue;

languageResource = ResourceLoader.GetForViewIndependentUse();
}

public LivelyPropertiesView(LibraryModel model) : this()
Expand Down Expand Up @@ -104,18 +109,10 @@ private void GenerateUIElements()
{
if (livelyPropertyCopyData == null)
{
var msg = "Property file not found!";
if (libraryItem.LivelyInfo.Type == WallpaperType.video ||
libraryItem.LivelyInfo.Type == WallpaperType.videostream ||
libraryItem.LivelyInfo.Type == WallpaperType.gif ||
libraryItem.LivelyInfo.Type == WallpaperType.picture)
{
msg += "\n(Mpv player is required.)";
}
//Empty..
AddUIElement(new TextBlock
{
Text = msg,
Text = "Property file not found!",
//Background = Brushes.Red,
FontSize = 18,
//Foreground = Brushes.Gray,
Expand Down Expand Up @@ -262,7 +259,7 @@ private void GenerateUIElements()
chk.Unchecked += Checkbox_CheckedChanged;
obj = chk;
}
else if (uiElementType.Equals("dropdown", StringComparison.OrdinalIgnoreCase))
else if (uiElementType.Equals("dropdown", StringComparison.OrdinalIgnoreCase) || uiElementType.Equals("dropdown_scaler", StringComparison.OrdinalIgnoreCase))
{
var cmbBox = new ComboBox()
{
Expand All @@ -273,15 +270,28 @@ private void GenerateUIElements()
Margin = margin,
SelectedIndex = (int)item.Value["value"],
};
foreach (var dropItem in item.Value["items"])

if (uiElementType.Equals("dropdown_scaler", StringComparison.OrdinalIgnoreCase))
{
cmbBox.Items.Add(dropItem.ToString());
cmbBox.Items.Add(languageResource.GetString("WallpaperFitNone/Content"));
cmbBox.Items.Add(languageResource.GetString("WallpaperFitFill/Content"));
cmbBox.Items.Add(languageResource.GetString("WallpaperFitUniform/Content"));
cmbBox.Items.Add(languageResource.GetString("WallpaperFitUniformToFill/Content"));
ToolTipService.SetToolTip(cmbBox, new ToolTip() { Content = languageResource.GetString("WallpaperFit/Description") });
cmbBox.SelectionChanged += XamlCmbBox_Slider_SelectionChanged;
}
if (item.Value["help"] != null && !string.IsNullOrWhiteSpace(item.Value["help"].ToString()))
else
{
ToolTipService.SetToolTip(cmbBox, new ToolTip() { Content = (string)item.Value["help"] });
foreach (var dropItem in item.Value["items"])
{
cmbBox.Items.Add(dropItem.ToString());
}
if (item.Value["help"] != null && !string.IsNullOrWhiteSpace(item.Value["help"].ToString()))
{
ToolTipService.SetToolTip(cmbBox, new ToolTip() { Content = (string)item.Value["help"] });
}
cmbBox.SelectionChanged += XamlCmbBox_SelectionChanged;
}
cmbBox.SelectionChanged += XamlCmbBox_SelectionChanged;
obj = cmbBox;
}
else if (uiElementType.Equals("folderDropdown", StringComparison.OrdinalIgnoreCase))
Expand Down Expand Up @@ -359,19 +369,26 @@ private void GenerateUIElements()
!uiElementType.Equals("checkbox", StringComparison.OrdinalIgnoreCase) &&
!uiElementType.Equals("label", StringComparison.OrdinalIgnoreCase))
{
string help = null;
string title = null;
if (uiElementType.Equals("dropdown_scaler", StringComparison.OrdinalIgnoreCase))
{
title = languageResource.GetString("WallpaperFit/Header");
help = languageResource.GetString("WallpaperFit/Description");
}

var tb = new TextBlock
{
Text = item.Value["text"].ToString(),
Text = title ?? item.Value["text"].ToString(),
HorizontalAlignment = HorizontalAlignment.Left,
//MaxWidth = minWidth,
MinWidth = minWidth,
Margin = margin
};
AddUIElement(tb);

if (item.Value["help"] != null && !string.IsNullOrWhiteSpace(item.Value["help"].ToString()))
{
ToolTipService.SetToolTip(tb, new ToolTip() { Content = (string)item.Value["help"] });
}
ToolTipService.SetToolTip(tb, new ToolTip() { Content = help ?? (string)item.Value["help"] });
}

AddUIElement(obj);
Expand Down Expand Up @@ -412,6 +429,18 @@ private void XamlCmbBox_SelectionChanged(object sender, SelectionChangedEventArg
catch { }
}

private void XamlCmbBox_Slider_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
try
{
var item = (ComboBox)sender;
WallpaperSendMsg(new LivelyDropdownScaler() { Name = item.Name, Value = item.SelectedIndex });
livelyPropertyCopyData[item.Name]["value"] = item.SelectedIndex;
UpdatePropertyFile();
}
catch { }
}

private void XamlFolderCmbBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
try
Expand Down
19 changes: 0 additions & 19 deletions src/Lively/Lively.UI.WinUI/Views/MainWindow.xaml
Expand Up @@ -193,26 +193,7 @@
-->
</AppBarButton>

<AppBarSeparator x:Name="separatorLabel2" Visibility="Collapsed" />
<AppBarButton
Name="audioBtn"
MaxWidth="50"
LabelPosition="Collapsed"
Visibility="Collapsed">
<AppBarButton.Flyout>
<Flyout>
<Slider
Name="audioSlider"
MinWidth="125"
ValueChanged="SliderAudio_ValueChanged" />
</Flyout>
</AppBarButton.Flyout>
<AppBarButton.Icon>
<FontIcon Glyph="&#xE994;" />
</AppBarButton.Icon>
</AppBarButton>
<AppBarSeparator x:Name="separatorLabel3" />

<AppBarButton
Name="coffeeBtn"
MaxWidth="50"
Expand Down
24 changes: 0 additions & 24 deletions src/Lively/Lively.UI.WinUI/Views/MainWindow.xaml.cs
Expand Up @@ -97,8 +97,6 @@ public sealed partial class MainWindow : WindowEx
this.SystemBackdrop = new MicaBackdrop();
Root.DataContext = mainViewModel;
i18n = ResourceLoader.GetForViewIndependentUse();
this.audioSlider.Value = settingsVm.GlobalWallpaperVolume;
UpdateAudioSliderIcon(settingsVm.GlobalWallpaperVolume);
this.controlPanelLabel.Label = $"{desktopCore.Wallpapers.Count} {i18n.GetString("ActiveWallpapers/Label")}";
controlPanelMonitor.Glyph = monitorGlyphs[desktopCore.Wallpapers.Count >= monitorGlyphs.Length ? monitorGlyphs.Length - 1 : desktopCore.Wallpapers.Count];
desktopCore.WallpaperChanged += DesktopCore_WallpaperChanged;
Expand Down Expand Up @@ -164,7 +162,6 @@ public sealed partial class MainWindow : WindowEx
private void CompactLabels()
{
separatorLabel1.Visibility = Visibility.Collapsed;
separatorLabel2.Visibility = Visibility.Collapsed;
separatorLabel3.Visibility = Visibility.Collapsed;
controlPanelLabel.LabelPosition = CommandBarLabelPosition.Collapsed;
addWallpaperLabel.LabelPosition = CommandBarLabelPosition.Collapsed;
Expand Down Expand Up @@ -269,9 +266,6 @@ private void NavView_BackRequested(NavigationView sender, NavigationViewBackRequ
{
ShowMainMenu();
NavViewNavigate(NavPages.library);

//If audio changed in settings page..
this.audioSlider.Value = settingsVm.GlobalWallpaperVolume;
}

private async void AddWallpaperButton_Click(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -438,12 +432,6 @@ private void AppBarAboutButton_Click(object sender, RoutedEventArgs e)
_ = dialogService.ShowAboutDialogAsync();
}

private void SliderAudio_ValueChanged(object sender, RangeBaseValueChangedEventArgs e)
{
settingsVm.GlobalWallpaperVolume = (int)e.NewValue;
UpdateAudioSliderIcon(settingsVm.GlobalWallpaperVolume);
}

private void CreateMainMenu()
{
navView.MenuItems.Add(CreateMenu(i18n.GetString("TitleLibrary"), NavPages.library.GetAttrValue(), "\uE8A9"));
Expand Down Expand Up @@ -483,9 +471,6 @@ private void ShowSettingsMenu()
}
}

private void UpdateAudioSliderIcon(double volume) =>
audioBtn.Icon = audioIcons[(int)Math.Ceiling((audioIcons.Length - 1) * volume / 100)];

//Actually called before window closed!
//Issue: https://github.com/microsoft/microsoft-ui-xaml/issues/5454
private async void Window_Closed(object sender, WindowEventArgs args)
Expand Down Expand Up @@ -870,15 +855,6 @@ public enum NavPages
settingsSystem,
}

private readonly FontIcon[] audioIcons =
{
new FontIcon(){ Glyph = "\uE74F" },
new FontIcon(){ Glyph = "\uE992" },
new FontIcon(){ Glyph = "\uE993" },
new FontIcon(){ Glyph = "\uE994" },
new FontIcon(){ Glyph = "\uE995" },
};

private readonly string[] monitorGlyphs =
{
"\uE900",
Expand Down
30 changes: 16 additions & 14 deletions src/Lively/Lively.UI.WinUI/Views/Pages/AddWallpaperView.xaml
Expand Up @@ -76,14 +76,14 @@
</Grid>

<StackPanel Grid.Row="1">
<controls:SettingsCard x:Uid="AddWallpaperFileBrowse" Margin="0,10,0,0">
<controls:SettingsCard
x:Uid="AddWallpaperFileBrowse"
Margin="0,10,0,0"
Command="{Binding BrowseFileCommand}"
IsClickEnabled="True">
<controls:SettingsCard.HeaderIcon>
<FontIcon Glyph="&#xEB9F;" />
</controls:SettingsCard.HeaderIcon>
<Button
x:Uid="TextOpen"
MinWidth="150"
Command="{Binding BrowseFileCommand}" />
</controls:SettingsCard>
<!--<InfoBar
IsClosable="False"
Expand All @@ -102,19 +102,21 @@
</controls:SettingsExpander.HeaderIcon>
<controls:SettingsExpander.Items>
<controls:SettingsCard ContentAlignment="Left">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="325" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBox Grid.Column="0" Text="{Binding WebUrlText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<StackPanel
VerticalAlignment="Center"
Orientation="Horizontal"
Spacing="4">
<TextBox
Width="350"
Text="{Binding WebUrlText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
TextWrapping="NoWrap" />
<Button
Grid.Column="1"
Margin="5,0,0,0"
Background="Transparent"
BorderThickness="0"
Command="{Binding BrowseWebCommand}">
<FontIcon Glyph="&#xE72A;" />
</Button>
</Grid>
</StackPanel>
</controls:SettingsCard>
</controls:SettingsExpander.Items>
</controls:SettingsExpander>
Expand Down
Expand Up @@ -5,13 +5,15 @@
xmlns:animations="using:CommunityToolkit.WinUI.Animations"
xmlns:controls="using:CommunityToolkit.WinUI.Controls"
xmlns:converters="using:CommunityToolkit.WinUI.Converters"
xmlns:customConverters="using:Lively.UI.WinUI.Helpers.Converters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:Lively.UI.WinUI.Views.Pages.Settings"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<Page.Resources>
<converters:BoolNegationConverter x:Key="BoolNegationConverter" />
<customConverters:AudioVolumeGlyphConverter x:Key="AudioVolumeGlyphConverter" />
</Page.Resources>

<Grid>
Expand Down Expand Up @@ -76,7 +78,7 @@
IsOpen="True"
Severity="Informational">
<InfoBar.ActionButton>
<HyperlinkButton NavigateUri="https://crwd.in/lively-wallpaper" ToolTipService.ToolTip="https://crwd.in/lively-wallpaper">
<HyperlinkButton NavigateUri="https://rocksdanister.github.io/lively/translation" ToolTipService.ToolTip="https://rocksdanister.github.io/lively/translation">
<HyperlinkButton.Content>
<TextBlock x:Uid="TextLearnMore" TextWrapping="Wrap" />
</HyperlinkButton.Content>
Expand Down Expand Up @@ -112,17 +114,13 @@
Margin="0,0,0,10"
FontWeight="SemiBold" />
<controls:SettingsExpander
x:Name="audioBtn"
x:Uid="Audio"
HeaderIcon="{Binding GlobalWallpaperVolume, Mode=OneWay, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource AudioVolumeGlyphConverter}}"
IsExpanded="True">
<controls:SettingsExpander.HeaderIcon>
<FontIcon Glyph="&#xE767;" />
</controls:SettingsExpander.HeaderIcon>
<Slider
MinWidth="{StaticResource SettingActionControlMinWidth}"
Maximum="100"
Minimum="0"
ValueChanged="Slider_ValueChanged"
Value="{Binding GlobalWallpaperVolume, Mode=TwoWay}" />
<controls:SettingsExpander.Items>
<controls:SettingsCard ContentAlignment="Left">
Expand Down

1 comment on commit e330d74

@rocksdanister
Copy link
Owner Author

@rocksdanister rocksdanister commented on e330d74 Apr 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Please sign in to comment.