Skip to content

libobs: Keep Linux sleep inhibition in C with Rust libobs - #454

Merged
zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/rust-sleep-inhibitor
Oct 13, 2026
Merged

zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/rust-sleep-inhibitor

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator

Description

With ENABLE_RUST_LIBOBS=ON (the OBS-Studio-Rust .deb and AppImage), OBS on Linux holds a real sleep and lock inhibitor again while it records or streams, through the inhibit portal or the session D-Bus service, as the C build does.

  • The platform-nix.c port (rust: Port libobs/util/platform-nix.c to obs-util #403, by Nathan V) leaves util/platform-nix.c out of the ON build. The Rust os_inhibit_sleep_* that replaced it ignored the reason and only ran xdg-screensaver reset every 30 s. That does nothing on Hyprland and other wlroots compositors and may do nothing on GNOME.
  • platform-nix-portal.c and platform-nix-dbus.c were still compiled, but their only callers were in the excluded platform-nix.c, so nothing called them.

The fix keeps sleep inhibition in C on Linux and FreeBSD in both lanes:

  • libobs/util/platform-nix-inhibit.c (new): os_inhibit_sleep_create, os_inhibit_sleep_set_active and os_inhibit_sleep_destroy with their helpers, moved unchanged from platform-nix.c. os-linux.cmake and os-freebsd.cmake compile it whether the option is ON or OFF. It tries the portal first, then (outside a Flatpak) org.freedesktop.ScreenSaver, org.freedesktop.PowerManagement.Inhibit and the MATE or GNOME session manager, and falls back to xdg-screensaver only without GIO or when none of them answers.
  • Rust: the three #[no_mangle] shims, nix::Inhibit (with its thread and xdg-screensaver spawn) and their three lines in rust-exports.d/obs-util-platform_nix.txt are removed, so there is one definition. The rest of the port is unchanged. The exported symbol set of libobs.so is identical in the two lanes (1766 symbols).
  • The C oracle no longer renames the moved functions, which platform-nix.c no longer has.
  • rust/README.md, the comments in nix.rs and ffi/platform_nix.rs, and the parity test header now say that os_inhibit_sleep_* is not ported and stays C.
  • macOS (platform-cocoa.m) and Windows (platform-windows.c) are unchanged.
  1. test: Check os_inhibit_sleep uses the portal and ScreenSaver D-Bus: test_inhibit_sleep_dbus (new, no display) calls the exported os_inhibit_sleep_* against fakes on a private D-Bus bus (GTestDBus starts its own dbus-daemon; the fakes run on their own thread so libobs's synchronous calls are answered).
    • test_portal_inhibit_and_release: a fake org.freedesktop.portal.Inhibit. set_active(true) must call Inhibit with the reason and flags 0xC (suspend and idle); set_active(false) must close the returned request.
    • test_screensaver_inhibit_and_release: no portal, a fake org.freedesktop.ScreenSaver. set_active(true) must call Inhibit("libobs", reason); set_active(false) must call UnInhibit with the returned cookie.
    • Both fail with the option ON (no D-Bus call at all) and pass with it OFF.
  2. libobs: Keep Linux sleep inhibition in C with Rust libobs: both cases pass in both lanes.

Motivation and Context

Fixes #453.

Why this one: it is a silent regression in the Linux release lane. OBS-Studio-Rust v0.1.0-beta.20261012 is the first release that contains #403, and its .deb and AppImage build with the option ON. A long unattended recording or stream can be ended by idle suspend, or a portal screencast blanked by the lock screen, and nothing in OBS shows that the inhibitor is missing. The C build and the Flatpak (which does not turn the option on) are not affected. Found in a review of the merges since #275, not reported by a user yet. Keeping the C code is the smallest change; a Rust port would need a D-Bus dependency for obs-util.

How Has This Been Tested?

Automated, in both libobs lanes (ENABLE_RUST_LIBOBS OFF and ON), on current master:

  • test_inhibit_sleep_dbus: at the RED commit, 2 of 2 fail with the option ON (neither fake gets an Inhibit call within 3 s) and 2 of 2 pass with it OFF. At GREEN, 2 of 2 pass in each lane. Both cases print [ OK ] with no skips, without a display (no DISPLAY and no session bus in the environment) and under Xvfb.
  • Repeatability: 20 runs in a row per lane passed (the C lane at RED, both lanes at GREEN).
  • Full ctest at GREEN, rebased on current master (ctest -j6 under Xvfb): 143 tests per lane. The only failures were test_video_io (OFF) and test_video_io_hidden (ON), new on master from the video-io port and untouched here; both pass when run on their own in both lanes (timing under parallel load). An earlier run on the old base was 141 of 141 in both lanes.
  • cargo test -p obs-util -p obs-c-oracle: 479 passed, 0 failed (including export_list, platform_nix and platform_nix_parity). cargo clippy -D warnings and cargo fmt --check are clean.
  • nm -D on libobs.so: the same 1766 exported symbols in both lanes, and os_inhibit_sleep_* now comes from platform-nix-inhibit.c.o in both (no definition left in liblibobs_rust.a).
  • clang-format, gersemi and ci/test_registration.py are clean.

Not tested:

  • A real desktop. No GNOME, KDE, Hyprland or wlroots session here was left idle with a recording running; the test checks the D-Bus calls with fakes. The C code is unchanged from what the OFF build has always run.
  • The Flatpak rule (no portal inside a Flatpak means no inhibitor, and no false success through xdg-screensaver). That code moved unchanged, but no test covers it: it needs /.flatpak-info at the filesystem root.
  • The other session D-Bus fallbacks (org.freedesktop.PowerManagement.Inhibit, MATE and GNOME session managers) and the xdg-screensaver path without GIO. Only the portal and org.freedesktop.ScreenSaver are faked.
  • FreeBSD. os-freebsd.cmake gets the same one-line change, but there is no FreeBSD build here or in CI.
  • CI coverage. The Tier 2 Linux image has no dbus-daemon, so the new test builds there and skips its cases (as test_portal_shortcuts does today). Adding dbus-daemon to rust/tools/linux-validate/Dockerfile would make both run in CI; that is left out of this PR to keep it to the fix.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • I have read the contributing document.
  • My code has been run through clang-format.
  • My code follows the project's style guidelines
  • My code is not on the master branch.
  • My code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.
  • I have used AI tooling in the creation of this PR
  • I am an AI agent being used to assist with this pull request: Claude Code (Claude Opus 5.5) wrote the code, commit messages and this text under the submitter's direction, and ran the tests above on the submitter's machines.

🤖 Generated with Claude Code

@rdoupe
rdoupe requested a review from zackees as a code owner October 13, 2026 04:22
@zackees

zackees commented Oct 13, 2026

Copy link
Copy Markdown
Member

Verified locally (Tier 2 image + dbus, ENABLE_RUST_LIBOBS OFF and ON):

  • RED 48a1fa9: test_inhibit_sleep_dbus passes with OFF (the C code) and fails with ON: test_portal_inhibit_and_release and test_screensaver_inhibit_and_release. That is the regression from the Rust platform-nix port.
  • GREEN 55fad9c: passes in both lanes, 147/147 each.
  • The edit to platform_nix_parity.rs only changes the module doc (sleep inhibit not ported, covered by the cmocka test).

Master's local gate is red until #450 merges (windows-gnu link). I'll rebase, gate and merge right after that.

@rdoupe

rdoupe commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator Author

The two red lanes aren't from this change: "Rust Tests (ubuntu-26.04)" fails linking the Windows cross-build of the obs-media-io tests video_matrices_layout and video_io_inlines_parity (mingw ld, unresolved externs), and "Rust Tier 2 windows-2025-vs2026" fails too. Both fail the same way on master at ea3df88 (Tier 2 Windows also on 71f5e4d and 5ba1b04). This PR touches no media-io or Windows code.

rdoupe and others added 2 commits October 12, 2026 22:03
os_inhibit_sleep_create/set_active must register a session inhibitor
through org.freedesktop.portal.Inhibit, or through
org.freedesktop.ScreenSaver when there is no portal, with the caller's
reason, and set_active(false) must release it.

Both services are faked on a private bus (GTestDBus starts its own
dbus-daemon) served from their own thread. No display is needed.
Without dbus-daemon the cases are skipped.

Fails with ENABLE_RUST_LIBOBS=ON: the Rust os_inhibit_sleep_* from the
platform-nix.c port (obs-rust#403) only runs xdg-screensaver reset every 30 s
and makes no D-Bus call. Passes with the C build.


Refs obs-rust#453.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
With ENABLE_RUST_LIBOBS=ON, util/platform-nix.c is not compiled and the
Rust port (obs-rust#403) provided os_inhibit_sleep_*. That version only ran
xdg-screensaver reset every 30 s and ignored the reason, so the portal
(platform-nix-portal.c) and session D-Bus (platform-nix-dbus.c)
inhibitors were compiled but never called. On Wayland desktops
(Hyprland, wlroots, GNOME) nothing stopped idle sleep or locking during
a recording or stream.

Move os_inhibit_sleep_* for Linux and FreeBSD out of platform-nix.c,
unchanged, into util/platform-nix-inhibit.c, which both lanes compile.
Drop the Rust shims, nix::Inhibit and their export entries, so libobs
has one definition and the same exported symbol set in both lanes. The
C oracle no longer renames the moved functions. rust/README.md and the
parity test header say the function stays C. macOS (platform-cocoa.m)
and Windows (platform-windows.c) are unchanged.

Fixes obs-rust#453.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Local-Gate: v1 tree=8e7cebb52a2ccab49eeffa1af7d49a8116ec88d4 secs=279 lanes=lint:run,rust-test:run,tier2-linux:run
Ci-Attestation: {"at":1791868099,"gate":"rust/all/fmt","host":"linux-x86_64","key":"43dcdeb829ab6f0eeadbfad56773ccd7b0a0e334ebe8665433b129819ab70360","lane":"lint","parents":["7ea103358fae5e15461faed076cc8d108a3af283"],"secs":47,"stamp":"e180dbaf8ca852d3482a8693eaedd30a","tree":"8e7cebb52a2ccab49eeffa1af7d49a8116ec88d4","v":1,"via":"run"}
Ci-Attestation: {"at":1791868099,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"43dcdeb829ab6f0eeadbfad56773ccd7b0a0e334ebe8665433b129819ab70360","lane":"lint","parents":["7ea103358fae5e15461faed076cc8d108a3af283"],"secs":47,"stamp":"a3f1f2449cd5c0cb4cd3ad85cf8bbe86","tree":"8e7cebb52a2ccab49eeffa1af7d49a8116ec88d4","v":1,"via":"run"}
Ci-Attestation: {"at":1791868099,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"dc918605f0cf0fa0101fe7e39bd11b1c96c378c6e755c9ea296d908d0795784b","lane":"rust-test","parents":["7ea103358fae5e15461faed076cc8d108a3af283"],"secs":157,"stamp":"cb9be05fa7c90af4c9da4645778f7ae4","tree":"8e7cebb52a2ccab49eeffa1af7d49a8116ec88d4","v":1,"via":"run"}
Ci-Attestation: {"at":1791868099,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"202b36cf9323fb6a487d762530ce84f333e8cf15419de9788f8986e56992a04f","lane":"tier2-linux","parents":["7ea103358fae5e15461faed076cc8d108a3af283"],"secs":74,"stamp":"65a42fad9306b19cfaa6003094b678cf","tree":"8e7cebb52a2ccab49eeffa1af7d49a8116ec88d4","v":1,"via":"run"}
@zackees

zackees commented Oct 13, 2026

Copy link
Copy Markdown
Member

#450 has landed: rebased on master, local gate passed; pushed as 57683fc. Merging once CI is green.

@zackees
zackees force-pushed the fix/rust-sleep-inhibitor branch from 55fad9c to 57683fc Compare October 13, 2026 05:08
@rdoupe
rdoupe force-pushed the fix/rust-sleep-inhibitor branch 2 times, most recently from 99dc9ea to 57683fc Compare October 13, 2026 05:11
@rdoupe

rdoupe commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator Author

Sorry: I force-pushed my own rebase over your attested 57683fc a couple of minutes after you pushed it. I've put 57683fc back as the head (same tree, your Local-Gate/Ci-Attestation trailers intact), so nothing of yours is lost.

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

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

bug: libobs: Rust libobs Linux builds no longer inhibit idle sleep while recording or streaming (regression from #403)

2 participants