Repository navigation
fix(screencast): honor Request.Close and propagate session closure - #16
Conversation
There was a problem hiding this comment.
🔵 Needs a closer look
Unresolved cancellation and packaging issues remain, and the custom dispatch and concurrent teardown paths need final human review.
2 open issues
What changed in this PR
This PR extends the ScreenCast backend’s lifecycle handling beyond picker-button cancellation, adding support for application-request cancellation and compositor-driven session closure.
Changes:
- Export per-call Request objects with ordered registration and cancellation handling.
- Make picker cancellation sticky and propagate compositor closure to portal sessions.
- Add private-D-Bus regression tests, CI dependencies, and lifecycle documentation.
| File | Description |
|---|---|
src/screencast/request.rs |
Manage Request registration, cancellation, and removal. |
src/screencast/pick.rs |
Preserve cancellation across spawning and reap cancelled children. |
src/screencast/mod.rs |
Integrate cancellation and session closure handling. |
src/screencast/lifecycle_tests.rs |
Add five private-D-Bus lifecycle tests. |
src/screencast/dispatch.rs |
Register requests before dispatching asynchronous workers. |
src/main.rs |
Register ScreenCast through the ordered dispatcher. |
README.md |
Document lifecycle behavior and test dependencies. |
Cargo.toml |
Raise the minimum zbus version to 5.18. |
.github/workflows/ci.yml |
Install D-Bus for regression tests. |
Review effort: Balanced
| let mut child = Command::new("dbus-daemon") | ||
| .args(["--session", "--nofork", "--nopidfile", "--print-address=1"]) | ||
| .stdout(Stdio::piped()) | ||
| .spawn() | ||
| .expect("D-Bus tests require dbus-daemon"); |
| let _operation = self.operations.lock().await; | ||
| let handler = self.session_handler(session_handle.as_str()); |
|
Verification update: the complete CI matrix for head 9daf39d is green: https://github.com/ParticleG/niri-screenshare/actions/runs/40267086377 . Both default and --no-default-features jobs passed formatting, release build, release tests, and Clippy with -D warnings. The follow-up commit only replaces a missing-child match with the equivalent ? expression required by Clippy 1.99; it does not relax any checks or change the tested lifecycle behavior. |


Problem
On
v0.2.3andmainat8bbf3e1, basic window capture works, but the backend ignores the request handles passed to its methods. Calling the public PortalRequest.Closewhile the chooser is open fails because the backend has noorg.freedesktop.impl.portal.Requestobject, and the chooser stays open. This is separate from the picker-button Cancel fix in #3 / #4.Also, closing the captured window stops the PipeWire stream but leaves the backend and frontend Session objects alive without a
Closednotification.org.freedesktop.impl.portal.Session.versionis missing.Changes
CreateSession,SelectSources, andStart; remove them on success, cancellation, or error.Request.Close, without cancelling another request.version = 1, subscribe to the compositor session'sClosedsignal before startup, and notify/unexport the portal session when the compositor ends it.Session.Closecleanup idempotent and preserve failed-start retry behavior.dbus-daemonin CI, and document the lifecycle behavior.Why ordered dispatch is necessary
A Request handler registered only at the start of an async ScreenCast method is insufficient: zbus normally spawns the method task, then can dispatch an immediately following
Closebefore that task has exported its object. This race was reproduced through the real public Portal frontend during testing.OrderedScreenCastregisters the request in message order before handing the method to an async worker. It delegates argument validation, replies, properties, and introspection to the generated interface. Existing serialized ScreenCast operation behavior is retained, while Request and Session cancellation remain independently dispatchable. No sleeps, retries, or cancellation fallbacks are used to hide the race. The zbus minimum is updated to 5.18 to match the Interface API already present in the lockfile.Automated verification
Passed locally:
The new tests cover cancellation isolation/stickiness, back-to-back
StartandRequest.Closemessages without waiting for request registration, cancellation during startup,Session.Closeduring startup, and compositor closure notification/unexport. Each test starts its own private bus and controlled compositor service.Real desktop smoke verification
Environment: Arch Linux, niri
26.04 (v26.04-206-ge19df12c),xdg-desktop-portal 1.22.1-2, PipeWire1.6.9.The patched backend and the installed Portal frontend ran on a private D-Bus session. A temporary transport bridge forwarded only the compositor ScreenCast API to the real niri session. Request/Session objects and cancellation were handled directly by the patched backend, not simulated by the bridge. The normal desktop Portal routing was not changed.
Verified:
Request.Closesucceeds and closes an already visible GTK chooser.Session.Closeto make cancellation pass.1.CreateSession,SelectSources,Start, andOpenPipeWireRemotework end to end. An actual PipeWire consumer receives changing red/blue frames from an owned single-window fixture through the Portal-provided FD.Session.Closeremoves the compositor capture.Closedand one frontendClosed, removes both Session objects, and leaves no capture running.This does not claim coverage of browser meeting applications or XWayland windows.
Protocol references