Skip to content

Add optional idle suspend timeout - #11686

Open
michaelgarrettbrown-collab wants to merge 6 commits into
omacom:quattrofrom
michaelgarrettbrown-collab:idle-suspend
Open

michaelgarrettbrown-collab wants to merge 6 commits into
omacom:quattrofrom
michaelgarrettbrown-collab:idle-suspend

Conversation

@michaelgarrettbrown-collab

@michaelgarrettbrown-collab michaelgarrettbrown-collab commented Sep 13, 2026 •

Copy link
Copy Markdown

Adds an optional idle.suspend timeout to Omarchy Shell, in seconds from the start of a user-idle cycle. Omitted, invalid, or non-positive values leave automatic suspend disabled.

Behaviour

  • Suspend shares the initial idle deadline with screensaver and lock. A Wayland inhibitor-aware monitor gates the suspend request.
  • Blocking logind idle inhibitors and failed inhibitor queries defer suspend. The service retries after one minute if the countdown is still pending.
  • Activity or unlock cancels a pending suspend, including a request waiting on an inhibitor query. The shell forwards the unlock event from the private lock service.
  • Logind sleep and resume events clear the old countdown and re-arm idle detection for a fresh interval on wake.
  • Stay Awake disables automatic suspend. Automatic suspend is independent of the manual Suspend menu toggle.
  • Timeouts are capped at the safe timer ceiling to prevent overflow.

Validation

  • Seven focused suites passed: idle, lock state, system lock, sleep lock, restart shell, QML text format, and the live plugin authentication-boundary fixture. git diff --check passed.
  • A Quickshell fixture on live Hyprland exercised the original suspend deadline, fresh idle detection after a simulated resume, and unlock cancellation with power commands stubbed out.
  • On a real machine, the idle timer triggered deep suspend on schedule. Wake re-armed the idle cycle, activity cancelled a pending suspend, and a real logind idle inhibitor deferred suspend.
  • The full visual screensaver → lock → suspend sequence remains to be checked. The Stable test machine lacks the native omarchy-screensaver package required by this Quattro checkout. The journal shows that the shell attempted the screensaver at its deadline, followed by lock and suspend on schedule.

@llstrk

llstrk commented Oct 1, 2026

Copy link
Copy Markdown

Automated AI review

Community review: Independent automated community review, unaffiliated with the Omarchy team, intended to help prepare PRs for their review.

Outcome: With default timings, an idle.suspend over 150 s likely counts from the lock, not the last input (from source, not reproduced).

Suspend countdown restarts on window events

Hyprland 0.56.2 restarts the full timeout of a respectInhibitors: true monitor on every window map, unmap or focus change, such as the screensaver opening and closing at lock. With defaults, "suspend": 900 would fire about 1,200 s after the last input.

Suggested change: Count from the original idle start like lockTimer, or use an input-only monitor plus an inhibitor check.

A huge idle.suspend suspends immediately

optionalSecondsFromConfig has no upper bound, and on x86_64 Quickshell turns timeouts above 2,147,483 s into 0 ms. The shell then suspends on start, restart and Stay Awake off (compositor step from source).

Suggested change: Clamp to Math.floor(2147483647 / 1000) seconds, as #7578 does.

Reproducer (fails at 09dac0d)

1. The new helper passes very large values through (fails at 09dac0dd)

Added to test/shell.d/idle-test.sh after the last optionalSecondsFromConfig assertion:

 assertEqual(idle.optionalSecondsFromConfig('nope'), -1, 'idle disables an invalid optional timeout')
+// Quickshell's IdleMonitor converts timeout * 1000 through a signed 32-bit int,
+// so a larger value reaches the compositor as a 0 ms (immediate) timeout.
+const farSuspend = idle.optionalSecondsFromConfig(999999999)
+assert(
+  farSuspend === -1 || farSuspend * 1000 <= 2147483647,
+  'idle keeps an optional timeout within the IdleMonitor millisecond range',
+  `actual: ${farSuspend} seconds (${farSuspend * 1000} ms)`
+)

bash test/shell.d/idle-test.sh at 09dac0dd exits 1.

stdout:

ok - idle floors configured seconds
ok - idle rejects negative seconds
ok - idle rejects invalid seconds
ok - idle floors an optional timeout
ok - idle disables an omitted optional timeout
ok - idle disables a null optional timeout
ok - idle disables a zero optional timeout
ok - idle disables an optional timeout flooring below one second
ok - idle disables a negative optional timeout
ok - idle disables an invalid optional timeout

stderr:

actual: 999999999 seconds (999999999000 ms)
not ok - idle keeps an optional timeout within the IdleMonitor millisecond range

With the helper's last line changed to return seconds > 0 ? Math.min(seconds, Math.floor(2147483647 / 1000)) : -1, the same test file exits 0 and prints all 18 ok lines, including ok - idle keeps an optional timeout within the IdleMonitor millisecond range.

2. What Quickshell sends to the compositor for those values

qs_timeout.cpp uses the same expression as IdleMonitor::updateNotification() in Quickshell src/wayland/idle_notify/monitor.cpp (unchanged from v0.3.0 to v0.3.1 and master):

#include <algorithm>
#include <cstdio>
#include <cstdlib>

using quint32 = unsigned int;
using qreal = double;

int main(int argc, char** argv) {
	for (int i = 1; i < argc; i++) {
		qreal paramsTimeout = std::strtod(argv[i], nullptr);
		auto timeout = static_cast<quint32>(std::max(0, static_cast<int>(paramsTimeout * 1000)));
		std::printf("IdleMonitor.timeout=%s s -> ext_idle_notifier_v1.get_idle_notification timeout=%u ms\n", argv[i], timeout);
	}
	return 0;
}

g++ -O2 -std=c++17 -o qs_timeout qs_timeout.cpp && ./qs_timeout 900 2147483 2147484 4294967 999999999 on x86_64 (exit 0):

IdleMonitor.timeout=900 s -> ext_idle_notifier_v1.get_idle_notification timeout=900000 ms
IdleMonitor.timeout=2147483 s -> ext_idle_notifier_v1.get_idle_notification timeout=2147483000 ms
IdleMonitor.timeout=2147484 s -> ext_idle_notifier_v1.get_idle_notification timeout=0 ms
IdleMonitor.timeout=4294967 s -> ext_idle_notifier_v1.get_idle_notification timeout=0 ms
IdleMonitor.timeout=999999999 s -> ext_idle_notifier_v1.get_idle_notification timeout=0 ms

An -O0 build printed the same values for 900, 2147483, 2147484 and 999999999. In Hyprland v0.56.2 (src/protocols/IdleNotify.cpp), a notification with a 0 ms timeout calls onTimerFired() from update() in its constructor and sends idled right away, unless an idle inhibitor is active. The compositor and suspend steps were not run.

Details

Countdown sequence (defaults: screensaver 150 s, lock 300 s; from source, not run):

t=0     last input; both monitors start counting
t=150   screensaver window maps and takes focus -> setInhibit(false) -> suspend countdown restarts
t=300   lock closes the screensaver (window unmap) -> countdown restarts again
t=300+N suspend fires (N = idle.suspend, for N > 150), instead of t=N

Sources: Hyprland 0.56.2 CInputManager::recheckIdleInhibitorStatus() ends with PROTO::idle->setInhibit(false); setInhibit() calls update() on every notification with inhibitorsAreObeyed(), and update(0) resets and re-arms the full timeout. It runs on window map/unmap, focus and fullscreen changes. The base Service.qml already notes that "starting the screensaver can make the compositor report activity", which is why the lock timer keeps running through that activity. Any other window event while away also restarts the countdown. Settling it at runtime needs a nested Hyprland session comparing the suspend log time with the last input.

Verified:

  • omarchy-toggle-enabled suspend-off || systemctl suspend: with the flag set, systemctl is not called (stubbed run).
  • Stay Awake disables the monitor (from source).
  • Omitted, null, zero, negative, below-one-second and non-numeric string values disable suspend.
  • bash test/shell.d/idle-test.sh passes at the head (17 checks).

Optional notes:

  • Optional test improvement: replacing onIsIdleChanged: root.handleSuspendIdleChanged() with onIsIdleChanged: {} still passes all 17 checks, so the test does not cover the handler that starts suspend. An assertion that the monitor calls handleSuspendIdleChanged would catch it.
  • Number() coercion accepts "suspend": true as 1 s and [900] as 900. Accepting only numbers and numeric strings would match the "invalid means unchanged" description.
  • respectInhibitors covers Wayland idle inhibitors and Hyprland idle_inhibit rules, not logind --what=idle locks, so "respects system inhibitors" (PR body) and "respects system sleep inhibitors" (test message) are broader than the behaviour.

Related open PRs: #8965 (gamepad/audio activity) gates only the main idle cycle and #12882 (lid Stay Awake) only inhibits lid-switch handling, so idle suspend would still fire under either after a merge. #12538, #12731, #9570, #12975, #8965 and #7578 overlap the same hunks.


Review information

Test scope: Source and sandbox tests at 09dac0dd; no live compositor or suspend.

AI process: Opus 5.5 Medium coordination and synthesis, Opus 5.5 Xhigh technical review and final fact check, GPT 6 Sol Xhigh search for related issues, Opus 5.5 Medium editorial check.

Opt out: To stop receiving these reviews, reply to this comment saying so.

@greptile-apps

greptile-apps Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; the previous activity-cancellation issue is fixed.

Summary

Adds optional idle.suspend timing, inhibitor checks, and cancellation on activity, unlock, sleep, and resume.

  • The idle service can suspend after a configured timeout.

Reviews (9) · Last reviewed commit: "Cancel suspend for activity during scree..." · Reviewed by Greptile

Comment thread test/shell.d/idle-test.sh Resolved
@jandrusk

Copy link
Copy Markdown

This looks like the implementation for #9931 (configurable auto-suspend). It's currently CONFLICTING — please rebase onto quattro. Also worth a short note on how idle.suspend interacts with the AC/battery idle split (#8595) and the known IdleMonitor re-arm bugs (#14438 / #8038), so suspend doesn't fire while the monitor is wedged.

@edneymatias

edneymatias commented Oct 23, 2026 •

Copy link
Copy Markdown

Tested this on Omarchy 4.0.6-1 (Hyprland, Lenovo LOQ 15IAX9E, Intel + NVIDIA hybrid).

I applied only the shell/plugins/services/idle part of the diff to a cloned omarchy.idle plugin (omarchy plugin clone). It applied cleanly: one hunk at offset -1 and one with fuzz 1, no conflicts. With "idle": {"screensaver": 150, "lock": 300, "suspend": 420}, omarchy-shell idle status reports suspend: 420 plus the new suspendInputIdle / suspendInhibitorIdle fields.

Result: left idle with Stay Awake off, no video playing and no logind block inhibitors, the screensaver started, the displays went to DPMS off, and the laptop was suspended when I came back. That is the behavior this PR is meant to add.

The journal confirms it was the idle service and not the lid or a manual action. The suspends came from the shell's systemctl suspend (times are local):

12:18:29 systemd-logind: suspend requested from client PID 65187 ('systemctl') (unit user@1000.service)...
12:18:29 omarchy-shell: omarchy idle ... process-exit: suspend exitCode=0 status=0
12:18:29 kernel: PM: suspend entry (deep)

and the same pair again later in the day. A lid close, for comparison, logs Lid closed / Suspending... with no systemctl request and no process-exit: suspend line.

I also built a small UI on top of it in a cloned power panel (a "Suspend after" row with Never / 10 min / 15 min / 30 min / 1 h buttons that writes idle.suspend through omarchy-shell-config's commit, plus a one-line status). Changing the value from the panel updates shell.json, and the status line reflects it. Happy to share it if a UI for this is of interest.

Stay Awake: with Stay Awake on, the laptop does not suspend, as expected.

Inhibitors (correction): an earlier version of this comment said a YouTube tab and LLM agent apps holding a logind sleep block both held off the suspend. I could not verify that, so I'm retracting it. What I did verify:

  • A Chrome tab playing video shows inhibitingIdle: true in hyprctl clients -j; I did not confirm a suspend being deferred by it.
  • An app that holds a logind idle inhibitor is not respected. My coding agent (omp) registers systemd-inhibit WHAT=idle, MODE=block, WHY=omp agent session for as long as a task runs. The laptop suspended twice in one afternoon while a long omp task was running. I did not capture the inhibitor list at those moments, so the excerpt below only shows what a timer-driven suspend looks like in the journal (one of that afternoon's suspends):
13:20:28 suspend-input-idle-monitor: idle
13:20:28 process-start: suspend omarchy-toggle-enabled suspend-off || systemctl suspend
13:20:28 systemd-logind: suspend requested from client PID 1675061 ('systemctl') ...
13:20:28 process-exit: suspend exitCode=0

This follows from the design: ext-idle-notify only honors Wayland inhibitors, and systemctl suspend is only refused by sleep block inhibitors, so an idle-only block is ignored by both. Locally I gated the command on logind (... || { systemd-inhibit --list --json=short | jq -e 'any(.[]; .mode == "block" and (.what | test("idle")))' >/dev/null && exit 3; systemctl suspend; }, retrying after 60 s on exit 3). With omp running a task, the timer then fired at 22:01:37 and 22:04:07, exited with exitCode=3 and did not suspend; it suspended at 22:06:37, after the block was released at 22:05:52. The 60 s retry itself was not exercised.

Screensaver and lock reset the suspend countdown (side finding). With idle.suspend (120 s) below the screensaver/lock timeouts, suspend-input-idle-monitor went back to active 0.1-0.25 s after the screensaver or lock started, while I was not touching the machine (e.g. process-start: screensaver 22:02:07.585 → active 22:02:07.687; process-start: lock 22:04:37.587 → 22:04:37.784; screensaver 22:16:44.986 → 22:16:45.240). hyprctl switchxkblayout and a focus dispatch on the same monitor did not reset it on their own; I did not isolate the cause. It only matters when idle.suspend is below the lock timeout, but it contradicts the code comment saying opening the screensaver or lock screen must not restart the suspend countdown.

suspend-off flag: with omarchy toggle suspend on and idle.suspend at 120 s, the timer fired twice but never suspended: process-exit: suspend exitCode=0 came 24-46 ms after suspend-input-idle-monitor: idle, with no suspend requested from ... ('systemctl') from logind and no PM: suspend entry.

Resume, one finding. After a real suspend, the next cycle depends on input arriving after the wake:

  • Woke at 17:18:35 and touched nothing (lock screen left up): no active event at all for ~5 min (the stock idle-monitor also stayed idle), so suspendInputIdle stayed true, no monitor changed state, and maybeSuspend() never ran again. The laptop stayed on until I touched it at 17:23:39.
  • After that input at 17:23:39, the next cycle suspended normally at 17:26:21 (120 s later). Waking at 17:26:40 and touching the machine logged suspend-input-idle-monitor: active 1 s later.

So waking without any later input (lid open, power button) leaves the machine up and locked indefinitely. It may be worth calling rearmSuspendMonitors() after resume, or re-checking maybeSuspend() on a timer while the input monitor is idle. I only have two observations, so the cause is a hypothesis.

Design note: omarchy toggle suspend is documented as menu availability only, and its notifications say exactly that ("Suspend removed from system menu" / "Suspend now available in system menu"). This PR reuses suspend-off as the gate for idle suspend, so someone who hides Suspend from the menu would also silently turn off auto-suspend, with nothing in the notification saying so. Is that coupling intended? If not, a separate flag (or a config key such as idle.suspend: 0) would keep the two apart; if it is, it may be worth saying so in the toggle's notification and in the manual.

One observation that might be useful for the inhibitor path: a Chrome tab playing video shows inhibitingIdle: true in hyprctl clients -j, whereas apps that only inhibit over D-Bus (org.freedesktop.ScreenSaver) are invisible to the timer, since nothing owns that name on the session bus since hypridle was dropped. That is what #13359 would address, so the two look complementary.

Comment thread shell/plugins/services/idle/Service.qml Resolved
Comment thread shell/plugins/services/idle/Service.qml Resolved
Comment thread shell/plugins/services/idle/Service.qml Resolved
@michaelgarrettbrown-collab

Copy link
Copy Markdown
Author

Thanks for the thorough live testing. The PR has been revised to address the reported cases:

  • Suspend now uses a timer armed from the original idle cycle, rather than an IdleMonitor clock, so screensaver and lock window events do not reset its deadline.
  • A Wayland inhibitor-aware monitor is retained as a gate, and blocking logind idle inhibitors are checked before systemctl suspend.
  • Either kind of temporary inhibition retries after 60 seconds.
  • Unlocking cancels a pending suspend; after a successful suspend request the next full timeout is armed again for resume without requiring fresh input.
  • Auto-suspend no longer reuses the manual Suspend menu visibility toggle.

bash test/shell.d/idle-test.sh and git diff --check pass on the updated commit.

Comment thread test/shell.d/idle-test.sh Resolved
@edneymatias

Copy link
Copy Markdown

Thanks for the quick revision, and for taking the live-test findings seriously.

Reading the new commits against what I reported, each point has a counterpart:

  • logind idle block inhibitors: suspendInhibitorCheck covers the case I hit (an agent holding WHAT=idle, MODE=block, and the old timer suspending anyway).
  • Retry: the 60 s retry timer replaces waiting for fresh input.
  • Screensaver/lock restarting the countdown: arming suspendTimer from the idle cycle looks like the right fix. With idle.suspend below the lock timeout I saw the old input monitor go back to active 0.1-0.25 s after the screensaver or lock started.
  • Waking without input: listening for PrepareForSleep and re-arming on resume addresses the case where the laptop stayed up and locked.
  • suspend-off: decoupling it from the menu toggle resolves the design question.

One caveat: I could not retest this revision. On my machine (4.5.0-3) patch --dry-run fails on the first Service.qml hunk, and a cloned idle plugin would not receive the sessionUnlocked hook added in shell.qml, so I can't give you a result for the new code. The notes above come from reading the diff only.

Two things I noticed while reading, in case they are useful:

  • If gdbus monitor for login1 fails to start or exits, sleepEventsAvailable stays false and attemptSuspend() defers forever ("sleep-events-unavailable"), so auto-suspend would quietly stop working. Fail-closed is safe, but it may be worth a log line or a bounded fallback.
  • The suspend path now depends on gdbus, stdbuf and jq.

Happy to rerun the same scenarios (long-running task with a logind idle block, wake with no input, screensaver/lock with a short idle.suspend) once this is in a release or applies to the current package.

Comment thread shell/plugins/services/idle/Service.qml Resolved
@omarchybot omarchybot removed the enhancement New feature or request label Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants