Skip to content

Commit

Permalink
Style tweaks to naming of stuff.
Browse files Browse the repository at this point in the history
  • Loading branch information
Toqozz committed Feb 29, 2024
1 parent 4af367b commit 6bf4ed3
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 38 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 19 additions & 25 deletions src/bus/dbus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
}
16 changes: 8 additions & 8 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
}
}

Expand Down
9 changes: 5 additions & 4 deletions wired.ron
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 6bf4ed3

Please sign in to comment.