Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion shell/plugins/services/idle/IdleModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,20 @@ function screensaverWindowsAfter(windows, address, visible) {
}
}

// A second idle monitor watches for input while the screensaver is displayed.
// It only counts as input once the monitor has gone quiet since the screensaver
// appeared, because launching the screensaver registers as activity itself.
function dismissStateAfter(settled, isIdle, visible) {
if (!visible) return { settled: false, dismiss: false }
if (isIdle) return { settled: true, dismiss: false }
return { settled: false, dismiss: !!settled }
}

if (typeof module !== "undefined") {
module.exports = {
secondsFromConfig: secondsFromConfig,
eventParts: eventParts,
screensaverWindowsAfter: screensaverWindowsAfter
screensaverWindowsAfter: screensaverWindowsAfter,
dismissStateAfter: dismissStateAfter
}
}
33 changes: 33 additions & 0 deletions shell/plugins/services/idle/Service.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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 bool screensaverVisible: screensaverWindowCount > 0

property bool stayAwake: false
property bool stayAwakeStateLoaded: false
Expand Down Expand Up @@ -79,6 +80,20 @@ Item {
runProcess(lockProcess, "lock", "omarchy-system-lock")
}

function dismissScreensaver(reason) {
logEvent("screensaver-dismiss", reason || "input")
// Signal the script, not its terminal: exit_screensaver stops ttfx before the
// terminal closes, and closing it first takes ttfx's pty with it. The terminal
// also ends in "omarchy-screensaver", hence the bash prefix.
runProcess(dismissProcess, "dismiss", "pkill -f 'bash .*bin/omarchy-screensaver$'")
}

function handleDismissMonitorChanged() {
var next = IdleModel.dismissStateAfter(dismissMonitor.settled, dismissMonitor.isIdle, root.screensaverVisible)
dismissMonitor.settled = next.settled
if (next.dismiss) dismissScreensaver("input-while-screensaver-visible")
}

function startIdleCycle() {
if (root.idledThisCycle) {
logEvent("idle-cycle-already-running")
Expand Down Expand Up @@ -255,6 +270,20 @@ Item {
onIsIdleChanged: root.handleIdleChanged()
}

// Launching the screensaver counts as activity, so the main monitor sits at
// active for as long as it is displayed and never signals again. This one is
// armed only while the screensaver is up, and catches the input its read-loop
// cannot see: touch and pointer motion never reach the screensaver's stdin.
IdleMonitor {
id: dismissMonitor
property bool settled: false
enabled: root.screensaverVisible
timeout: 1
respectInhibitors: false
onEnabledChanged: settled = false
onIsIdleChanged: root.handleDismissMonitorChanged()
}

Timer {
id: screensaverTimer
interval: root.screensaverDelaySeconds * 1000
Expand Down Expand Up @@ -293,6 +322,10 @@ Item {
id: lockProcess
onExited: function(exitCode, exitStatus) { root.logEvent("process-exit", "lock exitCode=" + exitCode + " status=" + exitStatus) }
}
Process {
id: dismissProcess
onExited: function(exitCode, exitStatus) { root.logEvent("process-exit", "dismiss exitCode=" + exitCode + " status=" + exitStatus) }
}
Process {
id: wakeProcess
onExited: function(exitCode, exitStatus) { root.logEvent("process-exit", "wake exitCode=" + exitCode + " status=" + exitStatus) }
Expand Down
21 changes: 21 additions & 0 deletions test/shell.d/idle-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,27 @@ assertDeepEqual(
{ windows: { a: true }, count: 1 },
'idle leaves screensaver windows unchanged without an address'
)

assertDeepEqual(
idle.dismissStateAfter(false, true, true),
{ settled: true, dismiss: false },
'idle settles the dismiss monitor once the screensaver goes quiet'
)
assertDeepEqual(
idle.dismissStateAfter(true, false, true),
{ settled: false, dismiss: true },
'idle dismisses the screensaver on input after it has settled'
)
assertDeepEqual(
idle.dismissStateAfter(false, false, true),
{ settled: false, dismiss: false },
'idle ignores the activity caused by launching the screensaver'
)
assertDeepEqual(
idle.dismissStateAfter(true, false, false),
{ settled: false, dismiss: false },
'idle never dismisses without a screensaver on screen'
)
JS

test_tmp=$(mktemp -d)
Expand Down