File: system-sleep.el.html
Call system-sleep-block-sleep to inhibit system-wide idle sleep.
Idle sleep is typically triggered when the system does not detect user activity and is independent of any processing that may be on going. This function is useful to block idle sleep for long-running operations, for example, when a compilation is running. You have the option of keeping the system active while letting the display sleep. This function returns a token which you must use to unblock this request.
Call system-sleep-unblock-sleep with the token from
system-sleep-block-sleep to unblock system-wide idle sleep for this
request. There may be other active requests which will prevent the
system from sleeping.
The function system-sleep-sleep-blocked-p will tell you if
system-sleep has any active system sleep blocks.
Note: When the Emacs process dies, blocks are released on all platforms.
You can register functions on the abnormal hook
system-sleep-event-functions. Each function will be called when
the system is preparing for sleep and when the system wakes from
sleep. These functions are useful when you want to close (and
potentially reopen) external connections or serial ports.
On supported GNU/Linux systems, the implementation is via D-Bus to inhibit idle sleep, keep the display active, and forward events from logind for system sleep events.
On macOS and MS-Windows, native APIs are used to block idle sleep, keep the display active, and provide sleep event notifications.
On MS-Windows, an idle sleep block that keeps the display active may not inhibit the screen saver.
Externally to Emacs, there are system utility functions that you can use to inspect all processes on your system that might be blocking it from sleeping.
On D-Bus systems, you can use the commands:
systemd-inhibit --list
or
dbus-send --system --print-reply --dest=org.freedesktop.login1 \
/org/freedesktop/login1 \
org.freedesktop.login1.Manager.ListInhibitors
Note: You can find the sleep/shutdown delay InhibitDelayMaxUSec in the file logind.conf(5) which typically defaults to 5 seconds.
On macOS, you can use the command:
pmset -g assertions
On MS-Windows, you can use the following command which may need to be run as an administrator:
powercfg -requests
Defined variables (4)
system-sleep--back-end | Generic sleep-wake method system dispatcher. |
system-sleep--dbus-sleep-inhibitor-types | This is a colon-separated list of options. |
system-sleep--sleep-block-tokens | A list of active sleep-block tokens. |
system-sleep-event-functions | Abnormal hook invoked on system sleep events. |
Defined functions (24)
copy-sleep-event | (ARG) |
make-sleep-event | (STATE) |
make-sleep-event--cmacro | (CL-WHOLE-ARG STATE) |
sleep-event-p | (X) |
sleep-event-p--inliner | (INLINE--FORM X) |
sleep-event-state | (sleep-event-state X) |
sleep-event-state--inliner | (INLINE--FORM X) |
system-sleep--block-sleep | (WHY ALLOW-DISPLAY-SLEEP) |
system-sleep--dbus-delay-lock | (MAKE-OR-CLOSE) |
system-sleep--dbus-prepare-for-sleep-callback | (SLEEP-OR-WAKE) |
system-sleep--dbus-prepare-for-sleep-function | (EVENT) |
system-sleep--dbus-prepare-for-sleep-watcher | (MAKE-OR-CLOSE) |
system-sleep--disable | () |
system-sleep--enable | () |
system-sleep--set-back-end | () |
system-sleep--sleep-event-handler | (EVENT) |
system-sleep--unblock-sleep | (TOKEN) |
system-sleep-block-sleep | (&optional WHY ALLOW-DISPLAY-SLEEP) |
system-sleep-disable | () |
system-sleep-enable | () |
system-sleep-sleep-blocked-p | () |
system-sleep-unblock-all-sleep-blocks | () |
system-sleep-unblock-sleep | (TOKEN) |
with-system-sleep-block | (&optional WHY ALLOW-DISPLAY-SLEEP &rest BODY) |