Skip to content

fix(macos): honor cursor visibility toggle - #6214

Open
Jac0b-Shi wants to merge 2 commits into
SunshineStream:masterfrom
Jac0b-Shi:pr/macos-capture-cursor-visibility
Open

Jac0b-Shi wants to merge 2 commits into
SunshineStream:masterfrom
Jac0b-Shi:pr/macos-capture-cursor-visibility

Conversation

@Jac0b-Shi

@Jac0b-Shi Jac0b-Shi commented Dec 2, 2026 •

Copy link
Copy Markdown

Description

Fixes an issue where the macOS capture backends (ScreenCaptureKit and AVFoundation) ignored the cursor visibility toggle (Ctrl+Alt+Shift+N), always starting with the cursor visible and never reacting to toggles while a stream was running.

Changes

  • Thread-safe cursor flag across backends: Converted display_cursor to std::atomic<bool> with a CAS toggle in input.cpp, and updated capture() signatures across all platform backends and tests so capture threads can safely read the flag without data races. (This is why non-macOS backend files appear in the diff — no functional changes were made to Windows/Linux capture behavior.)
  • ScreenCaptureKit: Applies the initial display_cursor state to showsCursor when starting the stream, and pushes subsequent changes via updateConfiguration, coalescing updates so only one configuration change is in flight at a time.
  • AVFoundation: Applies the initial display_cursor state to capturesCursor on the screen input, and re-checks the flag while waiting for frames so toggles still take effect on a static screen.

Screenshot

Not applicable — no UI changes.

Issues Fixed or Closed

No linked issue.

Roadmap Issues

Not applicable.

Testing

Automated

Full test suite passed on macOS: 879 passed, 8 skipped. App and Web UI built cleanly, and the modified translation units compile without warnings.

New regression coverage in tests/unit/platform/macos/test_sc_capture_loop.mm:

  • SamplesCursorAtStartupAndOnPollsWithoutFrames — verifies the loop passes the startup state to start() and re-samples the flag on every poll, including polls that deliver no frame.
  • SerializesCursorUpdatesAndPreservesStreamConfiguration — verifies duplicate requests are coalesced while an update is in flight, that other configuration fields survive the update, and that updates are ignored after the stream is stopped.
  • FailedCursorUpdateWakesCaptureForReinitialization — verifies a rejected configuration update marks the stream failed and wakes the capture loop so the display gets rebuilt.
  • KeyboardPassthroughTest.CursorShortcutTogglesSharedCaptureState in tests/unit/test_keyboard.cpp — verifies the shortcut toggles the shared atomic flag and is consumed rather than forwarded.

Manual

The following was verified by hand on physical hardware, not by an automated test.

Local frame capture verification (manually inspected): Captured frames were compared by eye for both backends. ScreenCaptureKit and AVFoundation were each confirmed to hide the cursor and restore it again, and ScreenCaptureKit was additionally confirmed to honor starting in the hidden state, i.e. a stream opened while the toggle was already off begins with no cursor.

End-to-end streaming (manually tested, Windows Moonlight -> macOS Sunshine):

  • Host: macOS 27.2.1, Apple Silicon (M4)
  • Client: Moonlight PC v6.2.0 on Windows
  • Manually verified toggling host cursor visibility in-stream via Ctrl+Alt+Shift+N: cursor hides immediately and reappears on toggle back.
  • Manually verified that reconnecting the Moonlight client (while the Sunshine process keeps running) starts the new stream honoring the in-memory hidden cursor state.
  • Note on expected behavior: the toggle is process-scoped, not persisted. Restarting the Sunshine process resets the flag to visible. This matches every existing platform and is not changed by this PR.

Not covered

  • Windows and Linux builds were not compiled locally. The capture() signature changes touch those backends, so they still need compile verification from GitHub Actions.

Notes

  • CI status: GitHub Actions (CI, common lint, CodeQL) is still action_required — the workflows are waiting on maintainer approval for a first-time contributor, so no job has run yet. The Windows and Linux matrices are the remaining verification for the capture() signature updates.
  • SonarCloud duplication: SonarCloud has already analysed this PR independently of Actions. The 3 new-code issues it raised have been addressed. What remains is only the duplication gate (4.1% on new code, 8 duplicated blocks, threshold is 2% / 0). The 4 lines counted as duplicates are the updated capture() override signatures in kmsgrab.cpp and x11grab.cpp. They now accept the shared atomic cursor flag and sit inside existing duplicated Linux capture loops whose bodies are unchanged. Refactoring those Linux capture loops is intentionally out of scope for this macOS bug fix, so I would rather leave that gate to maintainer judgement than restructure unrelated platform code.
  • Older macOS compatibility: pre-ScreenCaptureKit macOS was not tested on physical hardware; compatibility relies on the existing @available guards and AVFoundation behaviour.

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

AI assistance was used in two stages. The patch itself (the atomic-flag refactor, the cursor update plumbing, and the regression tests) was written by OpenAI Codex (GPT-6.2-sol). The comment and docstring review, formatting checks, local build and full test run on macOS, and this PR description were prepared with DeepSeek Harness (DeepSeek V4.1 Flash).

The code in this pull request was generated by OpenAI Codex, GPT-6.2-sol model

PR preparation and review were assisted by DeepSeek Harness, DeepSeek V4.1 Flash model

@Jac0b-Shi

Jac0b-Shi commented Dec 2, 2026 •

Copy link
Copy Markdown
Author

The code in this pull request was generated by OpenAI Codex, GPT-6.2-sol model

PR preparation and review were assisted by DeepSeek Harness, DeepSeek V4.1 Flash model

The macOS capture backends ignored the cursor visibility state: both
started capturing with the cursor enabled and never reacted to the
toggle while a stream was running.

Convert the shared display_cursor flag to std::atomic<bool> with a
CAS toggle in input handling, updating capture() signatures across
backends so capture threads can safely read it without data races.

On macOS, ScreenCaptureKit sets showsCursor on the initial stream
configuration and pushes later changes via updateConfiguration,
coalescing requests so only one update is in flight; AVFoundation
sets capturesCursor on the screen input and re-reads the flag while
waiting for frames so toggles apply even on a static screen.
@Jac0b-Shi
Jac0b-Shi force-pushed the pr/macos-capture-cursor-visibility branch from a0f47b4 to 84a1d0c Compare December 2, 2026 01:46
@Jac0b-Shi
Jac0b-Shi marked this pull request as ready for review December 2, 2026 01:57

@ReenigneArcher ReenigneArcher left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes for the missing AVFoundation regression coverage described inline. I found no additional functional defects in the current diff, and the cursor bug is still present in the corresponding macOS paths on current master.

Validation: built test_sunshine on macOS with tray support disabled and cached dependencies; all 43 tests in SCCaptureLoop.*, KeyboardPassthroughTest.*, and DisplayHelpers.* passed. git diff --check and clang-format 23.1 checks passed. The proposed AVFoundation test supplied inline was separately compiled and passed. I did not perform end-to-end streaming or compile Windows/Linux.

Checks and merge status: head 84a1d0c4205c5644b8a52fb5bce44f5bf9713cba is mergeable against master (44f9ed981ea80b55648623a37338ed15181b8164). Actions are awaiting maintainer approval, leaving hosted cross-platform verification unavailable. SonarCloud's quality gate currently fails for 3.9% duplication and 8 duplicated blocks on new code; the changed Linux capture-loop hunks contain signature changes only. Read the Docs and the semantic PR check passed.

Review completed by Codex | Model: gpt-6.1-sol | Thinking: xhigh

Comment thread src/platform/macos/av_video.m Resolved
@sonarqubecloud

sonarqubecloud Bot commented Dec 3, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
3.5% Duplication on New Code (required ≤ 2%)
8 Duplicated Blocks on New Code (required ≤ 0)

See analysis details on SonarQube Cloud

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.

2 participants