From 6bf4ed31cb87b0f4564c1c8858fd3bff64b2aaf9 Mon Sep 17 00:00:00 2001 From: Michael Palmos Date: Thu, 29 Feb 2024 16:44:43 +1000 Subject: [PATCH] Style tweaks to naming of stuff. --- Cargo.lock | 2 +- src/bus/dbus.rs | 44 +++++++++++++++++++------------------------- src/config.rs | 16 ++++++++-------- wired.ron | 9 +++++---- 4 files changed, 33 insertions(+), 38 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2ee018e..6aa5576 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2172,7 +2172,7 @@ dependencies = [ [[package]] name = "wired" -version = "0.10.5" +version = "0.10.6" dependencies = [ "bitflags", "cairo-rs", diff --git a/src/bus/dbus.rs b/src/bus/dbus.rs index c26f354..beb02f4 100644 --- a/src/bus/dbus.rs +++ b/src/bus/dbus.rs @@ -21,7 +21,7 @@ use serde::Serialize; use tiny_skia; use crate::bus::dbus_codegen::{self, OrgFreedesktopNotifications}; -use crate::config::TimeoutBehavior; +use crate::config::ZeroTimeoutBehavior; use crate::maths_utility; use crate::Config; @@ -234,6 +234,12 @@ pub enum ImageData { Dynamic(DynamicImage), } +#[derive(Clone, Serialize, Debug)] +pub enum Timeout { + Milliseconds(i32), + NeverExpire, +} + #[derive(Clone, Serialize)] pub struct Notification { pub id: u32, @@ -454,9 +460,18 @@ impl Notification { } let cfg = Config::get(); - let timeout = match cfg.timeout_behavior { - TimeoutBehavior::Legacy => legacy_timeout_behavior(expire_timeout, cfg.timeout), - TimeoutBehavior::DBusSpec => dbus_spec_timeout_behavior(expire_timeout, cfg.timeout), + let timeout = match cfg.zero_timeout_behavior { + ZeroTimeoutBehavior::UseDefault => Timeout::Milliseconds(if expire_timeout <= 0 { cfg.timeout } else { expire_timeout }), + ZeroTimeoutBehavior::NeverExpire => { + // From the spec: https://specifications.freedesktop.org/notification-spec/notification-spec-latest.html + if expire_timeout < 0 { + Timeout::Milliseconds(cfg.timeout) + } else if expire_timeout == 0 { + Timeout::NeverExpire + } else { + Timeout::Milliseconds(expire_timeout) + } + } }; Self { @@ -495,24 +510,3 @@ impl Notification { } } } - -#[derive(Clone, Serialize, Debug)] -pub enum Timeout { - Milliseconds(i32), - NeverExpire, -} - -fn legacy_timeout_behavior(timeout: i32, default: i32) -> Timeout { - Timeout::Milliseconds(if timeout <= 0 { default } else { timeout }) -} - -// This comes from the spec, see https://specifications.freedesktop.org/notification-spec/notification-spec-latest.html -fn dbus_spec_timeout_behavior(timeout: i32, default: i32) -> Timeout { - if timeout < 0 { - Timeout::Milliseconds(default) - } else if timeout == 0 { - Timeout::NeverExpire - } else { - Timeout::Milliseconds(timeout) - } -} diff --git a/src/config.rs b/src/config.rs index fcb37f9..d33934e 100644 --- a/src/config.rs +++ b/src/config.rs @@ -118,7 +118,7 @@ pub struct Config { // How to handle various DBus expire_timeout values #[serde(default)] - pub timeout_behavior: TimeoutBehavior, + pub zero_timeout_behavior: ZeroTimeoutBehavior, // Optional Properties @@ -504,16 +504,16 @@ impl Default for ShortcutsConfig { } #[derive(Debug, Deserialize, Clone)] -pub enum TimeoutBehavior { - // Legacy treats zero as 'use config default' - Legacy, - // DBusSpec treats zero as 'never expire' - DBusSpec, +pub enum ZeroTimeoutBehavior { + // Uses `expire_time`. + UseDefault, + // Treats zero as 'never expire'. + NeverExpire, } -impl Default for TimeoutBehavior { +impl Default for ZeroTimeoutBehavior { fn default() -> Self { - Self::DBusSpec + Self::NeverExpire } } diff --git a/wired.ron b/wired.ron index e9864c2..ed441a1 100644 --- a/wired.ron +++ b/wired.ron @@ -7,10 +7,11 @@ // 1000ms = 1s. timeout: 10000, - // Treats expire_timeout values of zero as 'never expire', see - // https://specifications.freedesktop.org/notification-spec/notification-spec-latest.html for details. - // For the original behavior of giving notifications with 'expire_timeout: 0' the default 'timeout' value, use 'Legacy'. - timeout_behavior: DBusSpec, + // How should we handle `expire_timeout` values of zero? + // `UseDefault`: use `timeout`. + // `NeverExpire`: show this notification forever. + // The latter is technically correct according to the notification spec: https://specifications.freedesktop.org/notification-spec/notification-spec-latest.html + zero_timeout_behavior: NeverExpire, // `poll_interval` decides decides how often (in milliseconds) Wired checks events, // draws notifications (if necessary) -- the update loop while any notification is present.