From aa5b3e20c27098f097edc05b97b83a5d91e31f40 Mon Sep 17 00:00:00 2001 From: husamemadH Date: Sat, 22 Aug 2026 17:53:25 +0300 Subject: [PATCH] Dismiss the screensaver on any input, not just a keypress The main idle monitor reports activity once while the screensaver maps its own window and then stays active for as long as the screensaver is up, so it never signals again and cannot see the input that should dismiss it. Only the screensaver's own read -n1 loop could, and that needs a byte on stdin while the terminal holds focus. Arm a second idle monitor while a screensaver window is on screen. It arms once input goes quiet, so the launch activity is ignored, and the next input from any device the compositor knows about tears the screensaver down. --- shell/plugins/services/idle/IdleModel.js | 13 ++++++- shell/plugins/services/idle/Service.qml | 43 +++++++++++++++++++++++- test/shell.d/idle-test.sh | 20 +++++++++++ 3 files changed, 74 insertions(+), 2 deletions(-) diff --git a/shell/plugins/services/idle/IdleModel.js b/shell/plugins/services/idle/IdleModel.js index 8e2315d0375a..68ccba970ffb 100644 --- a/shell/plugins/services/idle/IdleModel.js +++ b/shell/plugins/services/idle/IdleModel.js @@ -43,10 +43,21 @@ function screensaverWindowsAfter(windows, address, visible) { } } +// The screensaver's own window mapping registers as input, so a dismissal +// monitor cannot treat its first activity as the user. It arms only once input +// has gone quiet while the screensaver is on screen; the next activity after +// that is a real keypress, click, or pointer move and dismisses the screensaver. +function screensaverDismissAction(armed, isIdle, screensaverVisible) { + if (!screensaverVisible) return "ignore" + if (isIdle) return armed ? "ignore" : "arm" + return armed ? "dismiss" : "ignore" +} + if (typeof module !== "undefined") { module.exports = { secondsFromConfig: secondsFromConfig, eventParts: eventParts, - screensaverWindowsAfter: screensaverWindowsAfter + screensaverWindowsAfter: screensaverWindowsAfter, + screensaverDismissAction: screensaverDismissAction } } diff --git a/shell/plugins/services/idle/Service.qml b/shell/plugins/services/idle/Service.qml index 488f29611c34..191be1271efd 100644 --- a/shell/plugins/services/idle/Service.qml +++ b/shell/plugins/services/idle/Service.qml @@ -24,6 +24,7 @@ Item { readonly property int lockDelaySeconds: Math.max(0, lockTimeoutSeconds - firstIdleTimeoutSeconds) readonly property bool idleEnabled: stayAwakeStateLoaded && !stayAwake readonly property string screensaverClass: "org.omarchy.screensaver" + readonly property int screensaverDismissSettleSeconds: 1 property bool stayAwake: false property bool stayAwakeStateLoaded: false @@ -35,6 +36,7 @@ Item { property string lastEventAt: "" property var screensaverWindows: ({}) property int screensaverWindowCount: 0 + property bool screensaverDismissArmed: false function secondsFromConfig(value, fallback) { return IdleModel.secondsFromConfig(value, fallback) @@ -113,6 +115,29 @@ Item { function resetScreensaverWindows() { root.screensaverWindows = ({}) root.screensaverWindowCount = 0 + root.screensaverDismissArmed = false + } + + function dismissScreensaver(reason) { + logEvent("screensaver-dismiss", reason || "input") + root.screensaverDismissArmed = false + runProcess(dismissProcess, "dismiss", "pkill -f '[o]rg.omarchy.screensaver'") + } + + // The main idle monitor reports activity once while the screensaver maps its + // window and then stays active for as long as it is up, so it never sees the + // input that should dismiss it. A second monitor, armed only while the + // screensaver is on screen, supplies that signal for every input device the + // compositor knows about. + function handleScreensaverDismissSignal() { + var action = IdleModel.screensaverDismissAction(root.screensaverDismissArmed, screensaverDismissMonitor.isIdle, root.screensaverWindowCount > 0) + + if (action === "arm") { + root.screensaverDismissArmed = true + logEvent("screensaver-dismiss-armed") + } else if (action === "dismiss") { + dismissScreensaver("input") + } } function setScreensaverWindow(address, visible) { @@ -128,6 +153,7 @@ Item { function handleScreensaverWindowClosed(address) { setScreensaverWindow(address, false) + if (root.screensaverWindowCount === 0) root.screensaverDismissArmed = false if (!root.idleEnabled || !root.idledThisCycle || !root.screensaverStartedThisCycle) return if (root.screensaverWindowCount > 0) return @@ -191,6 +217,7 @@ Item { screensaverDelay: root.screensaverDelaySeconds, lockDelay: root.lockDelaySeconds, screensaverWindows: root.screensaverWindowCount, + screensaverDismissArmed: root.screensaverDismissArmed, timers: { screensaver: screensaverTimer.running, lock: lockTimer.running, @@ -199,7 +226,8 @@ Item { processes: { screensaver: screensaverProcess.running, lock: lockProcess.running, - wake: wakeProcess.running + wake: wakeProcess.running, + dismiss: dismissProcess.running }, lastEvent: root.lastEvent, lastEventAt: root.lastEventAt @@ -255,6 +283,14 @@ Item { onIsIdleChanged: root.handleIdleChanged() } + IdleMonitor { + id: screensaverDismissMonitor + enabled: root.idleEnabled && root.screensaverWindowCount > 0 + timeout: root.screensaverDismissSettleSeconds + respectInhibitors: false + onIsIdleChanged: root.handleScreensaverDismissSignal() + } + Timer { id: screensaverTimer interval: root.screensaverDelaySeconds * 1000 @@ -298,6 +334,11 @@ Item { onExited: function(exitCode, exitStatus) { root.logEvent("process-exit", "wake exitCode=" + exitCode + " status=" + exitStatus) } } + Process { + id: dismissProcess + onExited: function(exitCode, exitStatus) { root.logEvent("process-exit", "dismiss exitCode=" + exitCode + " status=" + exitStatus) } + } + Process { id: stayAwakeStateProbe command: ["bash", "-c", "mkdir -p \"$HOME/.local/state/omarchy/indicators\"; if [[ -f $HOME/.local/state/omarchy/indicators/stay-awake ]]; then echo yes; else echo no; fi"] diff --git a/test/shell.d/idle-test.sh b/test/shell.d/idle-test.sh index 62a19c2ce03e..5bc0fdf40722 100644 --- a/test/shell.d/idle-test.sh +++ b/test/shell.d/idle-test.sh @@ -33,6 +33,26 @@ assertDeepEqual( { windows: { a: true }, count: 1 }, 'idle leaves screensaver windows unchanged without an address' ) +assertEqual( + idle.screensaverDismissAction(false, true, true), + 'arm', + 'idle arms screensaver dismissal once input goes quiet' +) +assertEqual( + idle.screensaverDismissAction(false, false, true), + 'ignore', + 'idle ignores the screensaver launching itself as input' +) +assertEqual( + idle.screensaverDismissAction(true, false, true), + 'dismiss', + 'idle dismisses the screensaver on input once armed' +) +assertEqual( + idle.screensaverDismissAction(true, false, false), + 'ignore', + 'idle ignores input when no screensaver is on screen' +) JS test_tmp=$(mktemp -d)