Keep Windows awake when dbus is inhibited from idle, sleep

Open
#42,121 4 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
cpp, linux

Research direction

Start by tracing how /keep-awake currently uses the systemd integration and where it could observe changes to BlockInhibited. The issue proposes responding to idle, sleep, or shutdown inhibition with SetThreadExecutionState, then clearing the state when the property is empty; no files or tests are named. Done means Windows stays awake while the relevant inhibition is active and returns to normal afterward.

Written by the indexing model from the issue text.

Description

feature

Is your feature request related to a problem? Please describe.

I use Copilot CLI in WSL2 and have /keep-awake enabled. That does call the org.freedesktop.login1.Manager.Inhibit API to inhibit idle detection. This does not, however, prevent my Windows machine from going idle and eventually to sleep.

Describe the solution you'd like

Monitor for property changed to BlockInhibited and SetThreadExecutionState accordingly e.g., probably when you see any of "idle", "sleep", or "shutdown"—which can be combined e.g., "sleep:idle"—call SetThreadExecutionState(ES_SYSTEM_REQUIRED | ES_CONTINUOUS). When the new property value is empty, SetThreadExecutionState(ES_CONTINUOUS) to clear it. As a service, you also have options to "discourage" shutting down when you see dbus signal "shutdown" through SCM messages.

Describe alternatives you've considered

I could use a systemd service to monitor events and write to stdout, listening to it from a WSL plugin. I could also use a number of executables including something like pipeferry or npiperelay to establish a pipe and listen to that from Windows. More moving parts, but no code signing requirement like WSL plugins either.

Additional context

See https://gist.github.com/heaths/b155cb7120b89a2a1c626f9d1cca2a0f (Rust) for how you can filter events to avoid getting flooded. This is a simple sync example but these I would expect would be infrequent enough to warrant proper signaling over overlapped IO.

systemd integration is enabled.

Dominant language
C++
Stars
34.4k
Forks
1.9k
Avg merge
1d 23h
Merged PRs (30d)
166

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/WSL

All issues in microsoft/WSL

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.