diff --git a/src/settings-ui/Settings.UI.Library/Models/ColorPresetItem.cs b/src/settings-ui/Settings.UI.Library/Models/ColorPresetItem.cs new file mode 100644 index 0000000000..c99b56f139 --- /dev/null +++ b/src/settings-ui/Settings.UI.Library/Models/ColorPresetItem.cs @@ -0,0 +1,89 @@ +// 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.ComponentModel; +using System.Runtime.CompilerServices; +using System.Text.Json.Serialization; + +#nullable enable + +namespace Microsoft.PowerToys.Settings.UI.Library +{ + /// + /// Represents a color temperature preset item for VCP code 0x14. + /// Used to display available color temperature presets in UI components. + /// This is a local copy maintained in Settings.UI.Library to avoid a dependency on PowerDisplay.Lib. + /// + public partial class ColorPresetItem : INotifyPropertyChanged + { + private int _vcpValue; + private string _displayName = string.Empty; + + /// + /// Initializes a new instance of the class. + /// + public ColorPresetItem() + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The VCP value for the color temperature preset. + /// The display name for UI. + public ColorPresetItem(int vcpValue, string displayName) + { + _vcpValue = vcpValue; + _displayName = displayName; + } + + /// + /// Occurs when a property value changes. + /// + public event PropertyChangedEventHandler? PropertyChanged; + + /// + /// Gets or sets the VCP value for this color temperature preset. + /// + [JsonPropertyName("vcpValue")] + public int VcpValue + { + get => _vcpValue; + set + { + if (_vcpValue != value) + { + _vcpValue = value; + OnPropertyChanged(); + } + } + } + + /// + /// Gets or sets the display name for UI. + /// + [JsonPropertyName("displayName")] + public string DisplayName + { + get => _displayName; + set + { + if (_displayName != value) + { + _displayName = value; + OnPropertyChanged(); + } + } + } + + /// + /// Raises the PropertyChanged event. + /// + /// The name of the property that changed. + protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + } +} diff --git a/src/settings-ui/Settings.UI.Library/Models/CustomVcpValueMapping.cs b/src/settings-ui/Settings.UI.Library/Models/CustomVcpValueMapping.cs new file mode 100644 index 0000000000..72aada9250 --- /dev/null +++ b/src/settings-ui/Settings.UI.Library/Models/CustomVcpValueMapping.cs @@ -0,0 +1,85 @@ +// 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.Text.Json.Serialization; + +namespace Microsoft.PowerToys.Settings.UI.Library +{ + /// + /// Represents a custom name mapping for a VCP code value. + /// Used to override the default VCP value names with user-defined names. + /// This is a local copy maintained in Settings.UI.Library to avoid a dependency on PowerDisplay.Lib. + /// + public class CustomVcpValueMapping + { + /// + /// Gets or sets the VCP code (e.g., 0x14 for color temperature, 0x60 for input source). + /// + [JsonPropertyName("vcpCode")] + public byte VcpCode { get; set; } + + /// + /// Gets or sets the VCP value to map (e.g., 0x11 for HDMI-1). + /// + [JsonPropertyName("value")] + public int Value { get; set; } + + /// + /// Gets or sets the custom name to display instead of the default name. + /// + [JsonPropertyName("customName")] + public string CustomName { get; set; } = string.Empty; + + /// + /// Gets or sets a value indicating whether this mapping applies to all monitors. + /// When true, the mapping is applied globally. When false, only applies to TargetMonitorId. + /// + [JsonPropertyName("applyToAll")] + public bool ApplyToAll { get; set; } = true; + + /// + /// Gets or sets the target monitor ID when ApplyToAll is false. + /// This is the monitor's unique identifier. + /// + [JsonPropertyName("targetMonitorId")] + public string TargetMonitorId { get; set; } = string.Empty; + + /// + /// Gets or sets the target monitor display name (for UI display only, not serialized). + /// + [JsonIgnore] + public string TargetMonitorName { get; set; } = string.Empty; + + /// + /// Gets the display name for the VCP code (for UI display). + /// + [JsonIgnore] + public string VcpCodeDisplayName => $"VCP 0x{VcpCode:X2}"; + + /// + /// Gets the display name for the VCP value. + /// + [JsonIgnore] + public string ValueDisplayName => $"0x{Value:X2}"; + + /// + /// Gets a summary string for display in the UI list. + /// Format: "0xVV → CustomName" or "0xVV → CustomName (MonitorName)" + /// + [JsonIgnore] + public string DisplaySummary + { + get + { + var baseSummary = $"0x{Value:X2} \u2192 {CustomName}"; + if (!ApplyToAll && !string.IsNullOrEmpty(TargetMonitorName)) + { + return $"{baseSummary} ({TargetMonitorName})"; + } + + return baseSummary; + } + } + } +} diff --git a/src/settings-ui/Settings.UI.Library/MonitorInfo.cs b/src/settings-ui/Settings.UI.Library/MonitorInfo.cs index f53f682d3d..3e47d321bd 100644 --- a/src/settings-ui/Settings.UI.Library/MonitorInfo.cs +++ b/src/settings-ui/Settings.UI.Library/MonitorInfo.cs @@ -8,14 +8,13 @@ using System.Collections.ObjectModel; using System.Linq; using System.Text.Json.Serialization; using Microsoft.PowerToys.Settings.UI.Library.Helpers; -using PowerDisplay.Common.Drivers; -using PowerDisplay.Common.Models; -using PowerDisplay.Common.Utils; namespace Microsoft.PowerToys.Settings.UI.Library { public class MonitorInfo : Observable { + private const byte VcpCodeSelectColorPreset = 0x14; + private string _name = string.Empty; private string _id = string.Empty; private string _communicationMethod = string.Empty; @@ -532,7 +531,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library System.Globalization.NumberStyles.HexNumber, System.Globalization.CultureInfo.InvariantCulture, out int code) && - code == NativeConstants.VcpCodeSelectColorPreset); + code == VcpCodeSelectColorPreset); // No VCP 0x14 or no values if (colorTempVcp == null || colorTempVcp.ValueList == null || colorTempVcp.ValueList.Count == 0) @@ -556,9 +555,10 @@ namespace Microsoft.PowerToys.Settings.UI.Library }) .Where(x => x.VcpValue > 0); - // Use shared helper to compute presets, then convert to nested type for XAML compatibility - var basePresets = ColorTemperatureHelper.ComputeColorPresets(colorTempValues); - var presetList = basePresets.Select(p => new ColorPresetItem(p.VcpValue, p.DisplayName)); + // Compute presets inline (avoiding dependency on PowerDisplay.Lib's ColorTemperatureHelper) + var presetList = colorTempValues + .Select(item => new ColorPresetItem(item.VcpValue, !string.IsNullOrEmpty(item.Name) ? item.Name : "Manufacturer Defined")) + .OrderBy(p => p.VcpValue); return new ObservableCollection(presetList); } @@ -598,8 +598,8 @@ namespace Microsoft.PowerToys.Settings.UI.Library // Current value is not in the preset list - add it at the beginning var displayList = new List(); - // Add current value with "Custom" indicator using shared helper - var displayName = ColorTemperatureHelper.FormatCustomColorTemperatureDisplayName(_colorTemperatureVcp); + // Add current value with "Custom" indicator + var displayName = $"Custom (0x{_colorTemperatureVcp:X2})"; displayList.Add(new ColorPresetItem(_colorTemperatureVcp, displayName)); // Add all supported presets diff --git a/src/settings-ui/Settings.UI.Library/PowerDisplayProperties.cs b/src/settings-ui/Settings.UI.Library/PowerDisplayProperties.cs index 5539daf0fd..cae991fabd 100644 --- a/src/settings-ui/Settings.UI.Library/PowerDisplayProperties.cs +++ b/src/settings-ui/Settings.UI.Library/PowerDisplayProperties.cs @@ -4,7 +4,6 @@ using System.Collections.Generic; using System.Text.Json.Serialization; -using PowerDisplay.Common.Models; using Settings.UI.Library.Attributes; namespace Microsoft.PowerToys.Settings.UI.Library diff --git a/src/settings-ui/Settings.UI.Library/Settings.UI.Library.csproj b/src/settings-ui/Settings.UI.Library/Settings.UI.Library.csproj index 744e42e38c..77ed21cf07 100644 --- a/src/settings-ui/Settings.UI.Library/Settings.UI.Library.csproj +++ b/src/settings-ui/Settings.UI.Library/Settings.UI.Library.csproj @@ -23,7 +23,6 @@ - diff --git a/src/settings-ui/Settings.UI.Library/SettingsSerializationContext.cs b/src/settings-ui/Settings.UI.Library/SettingsSerializationContext.cs index 366f98cd8b..383c724aeb 100644 --- a/src/settings-ui/Settings.UI.Library/SettingsSerializationContext.cs +++ b/src/settings-ui/Settings.UI.Library/SettingsSerializationContext.cs @@ -4,7 +4,6 @@ using System.Collections.Generic; using System.Text.Json.Serialization; -using PowerDisplay.Common.Models; using SettingsUILibrary = Settings.UI.Library; using SettingsUILibraryHelpers = Settings.UI.Library.Helpers; @@ -158,13 +157,6 @@ namespace Microsoft.PowerToys.Settings.UI.Library [JsonSerializable(typeof(PasteAIProviderDefinition))] [JsonSerializable(typeof(System.Collections.ObjectModel.ObservableCollection))] - // PowerDisplay Profile Types (for AOT compatibility) - [JsonSerializable(typeof(PowerDisplayProfile))] - [JsonSerializable(typeof(List))] - [JsonSerializable(typeof(PowerDisplayProfiles))] - [JsonSerializable(typeof(ProfileMonitorSetting))] - [JsonSerializable(typeof(List))] - // IPC Send Message Wrapper Classes (Snd*) [JsonSerializable(typeof(SndAwakeSettings))] [JsonSerializable(typeof(SndCursorWrapSettings))] diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Views/CustomVcpMappingEditorDialog.xaml.cs b/src/settings-ui/Settings.UI/SettingsXAML/Views/CustomVcpMappingEditorDialog.xaml.cs index 915c891ada..428decc8d6 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/Views/CustomVcpMappingEditorDialog.xaml.cs +++ b/src/settings-ui/Settings.UI/SettingsXAML/Views/CustomVcpMappingEditorDialog.xaml.cs @@ -17,6 +17,7 @@ using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using PowerDisplay.Common.Models; using PowerDisplay.Common.Utils; +using CustomVcpValueMapping = Microsoft.PowerToys.Settings.UI.Library.CustomVcpValueMapping; namespace Microsoft.PowerToys.Settings.UI.Views { diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Views/PowerDisplayPage.xaml b/src/settings-ui/Settings.UI/SettingsXAML/Views/PowerDisplayPage.xaml index 218c4e199e..4fdeda3c9f 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/Views/PowerDisplayPage.xaml +++ b/src/settings-ui/Settings.UI/SettingsXAML/Views/PowerDisplayPage.xaml @@ -71,7 +71,7 @@ IsExpanded="{x:Bind ViewModel.HasCustomVcpMappings, Mode=OneWay}" ItemsSource="{x:Bind ViewModel.CustomVcpMappings, Mode=OneWay}"> - +