diff --git a/default_config.toml b/default_config.toml index 8d534ad..2307712 100644 --- a/default_config.toml +++ b/default_config.toml @@ -34,3 +34,4 @@ [other] fallback_icon = "🤨" deduplicate_icons = false +separator = ": " diff --git a/src/config.rs b/src/config.rs index a1f5c92..57c83f6 100644 --- a/src/config.rs +++ b/src/config.rs @@ -7,6 +7,7 @@ use std::io::{BufReader, Read, Write}; use std::path::PathBuf; const DEFAULT_FALLBACK_ICON: &str = "-"; +const DEFAULT_SEPARATOR: &str = ": "; const DEFAULT_CONFIG: &str = include_str!("../default_config.toml"); #[derive(Debug, Default, Clone)] @@ -19,6 +20,7 @@ pub struct Config { #[serde(default, deny_unknown_fields)] pub struct Other { pub fallback_icon: Option, + pub separator: Option, pub deduplicate_icons: bool, } @@ -46,6 +48,24 @@ impl Config { .unwrap_or(DEFAULT_FALLBACK_ICON) } + pub fn separator(&self) -> &str { + let sep = self.other.separator.as_deref(); + if let Some(sep) = sep { + let fallback_icon = self.fallback_icon(); + if let Some(icon) = self.mappings.values().find(|icon| icon.contains(sep)) { + error!("Can't use separator: \"{sep}\" as it is contained in icon: \"{icon}\"."); + DEFAULT_SEPARATOR + } else if fallback_icon.contains(sep) { + error!("Can't use separator: \"{sep}\" as it is contained in fallback icon: \"{fallback_icon}\""); + DEFAULT_SEPARATOR + } else { + sep + } + } else { + DEFAULT_SEPARATOR + } + } + pub fn path() -> Result { let mut user_path = dirs::config_dir().context("Could not find the configuration path")?; let mut system_path = PathBuf::from("/etc/xdg"); diff --git a/src/main.rs b/src/main.rs index dd1d349..4e4fc09 100644 --- a/src/main.rs +++ b/src/main.rs @@ -116,18 +116,19 @@ fn run() -> Result<()> { loop { // TODO: watch for changes using inotify and read the config only when needed let config = Config::new()?; + let sep: &str = config.separator(); let workspaces = wm.get_windows_in_each_workspace()?; for (name, windows) in workspaces { let new_name = pretty_windows(&config, &windows); let num = name - .split(':') + .split(sep) .next() .context("Unexpected workspace name")?; if new_name.is_empty() { wm.rename_workspace(&name, num)?; } else { - wm.rename_workspace(&name, &format!("{num}: {new_name}"))?; + wm.rename_workspace(&name, &format!("{num}{sep}{new_name}"))?; } }