From f92586630d6d66169ad057f738c2133e9bbae6ef Mon Sep 17 00:00:00 2001 From: Tassilo Horn Date: Wed, 6 Apr 2022 07:00:58 +0200 Subject: [PATCH] Refactoring towards handling click events --- src/bar/module.rs | 2 +- src/bar/module/battery.rs | 8 +++++--- src/bar/module/date.rs | 8 +++++--- src/bar/module/sysinfo.rs | 8 +++++--- src/bar/module/window.rs | 8 +++++--- 5 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/bar/module.rs b/src/bar/module.rs index b873e88..30a9fc2 100644 --- a/src/bar/module.rs +++ b/src/bar/module.rs @@ -31,6 +31,6 @@ pub trait BarModuleFn { fn name() -> &'static str where Self: Sized; - fn instance(&self) -> &str; + fn matches(&self, name: &str, instance: &str) -> bool; fn build(&self) -> s::Block; } diff --git a/src/bar/module/battery.rs b/src/bar/module/battery.rs index 450bf8e..b881f80 100644 --- a/src/bar/module/battery.rs +++ b/src/bar/module/battery.rs @@ -23,6 +23,8 @@ use std::cell::RefCell; use std::collections::HashSet; use swaybar_types as s; +const NAME: &str = "battery"; + pub struct BarModuleBattery { config: config::ModuleConfig, manager: RefCell, @@ -110,11 +112,11 @@ impl BarModuleFn for BarModuleBattery { } fn name() -> &'static str { - "battery" + NAME } - fn instance(&self) -> &str { - &self.config.instance + fn matches(&self, name: &str, instance: &str) -> bool { + NAME == name && self.config.instance == instance } fn build(&self) -> s::Block { diff --git a/src/bar/module/date.rs b/src/bar/module/date.rs index 77e5300..3cbd95b 100644 --- a/src/bar/module/date.rs +++ b/src/bar/module/date.rs @@ -19,6 +19,8 @@ use crate::bar::module::config; use crate::bar::module::BarModuleFn; use swaybar_types as s; +const NAME: &str = "date"; + pub struct BarModuleDate { config: config::ModuleConfig, } @@ -38,11 +40,11 @@ impl BarModuleFn for BarModuleDate { } fn name() -> &'static str { - "date" + NAME } - fn instance(&self) -> &str { - &self.config.instance + fn matches(&self, name: &str, instance: &str) -> bool { + NAME == name && self.config.instance == instance } fn build(&self) -> s::Block { diff --git a/src/bar/module/sysinfo.rs b/src/bar/module/sysinfo.rs index a41adea..2695f89 100644 --- a/src/bar/module/sysinfo.rs +++ b/src/bar/module/sysinfo.rs @@ -25,6 +25,8 @@ use sysinfo as si; use sysinfo::ProcessorExt; use sysinfo::SystemExt; +const NAME: &str = "sysinfo"; + pub struct BarModuleSysInfo { config: config::ModuleConfig, system: RefCell, @@ -93,11 +95,11 @@ impl BarModuleFn for BarModuleSysInfo { } fn name() -> &'static str { - "sysinfo" + NAME } - fn instance(&self) -> &str { - &self.config.instance + fn matches(&self, name: &str, instance: &str) -> bool { + NAME == name && self.config.instance == instance } fn build(&self) -> s::Block { diff --git a/src/bar/module/window.rs b/src/bar/module/window.rs index 2022d23..8113fdf 100644 --- a/src/bar/module/window.rs +++ b/src/bar/module/window.rs @@ -22,6 +22,8 @@ use crate::ipc; use crate::ipc::NodeMethods; use swaybar_types as s; +const NAME: &str = "window"; + pub struct BarModuleWindow { config: config::ModuleConfig, } @@ -41,11 +43,11 @@ impl BarModuleFn for BarModuleWindow { } fn name() -> &'static str { - "window" + NAME } - fn instance(&self) -> &str { - &self.config.instance + fn matches(&self, name: &str, instance: &str) -> bool { + NAME == name && self.config.instance == instance } fn build(&self) -> s::Block {