mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 19:57:57 +01:00
Refactor and enhance monitor management system
Refactored namespaces to improve modularity, including moving `PowerDisplay.Native` to `PowerDisplay.Common.Drivers`. Introduced the `IMonitorData` interface for better abstraction of monitor hardware data. Replaced `ColorTemperature` with `ColorTemperatureVcp` for precise VCP-based color temperature control, adding utilities for Kelvin conversion. Enhanced monitor state management with a new `MonitorStateFile` for JSON persistence and updated `MonitorStateManager` for debounced saves. Added `MonitorMatchingHelper` for consistent monitor identification and `ProfileHelper` for profile management operations. Refactored P/Invoke declarations into helper classes, updated UI bindings for `ColorTemperatureVcp`, and improved logging for better runtime visibility. Removed redundant code, added new utility classes (`MonitorValueConverter`, `MonitorMatchingHelper`), and ensured backward compatibility. These changes improve code organization, maintainability, and extensibility while aligning with hardware-level control standards.
This commit is contained in:
@@ -25,6 +25,7 @@ using Microsoft.PowerToys.Settings.UI.SerializationContext;
|
||||
using Microsoft.PowerToys.Settings.UI.Services;
|
||||
using PowerDisplay.Common.Models;
|
||||
using PowerDisplay.Common.Services;
|
||||
using PowerDisplay.Common.Utils;
|
||||
using PowerToys.Interop;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
@@ -216,17 +217,13 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generate a unique key for monitor matching based on hardware ID and internal name
|
||||
/// Generate a unique key for monitor matching based on hardware ID and internal name.
|
||||
/// Uses shared MonitorMatchingHelper from PowerDisplay.Lib for consistency.
|
||||
/// </summary>
|
||||
private string GetMonitorKey(MonitorInfo monitor)
|
||||
private static string GetMonitorKey(MonitorInfo monitor)
|
||||
{
|
||||
// Use hardware ID if available, otherwise fall back to internal name
|
||||
if (!string.IsNullOrEmpty(monitor.HardwareId))
|
||||
{
|
||||
return monitor.HardwareId;
|
||||
}
|
||||
|
||||
return monitor.InternalName ?? monitor.Name ?? string.Empty;
|
||||
// Use shared helper for consistent monitor matching logic
|
||||
return MonitorMatchingHelper.GetMonitorKey(monitor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -344,7 +341,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
_settings.Properties.PendingColorTemperatureOperation = new ColorTemperatureOperation
|
||||
{
|
||||
MonitorId = monitorInternalName,
|
||||
ColorTemperature = colorTemperature,
|
||||
ColorTemperatureVcp = colorTemperature,
|
||||
};
|
||||
|
||||
// Save settings to persist the operation
|
||||
|
||||
Reference in New Issue
Block a user