mirror of
https://github.com/Zedfrigg/ironbar.git
synced 2025-07-01 10:41:03 +02:00
refactor: use macro for module config matching
This commit is contained in:
parent
ebf7a97a85
commit
de80b99e64
1 changed files with 16 additions and 40 deletions
56
src/bar.rs
56
src/bar.rs
|
@ -85,48 +85,24 @@ fn load_modules(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_modules(content: >k::Box, modules: Vec<ModuleConfig>, info: ModuleInfo) {
|
fn add_modules(content: >k::Box, modules: Vec<ModuleConfig>, info: ModuleInfo) {
|
||||||
|
macro_rules! add_module {
|
||||||
|
($module:expr, $name:literal) => {{
|
||||||
|
let widget = $module.into_widget(&info);
|
||||||
|
widget.set_widget_name($name);
|
||||||
|
content.add(&widget);
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
|
||||||
for config in modules {
|
for config in modules {
|
||||||
match config {
|
match config {
|
||||||
ModuleConfig::Clock(module) => {
|
ModuleConfig::Clock(module) => add_module!(module, "clock"),
|
||||||
let widget = module.into_widget(&info);
|
ModuleConfig::Mpd(module) => add_module!(module, "mpd"),
|
||||||
widget.set_widget_name("clock");
|
ModuleConfig::Tray(module) => add_module!(module, "tray"),
|
||||||
content.add(&widget);
|
ModuleConfig::Workspaces(module) => add_module!(module, "workspaces"),
|
||||||
}
|
ModuleConfig::SysInfo(module) => add_module!(module, "sysinfo"),
|
||||||
ModuleConfig::Mpd(module) => {
|
ModuleConfig::Launcher(module) => add_module!(module, "launcher"),
|
||||||
let widget = module.into_widget(&info);
|
ModuleConfig::Script(module) => add_module!(module, "script"),
|
||||||
widget.set_widget_name("mpd");
|
ModuleConfig::Focused(module) => add_module!(module, "focused"),
|
||||||
content.add(&widget);
|
|
||||||
}
|
|
||||||
ModuleConfig::Tray(module) => {
|
|
||||||
let widget = module.into_widget(&info);
|
|
||||||
widget.set_widget_name("tray");
|
|
||||||
content.add(&widget);
|
|
||||||
}
|
|
||||||
ModuleConfig::Workspaces(module) => {
|
|
||||||
let widget = module.into_widget(&info);
|
|
||||||
widget.set_widget_name("workspaces");
|
|
||||||
content.add(&widget);
|
|
||||||
}
|
|
||||||
ModuleConfig::SysInfo(module) => {
|
|
||||||
let widget = module.into_widget(&info);
|
|
||||||
widget.set_widget_name("sysinfo");
|
|
||||||
content.add(&widget);
|
|
||||||
}
|
|
||||||
ModuleConfig::Launcher(module) => {
|
|
||||||
let widget = module.into_widget(&info);
|
|
||||||
widget.set_widget_name("launcher");
|
|
||||||
content.add(&widget);
|
|
||||||
}
|
|
||||||
ModuleConfig::Script(module) => {
|
|
||||||
let widget = module.into_widget(&info);
|
|
||||||
widget.set_widget_name("script");
|
|
||||||
content.add(&widget);
|
|
||||||
}
|
|
||||||
ModuleConfig::Focused(module) => {
|
|
||||||
let widget = module.into_widget(&info);
|
|
||||||
widget.set_widget_name("focused");
|
|
||||||
content.add(&widget);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue