Skip to content

Commit 9ff5289

Browse files
authored
Fixed persistence (#23)
Signed-off-by: Alessandro Bellia <casilda.bell85@gmail.com>
1 parent ee36ff0 commit 9ff5289

File tree

6 files changed

+51
-11
lines changed

6 files changed

+51
-11
lines changed

DwmLutGUI/DwmLutGUI.sln

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,32 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 16
4-
VisualStudioVersion = 16.0.31205.134
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.5.33516.290
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DwmLutGUI", "DwmLutGUI\DwmLutGUI.csproj", "{7FA75ADD-B7F9-4A7F-9198-BAC492FFF80C}"
77
EndProject
88
Global
99
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
1011
Debug|x64 = Debug|x64
12+
Debug|x86 = Debug|x86
13+
Release|Any CPU = Release|Any CPU
1114
Release|x64 = Release|x64
15+
Release|x86 = Release|x86
1216
EndGlobalSection
1317
GlobalSection(ProjectConfigurationPlatforms) = postSolution
18+
{7FA75ADD-B7F9-4A7F-9198-BAC492FFF80C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19+
{7FA75ADD-B7F9-4A7F-9198-BAC492FFF80C}.Debug|Any CPU.Build.0 = Debug|Any CPU
1420
{7FA75ADD-B7F9-4A7F-9198-BAC492FFF80C}.Debug|x64.ActiveCfg = Debug|x64
1521
{7FA75ADD-B7F9-4A7F-9198-BAC492FFF80C}.Debug|x64.Build.0 = Debug|x64
22+
{7FA75ADD-B7F9-4A7F-9198-BAC492FFF80C}.Debug|x86.ActiveCfg = Debug|Any CPU
23+
{7FA75ADD-B7F9-4A7F-9198-BAC492FFF80C}.Debug|x86.Build.0 = Debug|Any CPU
24+
{7FA75ADD-B7F9-4A7F-9198-BAC492FFF80C}.Release|Any CPU.ActiveCfg = Release|Any CPU
25+
{7FA75ADD-B7F9-4A7F-9198-BAC492FFF80C}.Release|Any CPU.Build.0 = Release|Any CPU
1626
{7FA75ADD-B7F9-4A7F-9198-BAC492FFF80C}.Release|x64.ActiveCfg = Release|x64
1727
{7FA75ADD-B7F9-4A7F-9198-BAC492FFF80C}.Release|x64.Build.0 = Release|x64
28+
{7FA75ADD-B7F9-4A7F-9198-BAC492FFF80C}.Release|x86.ActiveCfg = Release|Any CPU
29+
{7FA75ADD-B7F9-4A7F-9198-BAC492FFF80C}.Release|x86.Build.0 = Release|Any CPU
1830
EndGlobalSection
1931
GlobalSection(SolutionProperties) = preSolution
2032
HideSolutionNode = FALSE

DwmLutGUI/DwmLutGUI/AboutWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
SnapsToDevicePixels="True">
1212
<StackPanel Margin="6">
1313
<TextBlock FontSize="15" HorizontalAlignment="Center" TextAlignment="Center">
14-
dwm_lut v3.9.4 by lauralex (original by ledoge)
14+
dwm_lut v3.9.5 by lauralex (original by ledoge)
1515
</TextBlock>
1616
<TextBlock HorizontalAlignment="Center" TextAlignment="Center">
1717
Licensed under GPLv3 <LineBreak /> <LineBreak />

DwmLutGUI/DwmLutGUI/MainViewModel.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ internal class MainViewModel : INotifyPropertyChanged
1919
private string _activeText;
2020
private MonitorData _selectedMonitor;
2121
private bool _isActive;
22+
private Key _toggleKey;
2223

2324
private readonly string _configPath;
2425

@@ -83,6 +84,7 @@ private void UpdateConfigChanged()
8384
private void SaveConfig()
8485
{
8586
var xElem = new XElement("monitors",
87+
new XAttribute("lut_toggle", _toggleKey),
8688
_allMonitors.Select(x =>
8789
new XElement("monitor", new XAttribute("path", x.DevicePath),
8890
x.SdrLutPath != null ? new XAttribute("sdr_lut", x.SdrLutPath) : null,
@@ -122,6 +124,18 @@ public string HdrLutPath
122124
get => SelectedMonitor?.HdrLutPath;
123125
}
124126

127+
public Key ToggleKey
128+
{
129+
set
130+
{
131+
if (value == _toggleKey) return;
132+
_toggleKey = value;
133+
OnPropertyChanged();
134+
SaveConfig();
135+
}
136+
get => _toggleKey;
137+
}
138+
125139
public bool IsActive
126140
{
127141
set
@@ -147,6 +161,18 @@ public void UpdateMonitors()
147161
if (File.Exists(_configPath))
148162
{
149163
config = XElement.Load(_configPath).Descendants("monitor").ToList();
164+
try
165+
{
166+
_toggleKey = (Key)Enum.Parse(typeof(Key), (string)XElement.Load(_configPath).Attribute("lut_toggle"));
167+
}
168+
catch
169+
{
170+
_toggleKey = Key.Pause;
171+
}
172+
}
173+
else
174+
{
175+
_toggleKey = Key.Pause;
150176
}
151177

152178
var paths = WindowsDisplayAPI.DisplayConfig.PathInfo.GetActivePaths();

DwmLutGUI/DwmLutGUI/MainWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
<Button Grid.Row="1" IsEnabled="{Binding HdrLutPath, TargetNullValue=false}" Grid.Column="3"
4747
Content="Clear"
4848
Width="75" Click="HdrLutClear_Click" />
49-
<ComboBox x:Name="ToggleKeyCombo" Grid.Row="2" Grid.Column="0" Text="Toggle Key" />
49+
<ComboBox x:Name="ToggleKeyCombo" Grid.Row="2" Grid.Column="0" Text="Toggle Key" SelectedItem="{Binding ToggleKey}" />
5050
</Grid>
5151
<Grid DockPanel.Dock="Bottom">
5252
<Button Content="About" Width="75" HorizontalAlignment="Left" Click="AboutButton_Click" />

DwmLutGUI/DwmLutGUI/MainWindow.xaml.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77
using System.Threading;
88
using System.Threading.Tasks;
99
using System.Windows;
10+
using System.Windows.Controls;
1011
using System.Windows.Forms;
1112
using System.Windows.Input;
1213
using Microsoft.Win32;
14+
using ContextMenu = System.Windows.Forms.ContextMenu;
15+
using MenuItem = System.Windows.Forms.MenuItem;
1316
using MessageBox = System.Windows.Forms.MessageBox;
1417

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

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

176178
private void SdrLutClear_Click(object sender, RoutedEventArgs e)
177179
{
178-
_viewModel.SdrLutPath = null;
180+
_viewModel.SdrLutPath = "None";
179181
}
180182

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

191193
private void HdrLutClear_Click(object sender, RoutedEventArgs e)
192194
{
193-
_viewModel.HdrLutPath = null;
195+
_viewModel.HdrLutPath = "None";
194196
}
195197

196198
private void Disable_Click(object sender, RoutedEventArgs e)
@@ -280,7 +282,7 @@ private void RemoveHdrLut_Click(object sender, RoutedEventArgs e)
280282
var monitor = _viewModel.SelectedMonitor;
281283
if (monitor == null) return;
282284
monitor.HdrLuts.Remove(monitor.HdrLutPath);
283-
monitor.HdrLutPath = monitor.HdrLuts.FirstOrDefault();
285+
monitor.HdrLutPath = monitor.HdrLuts.FirstOrDefault() ?? "None";
284286
}
285287
}
286288
}

DwmLutGUI/DwmLutGUI/MonitorData.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public string SdrLutPath
5454
if (value == null) return;
5555
if (value != "None" && !SdrLuts.Contains(value))
5656
SdrLuts.Add(value);
57-
_sdrLutPath = value;
57+
_sdrLutPath = value != "None" ? value : null;
5858
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(SdrLutFilename)));
5959
StaticPropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(SdrLutFilename)));
6060
}
@@ -66,11 +66,11 @@ public string HdrLutPath
6666
set
6767
{
6868
if (value == _hdrLutPath) return;
69-
if (!HdrLuts.Contains(value))
69+
if (value != "None" && !HdrLuts.Contains(value))
7070
{
7171
HdrLuts.Add(value);
7272
}
73-
_hdrLutPath = value;
73+
_hdrLutPath = value != "None" ? value : null;
7474
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(HdrLutFilename)));
7575
StaticPropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(HdrLutFilename)));
7676
}

0 commit comments

Comments
 (0)