ViewShift: Display Renumbering Bug Fix
Fixed a nasty initialization bug today that was breaking baseline restoration when display numbering shifted on restart.
The scenario: You have 3 displays. You shut down with only the main display active (the other two off). When you restart with all 3 displays on, ViewShift fails silently to restore the baseline and just extends to whatever was last active. Wrong state, wrong setup.
The Root Cause
Windows dynamically assigns display device names (DISPLAY1, DISPLAY2, DISPLAY3, etc.) based on what's enumerated at boot time. When some displays are inactive:
- You shut down with 1 display active (ultrawide)
- ViewShift stores the baseline with
device_name: "\\.\DISPLAY1",device_name: "\\.\DISPLAY2",device_name: "\\.\DISPLAY3" - On restart with 2 inactive displays...Windows skips them during enumeration
- The remaining display gets DISPLAY1, next gets DISPLAY3 (not DISPLAY2), etc.
- Baseline restoration tries to apply to old device names that no longer exist
- The CCD API silently falls back to extending, instead of restoring the saved config
The baseline data was being saved correctly (it includes both device_name AND friendly_name from the monitor EDID), but the restoration logic wasn't using friendly_name as a fallback.
The Fix
Added a new function map_baseline_to_current_hardware() in ccd.py that remaps baseline displays to current hardware by matching friendly_name (EDID, which is stable):
def map_baseline_to_current_hardware(baseline_displays: list[dict]) -> list[dict]:
"""
Remap baseline displays to current hardware by matching friendly_name (EDID).
If a baseline display's device_name no longer exists, tries to find it by friendly_name.
Returns updated baseline with current device_names, or original if no matches found.
"""
available = enumerate_available_displays()
friendly_to_gdi = {d.friendly_name: d.gdi_name for d in available if d.friendly_name}
remapped = []
for baseline_disp in baseline_displays:
old_device = baseline_disp.get("device_name")
friendly = baseline_disp.get("friendly_name", "")
# Check if old device_name still exists
available_gdi = {d.gdi_name for d in available}
if old_device in available_gdi:
remapped.append(baseline_disp)
logger.debug("Baseline display %s unchanged", friendly)
elif friendly and friendly in friendly_to_gdi:
# Device was renumbered, remap by friendly_name
new_device = friendly_to_gdi[friendly]
remapped_disp = dict(baseline_disp)
remapped_disp["device_name"] = new_device
remapped.append(remapped_disp)
logger.info("Baseline display '%s' remapped: %s → %s", friendly, old_device, new_device)
else:
remapped.append(baseline_disp)
logger.warning("Baseline display '%s' not found", friendly)
return remapped
Then updated both:
populate_cache_from_baseline()— calls remap before extending to displaysbuild_baseline_scene()instore.py— calls remap before building the restoration scene
How It Works Now
On startup with renumbered displays:
- Load baseline (device_name: DISPLAY2, friendly_name: "HKC")
- Call
map_baseline_to_current_hardware(baseline) - Function queries current hardware, builds
{"HKC": "\\.\DISPLAY3"}mapping - Detects old DISPLAY2 no longer exists
- Matches by friendly_name → finds new device is DISPLAY3
- Returns remapped baseline with correct current device_names
- Baseline restoration now uses correct DISPLAY numbers
- All 3 displays come online in saved positions
Code Changes
ccd.py: +48 lines (newmap_baseline_to_current_hardware()function)store.py: +2 lines (import, call remap before building scene)- Updated
populate_cache_from_baseline()to use remapping
Tests passed — imports check out, no circular dependencies.
Testing Plan
To verify:
- Set baseline with all 3 displays active
- Shut down with only ultrawide on (others off)
- Restart with all 3 displays on
- Watch logs: should see "Baseline display 'HKC' remapped: \.\DISPLAY2 → \.\DISPLAY3"
- All displays should restore to saved positions (not just extend)
What This Fixes
✅ Baseline restoration now works regardless of display enumeration order ✅ Stable matching by monitor EDID (friendly_name) instead of device number ✅ Graceful fallback if hardware changes (logs warning, keeps original if no match found) ✅ No user action needed — transparent remap on startup
This is a critical fix for real-world multi-display setups where not all displays are always active.
Logs now show which displays are being remapped. Good diagnostics for future debugging.