Refactor and enhance monitor control logic

- Consolidated brightness and capabilities retrieval logic with `GetBrightnessInfoCore` and `RetryHelper` for improved modularity and resiliency.
- Introduced `LockedDictionary` for thread-safe dictionary operations, replacing manual locking in `PhysicalMonitorHandleManager` and `MonitorStateManager`.
- Refactored monitor discovery in `MonitorManager` to separate discovery, initialization, and validation steps for better maintainability.
- Simplified event registration in `App.xaml.cs` with helper methods to reduce repetitive code.
- Enhanced VCP code handling with new methods for formatted and sorted VCP code retrieval.
- Added `SuspendNotifications` in `MonitorInfo` to optimize batch property updates and improve UI performance.
- Simplified parameter update methods in `MonitorViewModel` by removing redundant `fromProfile` logic.
- Improved state management with synchronous save support and reusable JSON building logic in `MonitorStateManager`.
- Updated UI bindings in `ProfileEditorDialog.xaml` and improved VCP code display in `MainViewModel`.
- Cleaned up redundant code, improved logging, and standardized method naming for better readability and maintainability.
This commit is contained in:
Yu Leng
2025-11-26 05:02:49 +08:00
parent f5a2235f53
commit de44da04de
15 changed files with 962 additions and 454 deletions

View File

@@ -6,6 +6,7 @@ using System;
using System.Collections.Generic;
using System.Globalization;
using ManagedCommon;
using PowerDisplay.Common.Drivers;
namespace PowerDisplay.Common.Utils
{
@@ -15,26 +16,6 @@ namespace PowerDisplay.Common.Utils
/// </summary>
public static class MonitorFeatureHelper
{
/// <summary>
/// VCP code for Brightness (0x10) - Standard VESA MCCS brightness control
/// </summary>
public const int VcpCodeBrightness = 0x10;
/// <summary>
/// VCP code for Contrast (0x12) - Standard VESA MCCS contrast control
/// </summary>
public const int VcpCodeContrast = 0x12;
/// <summary>
/// VCP code for Select Color Preset (0x14) - Color temperature control
/// </summary>
public const int VcpCodeSelectColorPreset = 0x14;
/// <summary>
/// VCP code for Audio Speaker Volume (0x62)
/// </summary>
public const int VcpCodeVolume = 0x62;
/// <summary>
/// Result of parsing monitor feature support from VCP capabilities
/// </summary>
@@ -81,10 +62,10 @@ namespace PowerDisplay.Common.Utils
// Determine feature support based on VCP codes
return new FeatureSupportResult
{
SupportsBrightness = vcpCodeInts.Contains(VcpCodeBrightness),
SupportsContrast = vcpCodeInts.Contains(VcpCodeContrast),
SupportsColorTemperature = vcpCodeInts.Contains(VcpCodeSelectColorPreset),
SupportsVolume = vcpCodeInts.Contains(VcpCodeVolume),
SupportsBrightness = vcpCodeInts.Contains(NativeConstants.VcpCodeBrightness),
SupportsContrast = vcpCodeInts.Contains(NativeConstants.VcpCodeContrast),
SupportsColorTemperature = vcpCodeInts.Contains(NativeConstants.VcpCodeSelectColorPreset),
SupportsVolume = vcpCodeInts.Contains(NativeConstants.VcpCodeVolume),
CapabilitiesStatus = "available",
};
}