diff options
| author | Danilo M. <danix@danix.xyz> | 2026-09-15 14:05:38 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-09-15 14:05:38 +0200 |
| commit | 08349a30ca4221d399559481cb520864e5fe8d8a (patch) | |
| tree | 58e88230c3f40f25d228e2ffa948f25307edf1e2 | |
| parent | 6d5a9ef98008c998b1960d7febbebe21224e9e1b (diff) | |
| download | notifyd-08349a30ca4221d399559481cb520864e5fe8d8a.tar.gz notifyd-08349a30ca4221d399559481cb520864e5fe8d8a.zip | |
fix: honour the freedesktop expire_timeout direction
The spec says -1 means the server decides and 0 means never; the code had
them swapped, so a plain notify-send (libnotify's default is -1) became
immortal and an explicit never (-t 0) got the urgency default. Found by the
live handover test, where notify-send produced expires 0.
The urgency default is unchanged: low and normal 10s, critical never.
| -rw-r--r-- | internal/notify/policy.go | 16 | ||||
| -rw-r--r-- | internal/notify/policy_test.go | 8 |
2 files changed, 14 insertions, 10 deletions
diff --git a/internal/notify/policy.go b/internal/notify/policy.go index c1dc647..5c70390 100644 --- a/internal/notify/policy.go +++ b/internal/notify/policy.go @@ -22,8 +22,9 @@ const ( Critical Urgency = "critical" ) -// DefaultTimeoutMS is the balloon lifetime for an urgency when the client sends -// expire_timeout 0. Critical never expires, which is 0 here. +// DefaultTimeoutMS is the balloon lifetime for an urgency when the client +// leaves the choice to the server (expire_timeout -1). Critical never expires, +// which is 0 here. func DefaultTimeoutMS(u Urgency) int64 { switch u { case Low, Normal: @@ -33,14 +34,17 @@ func DefaultTimeoutMS(u Urgency) int64 { } } -// EffectiveTimeoutMS resolves the client's expire_timeout: 0 means the urgency -// default, -1 means never, anything positive is milliseconds and wins. +// EffectiveTimeoutMS resolves the client's expire_timeout per the freedesktop +// spec: -1 means the server decides (the urgency default), 0 means never, and +// anything positive is milliseconds and wins. The spec is precise about the +// direction and libnotify's default is -1, so getting it backwards would make +// every plain notify-send immortal. func EffectiveTimeoutMS(expire int32, u Urgency) int64 { switch { case expire == -1: - return 0 - case expire == 0: return DefaultTimeoutMS(u) + case expire == 0: + return 0 default: return int64(expire) } diff --git a/internal/notify/policy_test.go b/internal/notify/policy_test.go index ef5bb72..378c573 100644 --- a/internal/notify/policy_test.go +++ b/internal/notify/policy_test.go @@ -46,10 +46,10 @@ func TestEffectiveTimeoutMS(t *testing.T) { u Urgency want int64 }{ - {"zero uses low default", 0, Low, 10_000}, - {"zero uses normal default", 0, Normal, 10_000}, - {"zero critical never", 0, Critical, 0}, - {"minus one never", -1, Normal, 0}, + {"minus one uses low default", -1, Low, 10_000}, + {"minus one uses normal default", -1, Normal, 10_000}, + {"minus one critical never", -1, Critical, 0}, + {"zero never", 0, Normal, 0}, {"explicit wins", 3_000, Normal, 3_000}, {"sub second exact", 1, Normal, 1}, } |
