diff --git a/src/modules/powerdisplay/PowerDisplay.Lib/Drivers/DDC/MonitorDiscoveryHelper.cs b/src/modules/powerdisplay/PowerDisplay.Lib/Drivers/DDC/MonitorDiscoveryHelper.cs index 9df0966910..2bdc864b31 100644 --- a/src/modules/powerdisplay/PowerDisplay.Lib/Drivers/DDC/MonitorDiscoveryHelper.cs +++ b/src/modules/powerdisplay/PowerDisplay.Lib/Drivers/DDC/MonitorDiscoveryHelper.cs @@ -24,27 +24,6 @@ namespace PowerDisplay.Common.Drivers.DDC { } - /// - /// Get monitor device ID - /// - public unsafe string GetMonitorDeviceId(IntPtr hMonitor) - { - try - { - var monitorInfo = new MONITORINFOEX { CbSize = (uint)sizeof(MonitorInfoEx) }; - if (GetMonitorInfo(hMonitor, ref monitorInfo)) - { - return monitorInfo.GetDeviceName() ?? string.Empty; - } - } - catch - { - // Silent failure - } - - return string.Empty; - } - /// /// Get physical monitors for a logical monitor. /// Filters out any monitors with NULL handles (Windows API bug workaround). diff --git a/src/modules/powerdisplay/PowerDisplay.Lib/Drivers/NativeStructures.cs b/src/modules/powerdisplay/PowerDisplay.Lib/Drivers/NativeStructures.cs index 51df5a84e9..590d613df6 100644 --- a/src/modules/powerdisplay/PowerDisplay.Lib/Drivers/NativeStructures.cs +++ b/src/modules/powerdisplay/PowerDisplay.Lib/Drivers/NativeStructures.cs @@ -150,39 +150,6 @@ namespace PowerDisplay.Common.Drivers return new string((char*)ptr); } } - - /// - /// Helper method to get device string as string - /// - public readonly string GetDeviceString() - { - fixed (ushort* ptr = DeviceString) - { - return new string((char*)ptr); - } - } - - /// - /// Helper method to get device ID as string - /// - public readonly string GetDeviceID() - { - fixed (ushort* ptr = DeviceID) - { - return new string((char*)ptr); - } - } - - /// - /// Helper method to get device key as string - /// - public readonly string GetDeviceKey() - { - fixed (ushort* ptr = DeviceKey) - { - return new string((char*)ptr); - } - } } /// diff --git a/src/modules/powerdisplay/PowerDisplay.Lib/Models/VcpFeatureValue.cs b/src/modules/powerdisplay/PowerDisplay.Lib/Models/VcpFeatureValue.cs index 006c3153fb..a7d8b3a732 100644 --- a/src/modules/powerdisplay/PowerDisplay.Lib/Models/VcpFeatureValue.cs +++ b/src/modules/powerdisplay/PowerDisplay.Lib/Models/VcpFeatureValue.cs @@ -13,27 +13,27 @@ namespace PowerDisplay.Common.Models public readonly struct VcpFeatureValue { /// - /// Current value + /// Gets current value /// public int Current { get; } /// - /// Minimum value + /// Gets minimum value /// public int Minimum { get; } /// - /// Maximum value + /// Gets maximum value /// public int Maximum { get; } /// - /// Whether the value information is valid + /// Gets a value indicating whether whether the value information is valid /// public bool IsValid { get; } /// - /// Timestamp when the value information was obtained + /// Gets timestamp when the value information was obtained /// public DateTime Timestamp { get; } @@ -52,7 +52,7 @@ namespace PowerDisplay.Common.Models } /// - /// Creates invalid value information + /// Gets creates invalid value information /// public static VcpFeatureValue Invalid => new(-1, -1, -1); @@ -69,20 +69,6 @@ namespace PowerDisplay.Common.Models return (int)Math.Round((double)(Current - Minimum) * 100 / (Maximum - Minimum)); } - /// - /// Creates raw value from percentage - /// - public int FromPercentage(int percentage) - { - if (!IsValid) - { - return -1; - } - - percentage = Math.Clamp(percentage, 0, 100); - return Minimum + (int)Math.Round((double)(Maximum - Minimum) * percentage / 100); - } - public override string ToString() { return IsValid ? $"{Current}/{Maximum} ({ToPercentage()}%)" : "Invalid"; diff --git a/src/modules/powerdisplay/PowerDisplay.Lib/Utils/LockedDictionary.cs b/src/modules/powerdisplay/PowerDisplay.Lib/Utils/LockedDictionary.cs index 32ceec5006..93000dbcdb 100644 --- a/src/modules/powerdisplay/PowerDisplay.Lib/Utils/LockedDictionary.cs +++ b/src/modules/powerdisplay/PowerDisplay.Lib/Utils/LockedDictionary.cs @@ -22,20 +22,6 @@ namespace PowerDisplay.Common.Utils private readonly Dictionary _dictionary = new(); private readonly object _lock = new(); - /// - /// Gets the number of key/value pairs in the dictionary. - /// - public int Count - { - get - { - lock (_lock) - { - return _dictionary.Count; - } - } - } - /// /// Tries to get the value associated with the specified key. /// @@ -50,73 +36,6 @@ namespace PowerDisplay.Common.Utils } } - /// - /// Gets the value associated with the specified key, or the default value if not found. - /// - /// The key to locate. - /// The value if found; otherwise, the default value. - public TValue? GetValueOrDefault(TKey key) - { - lock (_lock) - { - return _dictionary.TryGetValue(key, out var value) ? value : default; - } - } - - /// - /// Adds or updates a key/value pair. - /// - /// The key to add or update. - /// The value to associate with the key. - public void AddOrUpdate(TKey key, TValue value) - { - lock (_lock) - { - _dictionary[key] = value; - } - } - - /// - /// Gets the value for the key if it exists; otherwise, adds the value using the provided factory. - /// - /// The key to locate or add. - /// The factory function to create a new value if the key doesn't exist. - /// The existing or newly created value. - public TValue GetOrAdd(TKey key, Func valueFactory) - { - lock (_lock) - { - if (_dictionary.TryGetValue(key, out var existingValue)) - { - return existingValue; - } - - var newValue = valueFactory(key); - _dictionary[key] = newValue; - return newValue; - } - } - - /// - /// Tries to remove the value associated with the specified key. - /// - /// The key to remove. - /// When this method returns, contains the removed value if found; otherwise, the default value. - /// True if the key was found and removed; otherwise, false. - public bool TryRemove(TKey key, out TValue? value) - { - lock (_lock) - { - if (_dictionary.TryGetValue(key, out value)) - { - _dictionary.Remove(key); - return true; - } - - return false; - } - } - /// /// Removes all key/value pairs from the dictionary. /// @@ -128,19 +47,6 @@ namespace PowerDisplay.Common.Utils } } - /// - /// Checks if the dictionary contains the specified key. - /// - /// The key to check. - /// True if the key exists; otherwise, false. - public bool ContainsKey(TKey key) - { - lock (_lock) - { - return _dictionary.ContainsKey(key); - } - } - /// /// Gets a snapshot of all values in the dictionary. /// Returns a copy to ensure thread safety. @@ -154,32 +60,6 @@ namespace PowerDisplay.Common.Utils } } - /// - /// Gets a snapshot of all keys in the dictionary. - /// Returns a copy to ensure thread safety. - /// - /// A list containing copies of all keys. - public List GetKeysSnapshot() - { - lock (_lock) - { - return new List(_dictionary.Keys); - } - } - - /// - /// Gets a snapshot of all key/value pairs in the dictionary. - /// Returns a copy to ensure thread safety. - /// - /// A dictionary containing copies of all key/value pairs. - public Dictionary GetSnapshot() - { - lock (_lock) - { - return new Dictionary(_dictionary); - } - } - /// /// Executes an action within the lock, providing the internal dictionary for complex operations. /// Use this for multi-step transactions that need to be atomic. diff --git a/src/modules/powerdisplay/PowerDisplay.Lib/Utils/MonitorFeatureHelper.cs b/src/modules/powerdisplay/PowerDisplay.Lib/Utils/MonitorFeatureHelper.cs deleted file mode 100644 index a470a47d43..0000000000 --- a/src/modules/powerdisplay/PowerDisplay.Lib/Utils/MonitorFeatureHelper.cs +++ /dev/null @@ -1,112 +0,0 @@ -// Copyright (c) Microsoft Corporation -// The Microsoft Corporation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.Collections.Generic; -using System.Globalization; -using PowerDisplay.Common.Drivers; - -namespace PowerDisplay.Common.Utils -{ - /// - /// Unified helper class for parsing monitor feature support from VCP capabilities. - /// This eliminates duplicate VCP parsing logic across PowerDisplay.exe and Settings.UI. - /// - public static class MonitorFeatureHelper - { - /// - /// Result of parsing monitor feature support from VCP capabilities - /// - public readonly struct FeatureSupportResult - { - public bool SupportsBrightness { get; init; } - - public bool SupportsContrast { get; init; } - - public bool SupportsColorTemperature { get; init; } - - public bool SupportsVolume { get; init; } - - public bool SupportsInputSource { get; init; } - - public string CapabilitiesStatus { get; init; } - - public static FeatureSupportResult Unavailable => new() - { - SupportsBrightness = false, - SupportsContrast = false, - SupportsColorTemperature = false, - SupportsVolume = false, - SupportsInputSource = false, - CapabilitiesStatus = "unavailable", - }; - } - - /// - /// Parse feature support from a list of VCP code strings. - /// This is the single source of truth for determining monitor capabilities. - /// - /// List of VCP codes as strings (e.g., "0x10", "10", "0x12") - /// Raw capabilities string, used to determine availability status - /// Feature support result - public static FeatureSupportResult ParseFeatureSupport(IReadOnlyList? vcpCodes, string? capabilitiesRaw) - { - // Check capabilities availability - if (string.IsNullOrEmpty(capabilitiesRaw)) - { - return FeatureSupportResult.Unavailable; - } - - // Convert all VCP codes to integers for comparison - var vcpCodeInts = ParseVcpCodesToIntegers(vcpCodes); - - // Determine feature support based on VCP codes - return new FeatureSupportResult - { - SupportsBrightness = vcpCodeInts.Contains(NativeConstants.VcpCodeBrightness), - SupportsContrast = vcpCodeInts.Contains(NativeConstants.VcpCodeContrast), - SupportsColorTemperature = vcpCodeInts.Contains(NativeConstants.VcpCodeSelectColorPreset), - SupportsVolume = vcpCodeInts.Contains(NativeConstants.VcpCodeVolume), - SupportsInputSource = vcpCodeInts.Contains(NativeConstants.VcpCodeInputSource), - CapabilitiesStatus = "available", - }; - } - - /// - /// Parse VCP codes from string list to integer set - /// Handles both hex formats: "0x10" and "10" - /// - private static HashSet ParseVcpCodesToIntegers(IReadOnlyList? vcpCodes) - { - var result = new HashSet(); - - if (vcpCodes == null) - { - return result; - } - - foreach (var code in vcpCodes) - { - if (string.IsNullOrWhiteSpace(code)) - { - continue; - } - - // Remove "0x" prefix if present and parse as hex - var cleanCode = code.Trim(); - if (cleanCode.StartsWith("0x", StringComparison.OrdinalIgnoreCase)) - { - cleanCode = cleanCode.Substring(2); - } - - if (int.TryParse(cleanCode, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out int codeInt)) - { - result.Add(codeInt); - } - } - - return result; - } - } -} diff --git a/src/modules/powerdisplay/PowerDisplay.Lib/Utils/MonitorValueConverter.cs b/src/modules/powerdisplay/PowerDisplay.Lib/Utils/MonitorValueConverter.cs index 69cf022b81..e4d5980691 100644 --- a/src/modules/powerdisplay/PowerDisplay.Lib/Utils/MonitorValueConverter.cs +++ b/src/modules/powerdisplay/PowerDisplay.Lib/Utils/MonitorValueConverter.cs @@ -2,9 +2,6 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Collections.Generic; -using PowerDisplay.Common.Drivers; - namespace PowerDisplay.Common.Utils { /// @@ -13,49 +10,6 @@ namespace PowerDisplay.Common.Utils /// public static class MonitorValueConverter { - /// - /// Standard VCP color temperature preset to Kelvin value mapping. - /// Based on MCCS (Monitor Control Command Set) standard. - /// - private static readonly Dictionary VcpToKelvinMap = new() - { - [0x03] = 4000, - [0x04] = 5000, - [0x05] = 6500, - [0x06] = 7500, - [0x08] = 9300, - [0x09] = 10000, - [0x0A] = 11500, - }; - - /// - /// Converts a VCP color temperature preset value to approximate Kelvin temperature. - /// - /// The VCP preset value (e.g., 0x05). - /// The Kelvin temperature (e.g., 6500), or 0 if unknown. - public static int VcpToKelvin(int vcpValue) - { - return VcpToKelvinMap.TryGetValue(vcpValue, out var kelvin) ? kelvin : 0; - } - - /// - /// Formats a VCP color temperature value as a Kelvin string for display. - /// - /// The VCP preset value (e.g., 0x05). - /// Formatted string like "6500K" or "Unknown (0x05)" if not a standard preset. - public static string FormatVcpAsKelvin(int vcpValue) - { - var kelvin = VcpToKelvin(vcpValue); - if (kelvin > 0) - { - return $"{kelvin}K"; - } - - // Use VcpValueNames for special presets like sRGB, User 1, etc. - var name = VcpValueNames.GetName(NativeConstants.VcpCodeSelectColorPreset, vcpValue); - return name ?? $"Unknown (0x{vcpValue:X2})"; - } - /// /// Formats a VCP color temperature value as a display name with preset name. /// @@ -65,26 +19,5 @@ namespace PowerDisplay.Common.Utils { return ColorTemperatureHelper.FormatColorTemperatureDisplayName(vcpValue); } - - /// - /// Gets the preset name for a VCP color temperature value. - /// - /// The VCP preset value (e.g., 0x05). - /// Preset name like "6500K", "sRGB", or null if unknown. - public static string? GetColorTemperaturePresetName(int vcpValue) - { - return VcpValueNames.GetName(NativeConstants.VcpCodeSelectColorPreset, vcpValue); - } - - /// - /// Checks if a VCP value represents a known color temperature preset. - /// - /// The VCP preset value. - /// True if the value is a known preset. - public static bool IsKnownColorTemperaturePreset(int vcpValue) - { - return VcpToKelvinMap.ContainsKey(vcpValue) || - VcpValueNames.GetName(NativeConstants.VcpCodeSelectColorPreset, vcpValue) != null; - } } } diff --git a/src/modules/powerdisplay/PowerDisplay/Assets/PowerDisplay/PowerDisplay.ico b/src/modules/powerdisplay/PowerDisplay/Assets/PowerDisplay.ico similarity index 100% rename from src/modules/powerdisplay/PowerDisplay/Assets/PowerDisplay/PowerDisplay.ico rename to src/modules/powerdisplay/PowerDisplay/Assets/PowerDisplay.ico diff --git a/src/modules/powerdisplay/PowerDisplay/PowerDisplay.csproj b/src/modules/powerdisplay/PowerDisplay/PowerDisplay.csproj index 1bb02378a9..42ab688fc5 100644 --- a/src/modules/powerdisplay/PowerDisplay/PowerDisplay.csproj +++ b/src/modules/powerdisplay/PowerDisplay/PowerDisplay.csproj @@ -7,7 +7,7 @@ WinExe PowerDisplay app.manifest - Assets\PowerDisplay\PowerDisplay.ico + Assets\PowerDisplay.ico x64;ARM64 true true