Repository navigation
libobs: Keep Linux sleep inhibition in C with Rust libobs - #454
Merged
Merged
Conversation
Member
|
Verified locally (Tier 2 image + dbus,
Master's local gate is red until #450 merges (windows-gnu link). I'll rebase, gate and merge right after that. |
Collaborator
Author
|
The two red lanes aren't from this change: "Rust Tests (ubuntu-26.04)" fails linking the Windows cross-build of the |
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"}
Member
zackees
force-pushed
the
fix/rust-sleep-inhibitor
branch
from
October 13, 2026 05:08
55fad9c to
57683fc
Compare
rdoupe
force-pushed
the
fix/rust-sleep-inhibitor
branch
2 times, most recently
from
October 13, 2026 05:11
99dc9ea to
57683fc
Compare
Collaborator
Author
This was referenced Oct 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.platform-nix.cport (rust: Port libobs/util/platform-nix.c to obs-util #403, by Nathan V) leavesutil/platform-nix.cout of the ON build. The Rustos_inhibit_sleep_*that replaced it ignored the reason and only ranxdg-screensaver resetevery 30 s. That does nothing on Hyprland and other wlroots compositors and may do nothing on GNOME.platform-nix-portal.candplatform-nix-dbus.cwere still compiled, but their only callers were in the excludedplatform-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_activeandos_inhibit_sleep_destroywith their helpers, moved unchanged fromplatform-nix.c.os-linux.cmakeandos-freebsd.cmakecompile it whether the option is ON or OFF. It tries the portal first, then (outside a Flatpak)org.freedesktop.ScreenSaver,org.freedesktop.PowerManagement.Inhibitand the MATE or GNOME session manager, and falls back toxdg-screensaveronly without GIO or when none of them answers.#[no_mangle]shims,nix::Inhibit(with its thread andxdg-screensaverspawn) and their three lines inrust-exports.d/obs-util-platform_nix.txtare removed, so there is one definition. The rest of the port is unchanged. The exported symbol set oflibobs.sois identical in the two lanes (1766 symbols).platform-nix.cno longer has.rust/README.md, the comments innix.rsandffi/platform_nix.rs, and the parity test header now say thatos_inhibit_sleep_*is not ported and stays C.platform-cocoa.m) and Windows (platform-windows.c) are unchanged.test: Check os_inhibit_sleep uses the portal and ScreenSaver D-Bus:test_inhibit_sleep_dbus(new, no display) calls the exportedos_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 fakeorg.freedesktop.portal.Inhibit.set_active(true)must callInhibitwith the reason and flags 0xC (suspend and idle);set_active(false)must close the returned request.test_screensaver_inhibit_and_release: no portal, a fakeorg.freedesktop.ScreenSaver.set_active(true)must callInhibit("libobs", reason);set_active(false)must callUnInhibitwith the returned cookie.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.20261012is 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 forobs-util.How Has This Been Tested?
Automated, in both libobs lanes (
ENABLE_RUST_LIBOBSOFF 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 (noDISPLAYand no session bus in the environment) and under Xvfb.ctest -j6under Xvfb): 143 tests per lane. The only failures weretest_video_io(OFF) andtest_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 (includingexport_list,platform_nixandplatform_nix_parity).cargo clippy -D warningsandcargo fmt --checkare clean.nm -Donlibobs.so: the same 1766 exported symbols in both lanes, andos_inhibit_sleep_*now comes fromplatform-nix-inhibit.c.oin both (no definition left inliblibobs_rust.a).ci/test_registration.pyare clean.Not tested:
xdg-screensaver). That code moved unchanged, but no test covers it: it needs/.flatpak-infoat the filesystem root.org.freedesktop.PowerManagement.Inhibit, MATE and GNOME session managers) and thexdg-screensaverpath without GIO. Only the portal andorg.freedesktop.ScreenSaverare faked.os-freebsd.cmakegets the same one-line change, but there is no FreeBSD build here or in CI.dbus-daemon, so the new test builds there and skips its cases (astest_portal_shortcutsdoes today). Addingdbus-daemontorust/tools/linux-validate/Dockerfilewould make both run in CI; that is left out of this PR to keep it to the fix.Types of changes
Checklist:
🤖 Generated with Claude Code