fix(display): stable per-display keys so refresh/HDR/resolution prefs stop resetting#32
Merged
Merged
Conversation
… stop resetting Per-display settings were keyed by the monitor's DevicePath, which Windows sometimes reports empty (capture cards, some HDMI/TV targets, transient driver state). When that happened, the code minted a fresh default DisplayPreference under the fallback key (FriendlyName|GdiDeviceName) — silently resetting saved settings, e.g. a Fixed 240 Hz refresh target back to "Maximum". This also left duplicate entries behind (the same monitor saved under two keys). - Add DisplayPreferenceResolver: resolves a display's prefs by StableKey and, on a miss, reuses an existing entry for the same physical monitor by re-keying it — but only when the label maps to exactly one active monitor, so two identical panels never share a pref block. Falls back to a default otherwise. - Add DedupeDisplays migration: collapses value-identical duplicate entries (keeping the real DevicePath key), run from ConfigStore.Load so old configs self-heal. - Wire the resolver into RefreshRateMonitor, HdrMonitor, ResolutionMonitor and SettingsWindow.LoadDisplays. - Harden the Fixed-Hz target: always include the saved FixedHz in the Settings dropdown even when the panel is momentarily capped low, so opening Settings during a driver glitch can't drop the target. - Add DisplayPreferenceResolverTests (7 cases). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Comment on lines
+63
to
+69
| foreach (var kv in displays) | ||
| { | ||
| if (kv.Value is null || kv.Value.DisplayLabel != label) continue; | ||
| if (activeKeys.Contains(kv.Key)) continue; // belongs to another active display | ||
| if (matchKey is not null) { ambiguous = true; break; } | ||
| matchKey = kv.Key; | ||
| } |
Comment on lines
+106
to
+115
| foreach (var sameValue in byValue) | ||
| { | ||
| var entries = sameValue.ToList(); | ||
| if (entries.Count < 2) continue; // nothing to collapse | ||
|
|
||
| var canonical = PickCanonical(entries.Select(e => e.Key)); | ||
| foreach (var e in entries) | ||
| if (!string.Equals(e.Key, canonical, StringComparison.Ordinal)) | ||
| displays.Remove(e.Key); | ||
| } |
Comment on lines
+112
to
+114
| foreach (var e in entries) | ||
| if (!string.Equals(e.Key, canonical, StringComparison.Ordinal)) | ||
| displays.Remove(e.Key); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Per-display settings (refresh rate, HDR, resolution) are keyed by the monitor's
DevicePath. Windows sometimes reports that empty — capture cards, some HDMI/TV targets, or transient driver state — and the code then minted a fresh defaultDisplayPreferenceunder the fallback key (FriendlyName|GdiDeviceName). Effects:This is also the latent risk behind the refresh-rate-notification gap: a panel temporarily capped low by a driver glitch could lose its Fixed target.
Changes
DisplayPreferenceResolverResolve(...): on a key miss, reuses an existing entry for the same physical monitor by re-keying it onto the currentStableKey— only when the label maps to exactly one active monitor, so two identical panels never share a pref block. Falls back to a default otherwise.DedupeDisplays(...): collapses value-identical duplicate entries (keeps the real DevicePath key). Run fromConfigStore.Load, so existing configs self-heal.RefreshRateMonitor,HdrMonitor,ResolutionMonitor, andSettingsWindow.LoadDisplays.FixedHzis always included in the Settings dropdown even when the panel is momentarily capped low, so opening Settings during a glitch can't drop it.DisplayPreferenceResolverTests(7 cases — exact hit, DevicePath-disappeared re-key, unknown display, identical-monitor ambiguity, dedupe collapse, dedupe-keeps-differing).Verification
dotnet build— 0 warnings (TreatWarningsAsErrors), 0 errors.dotnet test— 114 passed, 0 failed.🤖 Generated with Claude Code