Refactoring towards handling click events

main
Tassilo Horn 3 years ago
parent 345c91a559
commit f92586630d
  1. 2
      src/bar/module.rs
  2. 8
      src/bar/module/battery.rs
  3. 8
      src/bar/module/date.rs
  4. 8
      src/bar/module/sysinfo.rs
  5. 8
      src/bar/module/window.rs

@ -31,6 +31,6 @@ pub trait BarModuleFn {
fn name() -> &'static str fn name() -> &'static str
where where
Self: Sized; Self: Sized;
fn instance(&self) -> &str; fn matches(&self, name: &str, instance: &str) -> bool;
fn build(&self) -> s::Block; fn build(&self) -> s::Block;
} }

@ -23,6 +23,8 @@ use std::cell::RefCell;
use std::collections::HashSet; use std::collections::HashSet;
use swaybar_types as s; use swaybar_types as s;
const NAME: &str = "battery";
pub struct BarModuleBattery { pub struct BarModuleBattery {
config: config::ModuleConfig, config: config::ModuleConfig,
manager: RefCell<bat::Manager>, manager: RefCell<bat::Manager>,
@ -110,11 +112,11 @@ impl BarModuleFn for BarModuleBattery {
} }
fn name() -> &'static str { fn name() -> &'static str {
"battery" NAME
} }
fn instance(&self) -> &str { fn matches(&self, name: &str, instance: &str) -> bool {
&self.config.instance NAME == name && self.config.instance == instance
} }
fn build(&self) -> s::Block { fn build(&self) -> s::Block {

@ -19,6 +19,8 @@ use crate::bar::module::config;
use crate::bar::module::BarModuleFn; use crate::bar::module::BarModuleFn;
use swaybar_types as s; use swaybar_types as s;
const NAME: &str = "date";
pub struct BarModuleDate { pub struct BarModuleDate {
config: config::ModuleConfig, config: config::ModuleConfig,
} }
@ -38,11 +40,11 @@ impl BarModuleFn for BarModuleDate {
} }
fn name() -> &'static str { fn name() -> &'static str {
"date" NAME
} }
fn instance(&self) -> &str { fn matches(&self, name: &str, instance: &str) -> bool {
&self.config.instance NAME == name && self.config.instance == instance
} }
fn build(&self) -> s::Block { fn build(&self) -> s::Block {

@ -25,6 +25,8 @@ use sysinfo as si;
use sysinfo::ProcessorExt; use sysinfo::ProcessorExt;
use sysinfo::SystemExt; use sysinfo::SystemExt;
const NAME: &str = "sysinfo";
pub struct BarModuleSysInfo { pub struct BarModuleSysInfo {
config: config::ModuleConfig, config: config::ModuleConfig,
system: RefCell<si::System>, system: RefCell<si::System>,
@ -93,11 +95,11 @@ impl BarModuleFn for BarModuleSysInfo {
} }
fn name() -> &'static str { fn name() -> &'static str {
"sysinfo" NAME
} }
fn instance(&self) -> &str { fn matches(&self, name: &str, instance: &str) -> bool {
&self.config.instance NAME == name && self.config.instance == instance
} }
fn build(&self) -> s::Block { fn build(&self) -> s::Block {

@ -22,6 +22,8 @@ use crate::ipc;
use crate::ipc::NodeMethods; use crate::ipc::NodeMethods;
use swaybar_types as s; use swaybar_types as s;
const NAME: &str = "window";
pub struct BarModuleWindow { pub struct BarModuleWindow {
config: config::ModuleConfig, config: config::ModuleConfig,
} }
@ -41,11 +43,11 @@ impl BarModuleFn for BarModuleWindow {
} }
fn name() -> &'static str { fn name() -> &'static str {
"window" NAME
} }
fn instance(&self) -> &str { fn matches(&self, name: &str, instance: &str) -> bool {
&self.config.instance NAME == name && self.config.instance == instance
} }
fn build(&self) -> s::Block { fn build(&self) -> s::Block {

Loading…
Cancel
Save