Skip to content

Commit 2b4c70b

Browse files
committed
Add some documentation
1 parent f8e050e commit 2b4c70b

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

README.md

+17-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Arguments:
2626
Options:
2727
-d, --display Keep display on
2828
-i, --idle Keep system from idle sleeping
29-
-s, --sleep Keep system from sleeping (Functionality and conditions for this to work vary by OS)
29+
-s, --sleep Keep system from explicitly sleeping (Functionality and conditions for this to work vary by OS)
3030
--completions <SHELL> Generate shell completions [possible values: bash, elvish, fish, powershell, zsh]
3131
-w <PID> Wait for the process with the specified pid to exit. This option is ignored when used with the COMMAND argument
3232
-h, --help Print help information
@@ -66,6 +66,22 @@ See the generated header file for details on the API. See [cargo-c] for futher d
6666

6767
[cargo-c]: https://crates.io/crates/cargo-c
6868

69+
## Technical Details
70+
| | Windows | macOS | Linux |
71+
| ------------- | --------------------------- | ------------------------------- | ----------------------------------------------------------- |
72+
| API | [`SetThreadExecutionState`] | [`IOPMAssertionCreateWithName`] | [`org.freedesktop.ScreenSaver`] & [systemd Inhibitor Locks] |
73+
| Debug command | `powercfg /requests` | `pmset -g assertions` | `systemd-inhibit --list`, `gnome-session-inhibit --list` |
74+
| display | `ES_DISPLAY_REQUIRED` | `PreventUserIdleDisplaySleep` | `org.freedesktop.ScreenSaver.Inhibit` |
75+
| idle | `ES_SYSTEM_REQUIRED` | `PreventUserIdleSystemSleep` | `org.freedesktop.login1.Manager.Inhibit("idle")` |
76+
| sleep | `ES_AWAYMODE_REQUIRED` | `PreventSystemSleep` | `org.freedesktop.login1.Manager.Inhibit("sleep")` |
77+
78+
`idle` prevents the system from going to sleep on an idle timer, while `sleep` tries to prevent the system from going to sleep explicitly by the user (Whether `sleep` also prevents idle sleep varies by OS). `sleep` is restricted and will only work under certain conditions, most notably, the computer must be on AC power (AKA plugged in, not on battery), and is not allowed on Windows on any computer that has modern standby on (Which is unfortunate as modern standby is also used in laptops not only in handheld mobile devices).
79+
80+
[`SetThreadExecutionState`]: https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-setthreadexecutionstate
81+
[`IOPMAssertionCreateWithName`]: https://developer.apple.com/documentation/iokit/1557134-iopmassertioncreatewithname
82+
[`org.freedesktop.ScreenSaver`]: https://people.freedesktop.org/~hadess/idle-inhibition-spec/re01.html
83+
[systemd Inhibitor Locks]: https://www.freedesktop.org/wiki/Software/systemd/inhibit/
84+
6985
## Notes
7086
Preventing the computer from explicitly sleeping, and/or by closing the lid, is often restricted in various ways by the OS, e.g. Only on AC power, not in any PC running Windows with [Modern Standby](https://learn.microsoft.com/en-us/windows-hardware/design/device-experiences/modern-standby). Also note that Modern Standby ignores/terminates power requests on DC (Battery) power, [PowerSetRequest - Remarks](https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-powersetrequest#remarks).
7187

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ struct Options {
6363
#[builder(default)]
6464
idle: bool,
6565

66-
/// Prevent the system from sleeping. Only works under certain, OS dependant, conditions.
66+
/// Prevent the system from explicitly sleeping. Only works under certain, OS dependant, conditions.
6767
#[builder(default)]
6868
sleep: bool,
6969

src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ struct Cli {
2626
#[arg(short, long)]
2727
idle: bool,
2828

29-
/// Keep system from sleeping (Functionality and conditions for this to work vary by OS)
29+
/// Keep system from explicitly sleeping (Functionality and conditions for this to work vary by OS)
3030
#[arg(short, long)]
3131
sleep: bool,
3232

src/sys/linux.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
//!
55
//! Debug with `systemd-inhibit --list`, `gnome-session-inhibit --list`.
66
//!
7-
//! [ScreenSaver]: https://people.freedesktop.org/~hadess/idle-inhibition-spec/re01.html
8-
//! [systemd Inhibitor Locks]:(https://www.freedesktop.org/wiki/Software/systemd/inhibit/
7+
//! [`org.freedesktop.ScreenSaver`]: https://people.freedesktop.org/~hadess/idle-inhibition-spec/re01.html
8+
//! [systemd Inhibitor Locks]: https://www.freedesktop.org/wiki/Software/systemd/inhibit/
99
1010
use zbus::{blocking::Connection, proxy};
1111

0 commit comments

Comments
 (0)