Skip to content

Commit

Permalink
Fixed persistence (#23)
Browse files Browse the repository at this point in the history
Signed-off-by: Alessandro Bellia <casilda.bell85@gmail.com>
  • Loading branch information
lauralex authored Apr 17, 2023
1 parent ee36ff0 commit 9ff5289
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 11 deletions.
16 changes: 14 additions & 2 deletions DwmLutGUI/DwmLutGUI.sln
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31205.134
# Visual Studio Version 17
VisualStudioVersion = 17.5.33516.290
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DwmLutGUI", "DwmLutGUI\DwmLutGUI.csproj", "{7FA75ADD-B7F9-4A7F-9198-BAC492FFF80C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7FA75ADD-B7F9-4A7F-9198-BAC492FFF80C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7FA75ADD-B7F9-4A7F-9198-BAC492FFF80C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7FA75ADD-B7F9-4A7F-9198-BAC492FFF80C}.Debug|x64.ActiveCfg = Debug|x64
{7FA75ADD-B7F9-4A7F-9198-BAC492FFF80C}.Debug|x64.Build.0 = Debug|x64
{7FA75ADD-B7F9-4A7F-9198-BAC492FFF80C}.Debug|x86.ActiveCfg = Debug|Any CPU
{7FA75ADD-B7F9-4A7F-9198-BAC492FFF80C}.Debug|x86.Build.0 = Debug|Any CPU
{7FA75ADD-B7F9-4A7F-9198-BAC492FFF80C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7FA75ADD-B7F9-4A7F-9198-BAC492FFF80C}.Release|Any CPU.Build.0 = Release|Any CPU
{7FA75ADD-B7F9-4A7F-9198-BAC492FFF80C}.Release|x64.ActiveCfg = Release|x64
{7FA75ADD-B7F9-4A7F-9198-BAC492FFF80C}.Release|x64.Build.0 = Release|x64
{7FA75ADD-B7F9-4A7F-9198-BAC492FFF80C}.Release|x86.ActiveCfg = Release|Any CPU
{7FA75ADD-B7F9-4A7F-9198-BAC492FFF80C}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 1 addition & 1 deletion DwmLutGUI/DwmLutGUI/AboutWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
SnapsToDevicePixels="True">
<StackPanel Margin="6">
<TextBlock FontSize="15" HorizontalAlignment="Center" TextAlignment="Center">
dwm_lut v3.9.4 by lauralex (original by ledoge)
dwm_lut v3.9.5 by lauralex (original by ledoge)
</TextBlock>
<TextBlock HorizontalAlignment="Center" TextAlignment="Center">
Licensed under GPLv3 <LineBreak /> <LineBreak />
Expand Down
26 changes: 26 additions & 0 deletions DwmLutGUI/DwmLutGUI/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ internal class MainViewModel : INotifyPropertyChanged
private string _activeText;
private MonitorData _selectedMonitor;
private bool _isActive;
private Key _toggleKey;

private readonly string _configPath;

Expand Down Expand Up @@ -83,6 +84,7 @@ private void UpdateConfigChanged()
private void SaveConfig()
{
var xElem = new XElement("monitors",
new XAttribute("lut_toggle", _toggleKey),
_allMonitors.Select(x =>
new XElement("monitor", new XAttribute("path", x.DevicePath),
x.SdrLutPath != null ? new XAttribute("sdr_lut", x.SdrLutPath) : null,
Expand Down Expand Up @@ -122,6 +124,18 @@ public string HdrLutPath
get => SelectedMonitor?.HdrLutPath;
}

public Key ToggleKey
{
set
{
if (value == _toggleKey) return;
_toggleKey = value;
OnPropertyChanged();
SaveConfig();
}
get => _toggleKey;
}

public bool IsActive
{
set
Expand All @@ -147,6 +161,18 @@ public void UpdateMonitors()
if (File.Exists(_configPath))
{
config = XElement.Load(_configPath).Descendants("monitor").ToList();
try
{
_toggleKey = (Key)Enum.Parse(typeof(Key), (string)XElement.Load(_configPath).Attribute("lut_toggle"));
}
catch
{
_toggleKey = Key.Pause;
}
}
else
{
_toggleKey = Key.Pause;
}

var paths = WindowsDisplayAPI.DisplayConfig.PathInfo.GetActivePaths();
Expand Down
2 changes: 1 addition & 1 deletion DwmLutGUI/DwmLutGUI/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<Button Grid.Row="1" IsEnabled="{Binding HdrLutPath, TargetNullValue=false}" Grid.Column="3"
Content="Clear"
Width="75" Click="HdrLutClear_Click" />
<ComboBox x:Name="ToggleKeyCombo" Grid.Row="2" Grid.Column="0" Text="Toggle Key" />
<ComboBox x:Name="ToggleKeyCombo" Grid.Row="2" Grid.Column="0" Text="Toggle Key" SelectedItem="{Binding ToggleKey}" />
</Grid>
<Grid DockPanel.Dock="Bottom">
<Button Content="About" Width="75" HorizontalAlignment="Left" Click="AboutButton_Click" />
Expand Down
10 changes: 6 additions & 4 deletions DwmLutGUI/DwmLutGUI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Forms;
using System.Windows.Input;
using Microsoft.Win32;
using ContextMenu = System.Windows.Forms.ContextMenu;
using MenuItem = System.Windows.Forms.MenuItem;
using MessageBox = System.Windows.Forms.MessageBox;

namespace DwmLutGUI
Expand Down Expand Up @@ -117,7 +120,6 @@ public MainWindow()
App.KListener.KeyDown += MonitorLutToggle;
var keys = Enum.GetValues(typeof(Key)).Cast<Key>().ToList();
ToggleKeyCombo.ItemsSource = keys;
ToggleKeyCombo.SelectedItem = Key.NumPad1;
}

protected override void OnStateChanged(EventArgs e)
Expand Down Expand Up @@ -175,7 +177,7 @@ private void SdrLutBrowse_Click(object sender, RoutedEventArgs e)

private void SdrLutClear_Click(object sender, RoutedEventArgs e)
{
_viewModel.SdrLutPath = null;
_viewModel.SdrLutPath = "None";
}

private void HdrLutBrowse_Click(object sender, RoutedEventArgs e)
Expand All @@ -190,7 +192,7 @@ private void HdrLutBrowse_Click(object sender, RoutedEventArgs e)

private void HdrLutClear_Click(object sender, RoutedEventArgs e)
{
_viewModel.HdrLutPath = null;
_viewModel.HdrLutPath = "None";
}

private void Disable_Click(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -280,7 +282,7 @@ private void RemoveHdrLut_Click(object sender, RoutedEventArgs e)
var monitor = _viewModel.SelectedMonitor;
if (monitor == null) return;
monitor.HdrLuts.Remove(monitor.HdrLutPath);
monitor.HdrLutPath = monitor.HdrLuts.FirstOrDefault();
monitor.HdrLutPath = monitor.HdrLuts.FirstOrDefault() ?? "None";
}
}
}
6 changes: 3 additions & 3 deletions DwmLutGUI/DwmLutGUI/MonitorData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public string SdrLutPath
if (value == null) return;
if (value != "None" && !SdrLuts.Contains(value))
SdrLuts.Add(value);
_sdrLutPath = value;
_sdrLutPath = value != "None" ? value : null;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(SdrLutFilename)));
StaticPropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(SdrLutFilename)));
}
Expand All @@ -66,11 +66,11 @@ public string HdrLutPath
set
{
if (value == _hdrLutPath) return;
if (!HdrLuts.Contains(value))
if (value != "None" && !HdrLuts.Contains(value))
{
HdrLuts.Add(value);
}
_hdrLutPath = value;
_hdrLutPath = value != "None" ? value : null;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(HdrLutFilename)));
StaticPropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(HdrLutFilename)));
}
Expand Down

0 comments on commit 9ff5289

Please sign in to comment.