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
6 changes: 1 addition & 5 deletions docs/notifications.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ The end-user view (hotkey notices for time, battery, weather) is in

## Toast lifecycle

A toast lives on screen for at least 5s (low), 8s (normal), or forever
(critical), stretched up to 30s if the sender asked for a longer
`expire_timeout`. Hovering pauses the countdown, and a content update restarts
it — new text deserves a full look. Left-click invokes the default action,
right-click or the hover-revealed close button dismisses.
Low and normal toasts stay on screen for at least 5s and 8s respectively, and use the sender's `expire_timeout` up to a 30s maximum. Critical toasts stay until dismissed unless the sender requests a positive timeout, which is also capped at 30s. Hovering pauses the countdown, and a content update restarts it — new text deserves a full look. Left-click invokes the default action, right-click or the hover-revealed close button dismisses.

Every on-screen popup is mirrored to its own file under
`~/.local/state/omarchy/notifications/` (one JSON line per file, named
Expand Down
21 changes: 20 additions & 1 deletion shell/plugins/notifications/NotificationLogic.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,26 @@ function parsePopupFiles(raw, normalUrgency) {
return entries
}

// Notification protocol timeouts are milliseconds; non-positive values do not
// request a finite lifetime.
function requestedDuration(expireTimeout) {
var ms = Number(expireTimeout || 0)
if (!isFinite(ms) || ms <= 0) return 0
return Math.round(ms)
}

function criticalPopupDuration(expireTimeout, maxDuration) {
var requested = requestedDuration(expireTimeout)
if (requested <= 0) return 0

var maximum = Number(maxDuration)
if (!isFinite(maximum) || maximum <= 0) return 0
return Math.min(maximum, requested)
}

// A persisted popup whose lifetime already ran out would have expired on
// screen had the shell kept running, so it is not restored. duration 0 means
// the popup never expires (critical urgency) and always survives restarts.
// the popup never expires and therefore survives restarts.
// A restore-reset deadline outranks the original timestamp: without it, a
// second restart would judge a re-shown toast by a clock that no longer
// governs its display and drop it while it is still on screen.
Expand Down Expand Up @@ -473,6 +490,8 @@ if (typeof module !== "undefined") {
persistablePopup: persistablePopup,
serializePopup: serializePopup,
parsePopupFiles: parsePopupFiles,
requestedDuration: requestedDuration,
criticalPopupDuration: criticalPopupDuration,
popupExpired: popupExpired,
popupPlacement: popupPlacement
}
Expand Down
22 changes: 4 additions & 18 deletions shell/plugins/notifications/Service.qml
Original file line number Diff line number Diff line change
Expand Up @@ -101,29 +101,15 @@ Item {

function durationFor(urgency, expireTimeout) {
switch (urgency) {
case NotificationUrgency.Critical: {
// FreeDesktop: expireTimeout 0 means never expire. A positive timeout
// from the sender must still be honoured for critical urgency — otherwise
// battery-low and similar toasts stick forever and resurrect on reboot.
var requested = requestedDuration(expireTimeout)
if (requested <= 0) return 0
return Math.min(maxPopupDuration, requested)
}
case NotificationUrgency.Critical:
return NotificationLogic.criticalPopupDuration(expireTimeout, maxPopupDuration)
case NotificationUrgency.Low:
return Math.min(maxPopupDuration, Math.max(lowPopupDuration, requestedDuration(expireTimeout)))
return Math.min(maxPopupDuration, Math.max(lowPopupDuration, NotificationLogic.requestedDuration(expireTimeout)))
default:
return Math.min(maxPopupDuration, Math.max(normalPopupDuration, requestedDuration(expireTimeout)))
return Math.min(maxPopupDuration, Math.max(normalPopupDuration, NotificationLogic.requestedDuration(expireTimeout)))
}
}

function requestedDuration(expireTimeout) {
// FreeDesktop notification spec (and Quickshell) report expireTimeout in
// milliseconds, so pass it through directly.
var ms = Number(expireTimeout || 0)
if (!isFinite(ms) || ms <= 0) return 0
return Math.round(ms)
}

// DND bypass: only let through notifications we trust to be intentional
// and rare.
// - omarchy-action: a user-action confirmation toast ("Theme changed",
Expand Down
53 changes: 18 additions & 35 deletions test/shell.d/notifications-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,20 @@ assertEqual(
'notifications omit the deadline field until a restore sets it'
)

assertEqual(notifications.criticalPopupDuration(30000, 30000), 30000, 'critical notifications honor a positive timeout')
assertEqual(notifications.criticalPopupDuration(60000, 30000), 30000, 'critical notification timeouts use the maximum duration')
assertEqual(notifications.criticalPopupDuration(0, 30000), 0, 'critical notifications remain sticky when timeout is zero')
assertEqual(notifications.criticalPopupDuration(-1, 30000), 0, 'critical notifications remain sticky for the server default timeout')
assertEqual(notifications.criticalPopupDuration(undefined, 30000), 0, 'critical notifications remain sticky when timeout is absent')
assert(
notifications.popupExpired({ timestamp: 1000 }, notifications.criticalPopupDuration(30000, 30000), 40000),
'a critical popup past its requested timeout expires on restore'
)
assert(
!notifications.popupExpired({ timestamp: 1000 }, notifications.criticalPopupDuration(30000, 30000), 20000),
'a critical popup inside its requested timeout is restored'
)

// The click action (an argv vector) is the only kind that survives a shell
// restart: a libnotify action leaves its sender waiting on an id from a server
// generation that no longer exists.
Expand Down Expand Up @@ -584,49 +598,18 @@ assert(
'notifications service keeps the last ten notifications in history'
)

// durationFor lives in QML, so pin the Critical branch and evaluate the same
// clamp the service uses for Low/Normal floors so Critical expireTimeout is
// honoured without regressing the other urgencies' minimums.
assert(
/case NotificationUrgency\.Critical: \{[\s\S]*?var requested = requestedDuration\(expireTimeout\)[\s\S]*?if \(requested <= 0\) return 0[\s\S]*?return Math\.min\(maxPopupDuration, requested\)/.test(serviceQml),
'notifications service honours a positive expireTimeout for critical urgency'
/case NotificationUrgency\.Critical:\s*\n\s*return NotificationLogic\.criticalPopupDuration\(expireTimeout, maxPopupDuration\)/.test(serviceQml),
'notifications service uses the tested critical popup duration policy'
)
assert(
/case NotificationUrgency\.Critical: \{[\s\S]*?if \(requested <= 0\) return 0/.test(serviceQml),
'notifications service keeps critical sticky when expireTimeout is 0 or absent'
)
assert(
/case NotificationUrgency\.Low:\s*\n\s*return Math\.min\(maxPopupDuration, Math\.max\(lowPopupDuration, requestedDuration\(expireTimeout\)\)\)/.test(serviceQml),
/case NotificationUrgency\.Low:\s*\n\s*return Math\.min\(maxPopupDuration, Math\.max\(lowPopupDuration, NotificationLogic\.requestedDuration\(expireTimeout\)\)\)/.test(serviceQml),
'notifications service keeps the Low urgency duration floor'
)
assert(
/default:\s*\n\s*return Math\.min\(maxPopupDuration, Math\.max\(normalPopupDuration, requestedDuration\(expireTimeout\)\)\)/.test(serviceQml),
/default:\s*\n\s*return Math\.min\(maxPopupDuration, Math\.max\(normalPopupDuration, NotificationLogic\.requestedDuration\(expireTimeout\)\)\)/.test(serviceQml),
'notifications service keeps the Normal urgency duration floor'
)

function requestedDuration(expireTimeout) {
const ms = Number(expireTimeout || 0)
if (!Number.isFinite(ms) || ms <= 0) return 0
return Math.round(ms)
}
function durationFor(urgency, expireTimeout, { low = 5000, normal = 8000, max = 30000 } = {}) {
// Mirror Service.qml: Critical=2, Low=0, Normal=1 (FreeDesktop / Quickshell).
if (urgency === 2) {
const requested = requestedDuration(expireTimeout)
if (requested <= 0) return 0
return Math.min(max, requested)
}
if (urgency === 0) return Math.min(max, Math.max(low, requestedDuration(expireTimeout)))
return Math.min(max, Math.max(normal, requestedDuration(expireTimeout)))
}
assertEqual(durationFor(2, 30000), 30000, 'critical with a positive expireTimeout gets a finite duration')
assertEqual(durationFor(2, 60000), 30000, 'critical expireTimeout is clamped to maxPopupDuration')
assertEqual(durationFor(2, 0), 0, 'critical with expireTimeout 0 stays sticky')
assertEqual(durationFor(2, undefined), 0, 'critical with a missing expireTimeout stays sticky')
assertEqual(durationFor(0, 1000), 5000, 'low urgency keeps its minimum floor')
assertEqual(durationFor(1, 1000), 8000, 'normal urgency keeps its minimum floor')
assertEqual(durationFor(0, 25000), 25000, 'low urgency honouring a request above the floor is unchanged')
assertEqual(durationFor(1, 25000), 25000, 'normal urgency honouring a request above the floor is unchanged')
assert(
/function showHistory\(\): string \{\s*return service\.showRecentHistory\(\)\s*\}/.test(serviceQml),
'notifications history IPC replays recent notifications'
Expand Down