Skip to content

feat(linux): Portal capture fallback support, misc fixes - #5774

Merged
ReenigneArcher merged 16 commits into
LizardByte:masterfrom
psyke83:portalgrab_fallback
Sep 25, 2026
Merged

ReenigneArcher merged 16 commits into
LizardByte:masterfrom
psyke83:portalgrab_fallback

Conversation

@psyke83

@psyke83 psyke83 commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Description

Add support for fallback capture when Portal capture is selected but a restore token is stale or not yet created.

New flow:

  • User config sets capture = portal.
  • Check for a Portal restore token on disk. If it exists, first verify that Portal capture works by negotiating the existing restore token with a 10 second timeout.
  • If negotiation succeeds, start Portal capture as normal.
  • If negotiation fails within 10 seconds, treat the token as stale, delete and restart Sunshine.
  • If no restore token exists, queue a non-blocking TaskPool task to trigger token negotiation via the XDG dialog that can run concurrently with any other capture method.
  • If Portal cannot be used yet, disregard the 'capture = portal' config and continue probing for other working capture methods.
  • If a fallback capture method succeeded, the user can connect to the session; the WebUI will echo a fatal error to indicate that this is temporary. The user can then confirm the XDG permission dialog, which immediately triggers a Sunshine restart, and subsequent sessions will use actual Portal capture directly.

Minor changes:

  • Increase TaskPool thread count to 2, as the XDG negotiation task can be long-running and blocks input when the pool is single threaded.
  • Promote KWin capture autodetection above Portal, as it is less complicated to set up on supported systems.
  • When Portal capture is selected but a restore token is stale, Sunshine startup can potentially be delayed by ~12 seconds (2 second ping, 10 second timeout for negotiation) until the token is re-negotiated.

Bugfixes:

  • Avoid blocking DBus calls which causes Sunshine to terminate uncleanly if an XDG Remote Desktop dialog is still open during restart/shutdown.
  • Clean up CAP_SYS_ADMIN log spam caused by recent DRM worker thread changes.
  • Clean up legacy CAP_SYS_ADMIN workarounds in Portal and Kwin capture code.
  • Fix KWin autodetection false positives on GNOME.

Screenshot

Screenshot_20260921_205127-1

Issues Fixed or Closed

Roadmap Issues

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
  • Unit tests have been added or updated for any new or modified functionality

AI Usage

See our AI usage policy.

  • None: No AI tools were used in creating this PR
  • Light: AI provided minor assistance (formatting, simple suggestions)
  • Moderate: AI helped with code generation or debugging specific parts
  • Heavy: AI generated most or all of the code changes

@NovaStorm775

Copy link
Copy Markdown

Hi Dude, appreciate your work! Do you think this could fix my issue? 5750

@psyke83

psyke83 commented Sep 23, 2026

Copy link
Copy Markdown
Contributor Author

Hi Dude, appreciate your work! Do you think this could fix my issue? 5750

This PR will change the behaviour (as a stale token will be detected, deleted and trigger a Sunshine restart, vs the current behaviour of a stale token hanging Sunshine), but will most likely not fix the issue itself. When I have some free time I'll check and see if I can reproduce your issue.

@Kishi85

Kishi85 commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

LGTM, also I've not found any issues so far after applying this to my usual test system.

Comment thread docs/troubleshooting.md Outdated
Comment thread src/platform/linux/portalgrab.cpp
@psyke83
psyke83 force-pushed the portalgrab_fallback branch 3 times, most recently from 079996e to 44a5ce9 Compare September 25, 2026 02:25
Add support for fallback capture when Portal capture is selected but a
restore token is stale or not yet created.

New flow:

* User config sets capture = portal.
* Check for a Portal restore token on disk. If it exists, first verify that
  Portal capture works by negotiating the existing restore token with
  a 10 second timeout.
* If negotiation succeeds, start Portal capture as normal.
* If negotiation fails within 10 seconds, treat the token as stale, delete
  and restart Sunshine.
* If no restore token exists, queue a non-blocking TaskPool task to trigger
  token negotiation via the XDG dialog that can run concurrently with any
  other capture method.
* If Portal cannot be used yet, disregard the 'capture = portal' config
  and continue probing for other working capture methods.
* If a fallback capture method succeeded, the user can connect to the session;
  the WebUI will echo a fatal error to indicate that this is temporary. The
  user can then confirm the XDG permission dialog, which immediately
  triggers a Sunshine restart, and subsequent sessions will use actual
  Portal capture directly.

Minor changes:
* Increase TaskPool thread count to 2, as the XDG negotiation task can be
  long-running and blocks input when the pool is single threaded.
* Promote KWin capture autodetection above Portal, as it is less complicated
  to set up on supported systems.
* When Portal capture is selected but a restore token is stale,
  Sunshine startup can potentially be delayed by ~12 seconds (2 second ping,
  10 second timeout for negotiation) until the token is re-negotiated.

Bugfixes:
* Avoid blocking DBus calls which causes Sunshine to terminate uncleanly
  if an XDG Remote Desktop dialog is still open during restart/shutdown.
* Clean up CAP_SYS_ADMIN log spam caused by recent DRM worker thread changes.
* Clean up legacy CAP_SYS_ADMIN workarounds in Portal and Kwin capture code.
* Fix KWin autodetection false positives on GNOME.
@codecov

codecov Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Bundle Report

Bundle size has no change ✅

@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown
Last Updated 2026-09-25 18:42:19 UTC
Source Run CI Run #5788
Commit 9fe9950957cfd17864404c9304ef819ac065d08e

Screenshot Comparison

PR #5774 screenshots vs screenshots baseline.

Matrix: AppImage-aarch64

Image Baseline PR
sunshine_tray_initial.png
sunshine_tray_menu.png
sunshine_tray_pairing_request.png
sunshine_tray_paused.png
sunshine_tray_stopped.png
sunshine_tray_streaming.png
sunshine_tray_tooltip.png

Matrix: AppImage-x86_64

Image Baseline PR
sunshine_tray_initial.png
sunshine_tray_menu.png
sunshine_tray_pairing_request.png
sunshine_tray_paused.png
sunshine_tray_stopped.png
sunshine_tray_streaming.png
sunshine_tray_tooltip.png

Matrix: Windows-AMD64

Image Baseline PR
sunshine_tray_initial.png
sunshine_tray_menu.png
sunshine_tray_pairing_request.png
sunshine_tray_paused.png
sunshine_tray_stopped.png
sunshine_tray_streaming.png
sunshine_tray_tooltip.png

Matrix: Windows-ARM64

Image Baseline PR
sunshine_tray_initial.png
sunshine_tray_menu.png
sunshine_tray_pairing_request.png
sunshine_tray_paused.png
sunshine_tray_stopped.png
sunshine_tray_streaming.png
sunshine_tray_tooltip.png

Matrix: macOS-arm64

Image Baseline PR
sunshine_tray_initial.png
sunshine_tray_menu.png
sunshine_tray_pairing_request.png
sunshine_tray_paused.png
sunshine_tray_stopped.png
sunshine_tray_streaming.png
sunshine_tray_tooltip.png

Matrix: macOS-x86_64

Image Baseline PR
sunshine_tray_initial.png
sunshine_tray_menu.png
sunshine_tray_pairing_request.png
sunshine_tray_paused.png
sunshine_tray_stopped.png
sunshine_tray_streaming.png
sunshine_tray_tooltip.png

@codecov

codecov Bot commented Sep 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 2.94118% with 132 lines in your changes missing coverage. Please review.
✅ Project coverage is 38.43%. Comparing base (4d71052) to head (9fe9950).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/platform/linux/portalgrab.cpp 0.00% 83 Missing ⚠️
src/platform/linux/misc.cpp 5.00% 30 Missing and 8 partials ⚠️
src/platform/linux/kmsgrab.cpp 25.00% 3 Missing and 3 partials ⚠️
src/platform/linux/kwingrab.cpp 0.00% 5 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5774      +/-   ##
==========================================
- Coverage   38.91%   38.43%   -0.49%     
==========================================
  Files         113      113              
  Lines       25972    26056      +84     
  Branches    11488    11539      +51     
==========================================
- Hits        10108    10014      -94     
+ Misses      14916    13280    -1636     
- Partials      948     2762    +1814     
Flag Coverage Δ
Alpine-aarch64 23.06% <2.22%> (-0.25%) ⬇️
Alpine-x86_64 23.19% <2.22%> (-0.25%) ⬇️
Archlinux 21.84% <2.20%> (-0.25%) ⬇️
Homebrew-macos-15 37.74% <ø> (ø)
Homebrew-macos-26 38.07% <ø> (+0.01%) ⬆️
Homebrew-ubuntu-24.04 24.72% <2.94%> (-0.60%) ⬇️
Linux-AppImage-aarch64 25.91% <2.94%> (-0.68%) ⬇️
Linux-AppImage-x86_64 26.10% <2.94%> (-0.68%) ⬇️
PowerShell 100.00% <ø> (ø)
Web-UI 85.00% <ø> (ø)
Windows-AMD64 30.83% <ø> (ø)
Windows-ARM64 25.85% <ø> (ø)
macOS-arm64 31.30% <ø> (ø)
macOS-x86_64 31.91% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/platform/linux/misc.h 0.00% <ø> (ø)
src/platform/linux/kwingrab.cpp 0.00% <0.00%> (ø)
src/platform/linux/kmsgrab.cpp 7.55% <25.00%> (+0.07%) ⬆️
src/platform/linux/misc.cpp 13.79% <5.00%> (-2.00%) ⬇️
src/platform/linux/portalgrab.cpp 0.00% <0.00%> (-21.59%) ⬇️

... and 47 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4d71052...9fe9950. Read the comment docs.

@ReenigneArcher
ReenigneArcher merged commit 55d6c0f into LizardByte:master Sep 25, 2026
81 of 84 checks passed
@ReenigneArcher ReenigneArcher added this to the xdg portal grab milestone Sep 25, 2026
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.

4 participants