Treat idle timeout 0 as disabled, not immediate

idle.screensaver / idle.lock of 0 was included in Math.min(), so
IdleMonitor's timeout became 0. Releasing a Wayland idle inhibitor
(SDL's default screensaver inhibit) then reported idle immediately and
locked the session even when lock had been "disabled" by setting it to 0.

Treat 0 as disabled when computing the first idle deadline, do not start
the corresponding action, and leave IdleMonitor off when both timeouts
are 0.

Fixes #10860
This commit is contained in:
Paulo Geyer committed 2026-09-19 13:57:52 -03:00
1 parent 60663faf87
commit 14921a956e
3 files changed
+62 -10

No files matched your search

+22
View File
@@ -4,6 +4,26 @@ function secondsFromConfig(value, fallback) {
return Math.floor(n)
}
// 0 means the action is disabled, not "fire immediately". min(0, 300) would
// otherwise make IdleMonitor report idle as soon as an inhibitor is released.
function firstIdleTimeout(screensaverSeconds, lockSeconds) {
var times = []
if (screensaverSeconds > 0) times.push(screensaverSeconds)
if (lockSeconds > 0) times.push(lockSeconds)
if (times.length === 0) return 0
var min = times[0]
for (var i = 1; i < times.length; i++) {
if (times[i] < min) min = times[i]
}
return min
}
function delayAfterFirstIdle(timeoutSeconds, firstIdleSeconds) {
if (!(timeoutSeconds > 0)) return 0
var delay = timeoutSeconds - firstIdleSeconds
return delay > 0 ? delay : 0
}
function eventParts(event, count) {
try {
if (event && event.parse) return event.parse(count)
@@ -46,6 +66,8 @@ function screensaverWindowsAfter(windows, address, visible) {
if (typeof module !== "undefined") {
module.exports = {
secondsFromConfig: secondsFromConfig,
firstIdleTimeout: firstIdleTimeout,
delayAfterFirstIdle: delayAfterFirstIdle,
eventParts: eventParts,
screensaverWindowsAfter: screensaverWindowsAfter
}