Skip to content

Commit

Permalink
add ability to disable items with a config file
Browse files Browse the repository at this point in the history
  • Loading branch information
acheronfail committed Dec 28, 2023
1 parent fae1a6b commit fae1e70
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,16 @@ pub struct AppConfig {
/// List of the items for the bar
pub items: Vec<Item>,

/// Optional list of item indices to disable.
/// Useful when defining additional config files which disable items defined in previous config
/// files.
#[serde(default)]
pub disable: Vec<usize>,

/// Path to the socket to use for ipc. Useful when having multiple bars to separate their sockets.
/// The CLI option takes precedence over this.
#[serde(rename = "socket")]
socket: Option<PathBuf>,
/// Runtime only cache for the resolved socket path.

/// Runtime only cache for index to name item mappings
#[serde(skip)]
Expand Down
5 changes: 5 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ fn setup_i3_bar(config: &RcCell<AppConfig>) -> Result<(RcCell<Bar>, RcCell<Dispa

// Iterate config and create bar items
for (idx, item) in config.items.iter().enumerate() {
if config.disable.contains(&idx) {
log::info!("not creating item {idx} since it was disabled by config");
continue;
}

let bar_item = item.to_bar_item();

// all cheaply cloneable (smart pointers, senders, etc)
Expand Down

0 comments on commit fae1e70

Please sign in to comment.