Skip to content

fix(display_device): restore Windows CCD database persistence and add opt-in display-loss reapply - #6189

Open
pperanich wants to merge 3 commits into
SunshineStream:masterfrom
pperanich:fix/windows-display-persistence-and-reapply
Open

pperanich wants to merge 3 commits into
SunshineStream:masterfrom
pperanich:fix/windows-display-persistence-and-reapply

Conversation

@pperanich

Copy link
Copy Markdown

Description

This PR restores Windows CCD display-database persistence (save_to_database = true) for libdisplaydevice and adds an opt-in setting (dd_reapply_on_display_loss, disabled by default) to reapply the active stream's display configuration if Windows externally deactivates or drops the configured display mid-stream.

Summary of Changes

  1. Restore save_to_database = true on Windows (src/display_device.cpp):
  2. Opt-in mid-stream topology re-enforcement (dd_reapply_on_display_loss):
    • Added config::video_t::dd_t::reapply_on_display_loss (src/config.h, src/config.cpp, default false / disabled).
    • Tracked the active stream's SingleDisplayConfiguration in src/display_device.cpp (cleared on revert, reset, init, and deinit) and added display_device::reapply_configuration_on_display_loss() with a 2000 ms cooldown and VerifyOnly guard.
    • Extracted video::refresh_displays_with_callbacks() in src/video.cpp so that when the previously active display disappears mid-stream, Sunshine checks for a renumbered output_name and—if dd_reapply_on_display_loss is enabled—reapplies the active display configuration and re-enumerates before falling back to index 0.
    • Added the Windows-only Web UI checkbox (DisplayDeviceOptions.vue, shown when dd_configuration_option is not disabled or verify_only), default entry in config_tabs.json, English localization in en.json, and documentation in docs/configuration.md.

Screenshot

Issues Fixed or Closed

Roadmap Issues

Testing

Automated Tests & Checks

  • Unit / integration tests added:
    • tests/unit/test_config.cpp: default value and enabled/disabled parsing for dd_reapply_on_display_loss.
    • tests/unit/test_display_device.cpp: DisplayDeviceReapply tests covering inactive/VerifyOnly/post-revert skips, active reapply, cooldown gating, and apply failure handling.
    • tests/unit/test_video.cpp: VideoRefreshDisplaysTest (10 cases) covering display preservation, renumbered output recovery, fallback when disabled, reapply recovery on display loss and transient empty enumeration, reapply failure fallback, and initial selection.
    • tests/web/Configuration.test.js: Vitest test verifying dd_reapply_on_display_loss visibility and toggle behavior across verify_only vs active preparation modes.
  • Native Windows MSYS2 UCRT64 build & tests (-DBUILD_WERROR=ON):
    • Built all 282/282 targets (sunshine.exe, tools, Web UI, test_sunshine.exe) and passed the Windows ldd linkage check cleanly.
    • test_sunshine.exe --gtest_filter="DisplayDevice*:VideoRefreshDisplaysTest.*:ConfigDefaultsTest.*:ConfigPersistenceTest.*:ConfigConsistencyTest.*:LocaleConsistencyTest.*": 199/199 passed.
  • Linux test_sunshine & gcov coverage:
    • 199/199 passed across the same 13 test suites, with 100% line coverage on display_device::reapply_configuration_on_display_loss() and video::refresh_displays_with_callbacks().
  • Web tests (npm test):
    • 24/24 in tests/web/Configuration.test.js and 23/23 in tests/web/localization_files.test.js passed (219/220 total; the 1 failure is an unrelated pre-existing Windows CRLF split in tests/web/ExternalAudio.test.js:63).
  • Doxygen & formatting:
    • Strict Dockle/Doxygen (WARN_AS_ERROR = YES, full repo with _WIN32 predefined): 0 warnings.
    • uv run --locked lb-update-clang-format: PASS with zero unrelated diffs.

Live Windows Hardware Validation

Tested on Windows 11 Pro (AMD Radeon RX 6800 + DisplayPort 4K@144Hz HDR physical monitor + persistent 3024×1890@120Hz HDR-capable virtual display) built with the companion libdisplaydevice PR linked in:

  • save_to_database = true with dd_reapply_on_display_loss = disabled (default):
    • SDR (2m23s) and HDR (2m29s) streams with dd_configuration_option = ensure_only_display survived 5 DisplayPort standby HPD cycles each (between +21s and +59s) with zero drops off the virtual display.
  • Opt-in dd_reapply_on_display_loss = enabled:
    • Toggled via Web UI (persisted cleanly to sunshine.conf). Simulating an external SetDisplayConfig switch back to the physical monitor mid-stream triggered automatic reapply and restored the virtual display (3024×1890 @ 120Hz HDR) in 455 ms, followed by clean revert to physical-only on disconnect.
  • Disconnect revert after mid-stream display deactivation / hot-unplug (dd_reapply_on_display_loss = disabled):
    • Reverted cleanly to physical-only and deleted display_device.state with zero hdrStateGuardFn / Extended-mode fallback errors.

Type of Change

  • feat: New feature (non-breaking change which adds functionality)
  • fix: Bug fix (non-breaking change which fixes an issue)
  • docs: Documentation only changes
  • style: Changes that do not affect the meaning of the code (white-space, formatting, missing semicolons, etc.)
  • refactor: Code change that neither fixes a bug nor adds a feature
  • perf: Code change that improves performance
  • test: Adding missing tests or correcting existing tests
  • build: Changes that affect the build system or external dependencies
  • ci: Changes to CI configuration files and scripts
  • chore: Other changes that don't modify src or test files
  • revert: Reverts a previous commit
  • BREAKING CHANGE: Introduces a breaking change (can be combined with any type above)

Checklist

  • Code follows the style guidelines of this project
  • Code has been self-reviewed
  • Code has been commented, particularly in hard-to-understand areas
  • Code docstring/documentation-blocks for new or existing methods/components have been added or updated
  • Tests have been added or updated for new or modified functionality, including regression tests for bug fixes

AI Usage

See our AI usage policy.

  • AI tools were used while preparing this PR

This pull request was generated by Antigravity (Gemini, high thinking level)

… opt-in display-loss reapply

Pass save_to_database = true to WinDisplayDevice on Windows so display wake, session switches, and DisplayPort standby/HPD resets do not revert the active stream topology (fixes SunshineStream#5942, paired with libdisplaydevice database-backed undock/redock recovery).

Also add the opt-in dd_reapply_on_display_loss setting (disabled by default, Windows-only) to reapply the active display configuration with a cooldown if Windows externally drops the configured display mid-stream.
@pperanich

Copy link
Copy Markdown
Author

This pull request was generated by Antigravity (Gemini, high thinking level)

…leanup

Extract find_display_index, select_display_index, and try_reapply_displays in src/video.cpp to reduce cognitive complexity and nesting depth, use explicit std::optional::has_value() checks, consolidate active display-config resets into DD_DATA.clear_active_config(), and add fallback index coverage in tests/unit/test_video.cpp.
@sonarqubecloud

Copy link
Copy Markdown

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows: display mode not kept and revert fails when displays are powered off (regression from #5625)

1 participant