plat/power.rs#
Source: lib/plat/power.rs
power -- keep the computer awake while the app works: no standby, no screen saver
inhibit(reason, what) -> Option<Inhibit> ask the system not to go to sleep on its own
(INHIBIT_SUSPEND: downloads, backups, long exports) or
also to keep the screen on and the session active
(INHIBIT_IDLE: presentations, videos; implies
INHIBIT_SUSPEND). The guard releases it when dropped.
None: not possible here (no service; the browser:
INHIBIT_SUSPEND alone, no Screen Wake Lock)
inhibited() -> u32 the INHIBIT_* bits the live guards of this process hold
reason is shown by the system (`powercfg /requests`, the desktop's list of inhibitors);
"" names the app. The user can still put the computer to sleep, and the opposite
direction already reaches the app: UIC_SUSPEND (the system goes to sleep / woke up) and
UIC_SESSION_END (logout, shutdown) come from win_api.rs and linux_life.rs.
Windows (win_power.rs): a power request with the reason as its text (PowerCreateRequest,
PowerSetRequest: INHIBIT_SUSPEND -> PowerRequestSystemRequired, INHIBIT_IDLE -> also
PowerRequestDisplayRequired). Linux (linux_power.rs): the Inhibit portal
(org.freedesktop.portal.Inhibit, flags suspend 4 / idle 8; also inside Flatpak; a refusal
of its backend arrives up to 300 ms after the answer and is waited for; INHIBIT_IDLE falls
back to idle alone where a backend only inhibits idle), without it
org.freedesktop.ScreenSaver (idle) and org.freedesktop.PowerManagement.Inhibit (suspend;
only best effort beside idle) -- all on a session-bus connection of plat that stays open
while a guard lives (the desktop ends inhibitions with their connection; it is closed when
the last guard goes). A backend may still drop an inhibition later; the guard does not
notice. logind's Inhibit is not used: it answers with a file descriptor, which plat's
D-Bus client does not receive. Browser and Android (web_power.rs): the Screen Wake Lock
(INHIBIT_IDLE only; taken again when the tab is visible again), FLAG_KEEP_SCREEN_ON and a
partial WakeLock (INHIBIT_SUSPEND). macOS (apple_power.rs): IOKit power assertions
(PreventUserIdleSystemSleep, with INHIBIT_IDLE also PreventUserIdleDisplaySleep). iOS
(apple_power_ios.rs): INHIBIT_IDLE turns UIApplication's idle timer off (no auto-lock while
the app is in front); INHIBIT_SUSPEND alone is None (iOS has no sleep but the screen's lock).
/// keep the system from going to sleep on its own (the screen may still turn off)
INHIBIT_SUSPEND: u32 = 1
/// keep the screen on and the session active (no screen saver, no lock); implies
/// INHIBIT_SUSPEND
INHIBIT_IDLE: u32 = 2
struct Inhibitan inhibition; dropping it lets the system sleep again
impl Inhibit
fn what(&self) -> u32the INHIBIT_* bits this guard holds (INHIBIT_IDLE with INHIBIT_SUSPEND)fn inhibit(reason: &str, what: u32) -> Option<Inhibit>keep the system awake (INHIBIT_SUSPEND) or also the screen on (INHIBIT_IDLE) until the guard is dropped -> None: not possible herefn inhibited() -> u32the INHIBIT_* bits the live guards of this process hold