Skip to content

Commit 27bc050

Browse files
committed
fix shutdown-event, add disable error popup setting, use better display id for Nvidia, fix refresh rate issues and improve background color
1 parent 4f4ce54 commit 27bc050

22 files changed

+384
-614
lines changed

ColorControl/ColorControl.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
<PublisherName>Maassoft</PublisherName>
1919
<Company>Maassoft</Company>
2020
<ApplicationRevision>0</ApplicationRevision>
21-
<ApplicationVersion>9.9.0.0</ApplicationVersion>
22-
<Version>9.9.0.0</Version>
21+
<ApplicationVersion>9.9.0.1</ApplicationVersion>
22+
<Version>9.9.0.1</Version>
2323
<UseApplicationTrust>false</UseApplicationTrust>
2424
<PublishWizardCompleted>true</PublishWizardCompleted>
2525
<BootstrapperEnabled>false</BootstrapperEnabled>

ColorControl/Forms/OptionsPanel.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,15 @@ private void btnOptionsAdvanced_Click(object sender, EventArgs e)
311311
SubLabel = "When this is enabled MinTML and MaxTML will be automatically be set to respectively the minimum luminance and the maximum luminance of the color profile",
312312
Value = _config.SetMinTmlAndMaxTml
313313
};
314+
var disableErrorPopupField = new FieldDefinition
315+
{
316+
FieldType = FieldType.CheckBox,
317+
Label = "Disable error popup when applying presets",
318+
SubLabel = "Check this to disable the error popup when there was an error applying a preset",
319+
Value = _config.DisableErrorPopupWhenApplyingPreset
320+
};
314321

315-
var values = MessageForms.ShowDialog("Advanced settings", new[] { processPollingIntervalField, useRawInputField, setMinTmlAndMaxTmlField });
322+
var values = MessageForms.ShowDialog("Advanced settings", new[] { processPollingIntervalField, useRawInputField, setMinTmlAndMaxTmlField, disableErrorPopupField });
316323

317324
if (values?.Any() != true)
318325
{
@@ -322,6 +329,7 @@ private void btnOptionsAdvanced_Click(object sender, EventArgs e)
322329
_config.ProcessMonitorPollingInterval = processPollingIntervalField.ValueAsInt;
323330
_config.UseRawInput = useRawInputField.ValueAsBool;
324331
_config.SetMinTmlAndMaxTml = setMinTmlAndMaxTmlField.ValueAsBool;
332+
_config.DisableErrorPopupWhenApplyingPreset = disableErrorPopupField.ValueAsBool;
325333

326334
_keyboardShortcutDispatcher.SetUseRawInput(_config.UseRawInput);
327335
}

ColorControl/MainForm.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public partial class MainForm : Form
3737
public NotifyIconManager _notifyIconManager;
3838
private readonly KeyboardShortcutDispatcher _keyboardShortcutDispatcher;
3939
private readonly UpdateManager _updateManager;
40+
private readonly WindowMessageDispatcher _windowMessageDispatcher;
4041
private Config _config;
4142

4243
private LgPanel _lgPanel;
@@ -48,7 +49,7 @@ public partial class MainForm : Form
4849
private GamePanel _gamePanel;
4950

5051
public MainForm(GlobalContext globalContext, ServiceManager serviceManager, IServiceProvider serviceProvider, ElevationService elevationService,
51-
NotifyIconManager notifyIconManager, KeyboardShortcutDispatcher keyboardShortcutDispatcher, UpdateManager updateManager)
52+
NotifyIconManager notifyIconManager, KeyboardShortcutDispatcher keyboardShortcutDispatcher, UpdateManager updateManager, WindowMessageDispatcher windowMessageDispatcher)
5253
{
5354
InitializeComponent();
5455

@@ -60,6 +61,7 @@ public MainForm(GlobalContext globalContext, ServiceManager serviceManager, ISer
6061
_notifyIconManager = notifyIconManager;
6162
_keyboardShortcutDispatcher = keyboardShortcutDispatcher;
6263
_updateManager = updateManager;
64+
_windowMessageDispatcher = windowMessageDispatcher;
6365
_config = Program.Config;
6466

6567
Text = globalContext.ApplicationTitleAdmin;
@@ -178,10 +180,8 @@ protected override void WndProc(ref Message m)
178180
if (m.Msg == NativeConstants.WM_QUERYENDSESSION)
179181
{
180182
SystemShutdown = true;
181-
}
182-
else if (m.Msg == NativeConstants.WM_ENDSESSION)
183-
{
184183
EndSession = true;
184+
_windowMessageDispatcher.DispatchEvent(WindowMessageDispatcher.Event_WindowMessageQueryEndSession, new WindowMessageEventArgs(m));
185185
}
186186
else if (m.Msg == Utils.WM_BRINGTOFRONT)
187187
{

ColorControl/MainWorker.cs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ internal class MainWorker
3030
private readonly WinApiService _winApiService;
3131
private readonly WinApiAdminService _winApiAdminService;
3232
private readonly UpdateManager _updateManager;
33-
private bool _queryEndSession;
3433
private nint _screenStateNotify;
3534

3635
public static int SHORTCUTID_SCREENSAVER = -100;
@@ -85,7 +84,6 @@ private async Task Init()
8584
_globalContext.SynchronizationContext = AsyncOperationManager.SynchronizationContext;
8685

8786
_windowMessageDispatcher.RegisterEventHandler(WindowMessageDispatcher.Event_WindowMessageQueryEndSession, HandleQueryEndSessionEvent);
88-
_windowMessageDispatcher.RegisterEventHandler(WindowMessageDispatcher.Event_WindowMessageClose, HandleCloseEvent);
8987
_windowMessageDispatcher.RegisterEventHandler(WindowMessageDispatcher.Event_WindowMessagePowerBroadcast, HandlePowerBroadcastEvent);
9088
_windowMessageDispatcher.RegisterEventHandler(WindowMessageDispatcher.Event_WindowMessageShowWindow, HandleShowWindowEvent);
9189
_windowMessageDispatcher.RegisterEventHandler(WindowMessageDispatcher.Event_WindowMessageUserBringToFront, HandleUserBringToFrontEvent);
@@ -151,21 +149,12 @@ private void HandlePowerBroadcastEvent(object sender, WindowMessageEventArgs e)
151149
}
152150
}
153151

154-
private void HandleCloseEvent(object sender, WindowMessageEventArgs e)
155-
{
156-
if (_queryEndSession)
157-
{
158-
Logger.Debug($"MainWorker: SystemShutdown");
159-
160-
_powerEventDispatcher.SendEvent(PowerEventDispatcher.Event_Shutdown);
161-
}
162-
}
163-
164152
private void HandleQueryEndSessionEvent(object sender, WindowMessageEventArgs e)
165153
{
166-
Logger.Debug("MainWorker: QueryEndSession");
154+
Logger.Debug($"MainWorker: QueryEndSession");
155+
Logger.Debug($"MainWorker: SystemShutdown");
167156

168-
_queryEndSession = true;
157+
_powerEventDispatcher.SendEvent(PowerEventDispatcher.Event_Shutdown);
169158
}
170159

171160
private void HandleHotKeyEvent(object sender, KeyboardShortcutEventArgs args)

ColorControl/Services/AMD/AmdPanel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ private void UpdateDisplayInfoItemsAmd()
9292
item = lvAmdPresets.Items.Add(display.DisplayName);
9393
item.ImageIndex = id;
9494
item.Font = new Font(item.Font, item.Font.Style | FontStyle.Bold);
95-
item.BackColor = Color.LightGray;
95+
item.BackColor = _globalContext.Config.UseDarkMode ? DarkModeUtils.ListViewDarkModeBackColor : Color.LightGray;
9696
}
9797

9898
var values = displayInfo.Values;

ColorControl/Services/AMD/AmdPreset.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,10 @@ public static string[] GetColumnNames()
6565

6666
public override List<string> GetDisplayValues(Config config = null)
6767
{
68-
var values = new List<string>();
69-
70-
values.Add(name);
68+
var values = new List<string>
69+
{
70+
name
71+
};
7172

7273
var display = string.Format("{0}", primaryDisplay ? "Primary" : displayName);
7374
values.Add(display);

ColorControl/Services/AMD/AmdService.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -305,10 +305,11 @@ public Screen GetScreenForDisplay(ADLDisplayInfo display)
305305
var index = 0;
306306
foreach (var screen in Screen.AllScreens)
307307
{
308-
Logger.Debug($"SCREEN[{index}]: {screen.DeviceName}, {screen.DeviceFriendlyName()}, {screen.Primary}");
308+
var info = CCD.GetDisplayInfo(screen.DeviceName);
309+
Logger.Debug($"SCREEN[{index}]: {screen.DeviceName}, {info?.FriendlyName}, {screen.Primary}");
309310
index++;
310311
}
311-
return Screen.AllScreens.FirstOrDefault(x => x.DeviceFriendlyName().Equals(display.DisplayName));
312+
return Screen.AllScreens.FirstOrDefault(x => CCD.GetDisplayInfo(x.DeviceName)?.FriendlyName.Equals(display.DisplayName) ?? false);
312313
}
313314

314315
public List<AmdDisplayInfo> GetDisplayInfos()
@@ -328,9 +329,10 @@ public List<AmdDisplayInfo> GetDisplayInfos()
328329

329330
foreach (var display in displays)
330331
{
331-
var values = new List<string>();
332-
333-
values.Add("Current settings");
332+
var values = new List<string>
333+
{
334+
"Current settings"
335+
};
334336

335337
var screen = GetScreenForDisplay(display);
336338

ColorControl/Services/Common/ServiceBase.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,10 @@ public async Task<bool> ApplyPresetUi(T preset)
9393
{
9494
Logger.Error(e);
9595

96-
MessageForms.ErrorOk($"Error applying {ServiceName}-preset ({e.TargetSite.Name}): {e.Message}");
96+
if (!_globalContext.Config.DisableErrorPopupWhenApplyingPreset)
97+
{
98+
MessageForms.ErrorOk($"Error applying {ServiceName}-preset ({preset.IdOrName}): {e.Message}");
99+
}
97100
return false;
98101
}
99102
}

ColorControl/Services/NVIDIA/NvDisplayInfo.cs

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using NvAPIWrapper.Display;
1+
using ColorControl.Shared.Native;
2+
using NStandard;
3+
using NvAPIWrapper.Display;
24
using System.Collections.Generic;
35

46
namespace ColorControl.Services.NVIDIA
@@ -7,18 +9,52 @@ class NvDisplayInfo
79
{
810
public Display Display { get; }
911

10-
public List<string> Values { get; }
12+
public List<string> Values { get; set; }
1113

12-
public string InfoLine { get; }
14+
public string InfoLine { get; set; }
1315

14-
public string Name { get; }
16+
public string Name { get; private set; }
1517

16-
public NvDisplayInfo(Display display, List<string> values, string infoLine, string name)
18+
public string DisplayId { get; private set; }
19+
20+
public NvDisplayInfo(Display display, List<string> values, string infoLine, string name = null)
1721
{
1822
Display = display;
1923
Values = values;
2024
InfoLine = infoLine;
2125
Name = name;
26+
27+
SetDisplayName();
28+
}
29+
30+
private void SetDisplayName()
31+
{
32+
if (!Name.IsNullOrEmpty())
33+
{
34+
return;
35+
}
36+
37+
38+
if (Display == null)
39+
{
40+
Name = "Unknown";
41+
42+
return;
43+
}
44+
45+
var info = CCD.GetDisplayInfo(Display.Name);
46+
47+
Name = info?.FriendlyName;
48+
DisplayId = info?.DisplayId;
49+
50+
if (Name.IsNullOrEmpty())
51+
{
52+
Name = DisplayId;
53+
}
54+
else
55+
{
56+
Name = $"{Name} ({DisplayId})";
57+
}
2258
}
2359

2460
public override string ToString()

0 commit comments

Comments
 (0)