swayrbar config

main
Tassilo Horn 3 years ago
parent a2e1b3343c
commit 5e80619761
  1. 2
      swayr/src/config.rs
  2. 39
      swayrbar/src/bar.rs
  3. 23
      swayrbar/src/config.rs
  4. 4
      swayrbar/src/module/battery.rs
  5. 8
      swayrbar/src/module/date.rs
  6. 6
      swayrbar/src/module/sysinfo.rs
  7. 10
      swayrbar/src/module/window.rs

@ -305,7 +305,7 @@ pub fn load_config() -> Config {
}
#[test]
fn test_load_config() {
fn test_load_swayr_config() {
let cfg = cfg::load_config::<Config>("swayr");
println!("{:?}", cfg);
}

@ -29,25 +29,30 @@ pub fn start() {
env_logger::Builder::from_env(Env::default().default_filter_or("warn"))
.init();
let config = config::Config::default();
let mods: Arc<Vec<Box<dyn BarModuleFn>>> = Arc::new(vec![
module::window::BarModuleWindow::create(
module::window::BarModuleWindow::default_config("0".to_owned()),
),
module::sysinfo::BarModuleSysInfo::create(
module::sysinfo::BarModuleSysInfo::default_config("0".to_owned()),
),
module::battery::BarModuleBattery::create(
module::battery::BarModuleBattery::default_config("0".to_owned()),
),
module::date::BarModuleDate::create(
module::date::BarModuleDate::default_config("0".to_owned()),
),
]);
let config = config::load_config();
let refresh_interval = config.refresh_interval;
let mods: Arc<Vec<Box<dyn BarModuleFn>>> = Arc::new(create_modules(config));
let mods_for_input = mods.clone();
thread::spawn(move || handle_input(mods_for_input));
generate_status(&mods, config.refresh_interval);
generate_status(&mods, refresh_interval);
}
fn create_modules(config: config::Config) -> Vec<Box<dyn BarModuleFn>> {
let mut mods = vec![];
for mc in config.modules {
let m = match mc.name.as_str() {
"window" => module::window::BarModuleWindow::create(mc),
"sysinfo" => module::sysinfo::BarModuleSysInfo::create(mc),
"battery" => module::battery::BarModuleBattery::create(mc),
"date" => module::date::BarModuleDate::create(mc),
unknown => {
log::warn!("Unknown module name '{}'. Ignoring...", unknown);
continue;
}
};
mods.push(m);
}
mods
}
pub fn handle_input(mods: Arc<Vec<Box<dyn BarModuleFn>>>) {

@ -16,6 +16,7 @@
//! TOML configuration for swayrbar.
use crate::module::BarModuleFn;
use crate::shared::cfg;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
@ -25,8 +26,7 @@ pub struct Config {
pub refresh_interval: u64,
/// The list of modules to display in the given order, each one specified
/// as `"<module_type>/<instance>"`.
pub modules: Vec<String>,
pub module_configs: Vec<ModuleConfig>,
pub modules: Vec<ModuleConfig>,
}
#[derive(Debug, Serialize, Deserialize)]
@ -42,8 +42,13 @@ impl Default for Config {
fn default() -> Self {
Config {
refresh_interval: 1000,
modules: vec!["date/0".to_owned()],
module_configs: vec![
modules: vec![
crate::module::window::BarModuleWindow::default_config(
"0".to_owned(),
),
crate::module::sysinfo::BarModuleSysInfo::default_config(
"0".to_owned(),
),
crate::module::date::BarModuleDate::default_config(
"0".to_owned(),
),
@ -51,3 +56,13 @@ impl Default for Config {
}
}
}
pub fn load_config() -> Config {
cfg::load_config::<Config>("swayrbar")
}
#[test]
fn test_load_swayrbar_config() {
let cfg = cfg::load_config::<Config>("swayrbar");
println!("{:?}", cfg);
}

@ -99,7 +99,7 @@ impl BarModuleFn for BarModuleBattery {
name: NAME.to_owned(),
instance,
format: "🔋 Bat: {state_of_charge:{:5.1}}%, {state}, Health: {state_of_health:{:5.1}}%".to_owned(),
html_escape: true,
html_escape: false,
on_click: HashMap::new()
}
}
@ -114,7 +114,7 @@ impl BarModuleFn for BarModuleBattery {
name: Some(NAME.to_owned()),
instance: Some(self.config.instance.clone()),
full_text: text,
align: Some(s::Align::Right),
align: Some(s::Align::Left),
markup: Some(s::Markup::Pango),
short_text: None,
color: None,

@ -38,11 +38,7 @@ impl BarModuleFn for BarModuleDate {
instance,
format: "⏰ %F %X".to_owned(),
html_escape: false,
// TODO: Only for testing.
on_click: HashMap::from([(
"Left".to_owned(),
vec!["foot".to_owned(), "htop".to_owned()],
)]),
on_click: HashMap::new(),
}
}
@ -56,7 +52,7 @@ impl BarModuleFn for BarModuleDate {
name: Some(NAME.to_owned()),
instance: Some(self.config.instance.clone()),
full_text: text,
align: Some(s::Align::Right),
align: Some(s::Align::Left),
markup: Some(s::Markup::Pango),
short_text: None,
color: None,

@ -99,8 +99,10 @@ impl BarModuleFn for BarModuleSysInfo {
name: "sysinfo".to_owned(),
instance,
format: "💻 CPU: {cpu_usage:{:4.1}}% Mem: {mem_usage:{:4.1}}% Load: {load_avg_1:{:4.2}} / {load_avg_5:{:4.2}} / {load_avg_15:{:4.2}}".to_owned(),
html_escape: true,
on_click: HashMap::new(),
html_escape: false,
on_click: HashMap::from([
("Left".to_owned(),
vec!["foot".to_owned(), "htop".to_owned()])]),
}
}

@ -40,8 +40,14 @@ impl BarModuleFn for BarModuleWindow {
name: NAME.to_owned(),
instance,
format: "🪟 {title} — {app_name}".to_owned(),
html_escape: true,
on_click: HashMap::new(),
html_escape: false,
on_click: HashMap::from([(
"Left".to_owned(),
vec![
"swayr".to_owned(),
"switch-to-urgent-or-lru-window".to_owned(),
],
)]),
}
}

Loading…
Cancel
Save