|
|
@ -70,7 +70,7 @@ pub enum Type { |
|
|
|
pub trait NodeMethods { |
|
|
|
pub trait NodeMethods { |
|
|
|
fn iter(&self) -> NodeIter; |
|
|
|
fn iter(&self) -> NodeIter; |
|
|
|
fn get_type(&self) -> Type; |
|
|
|
fn get_type(&self) -> Type; |
|
|
|
fn get_app_name(&self) -> Result<&str, &str>; |
|
|
|
fn get_app_name(&self) -> &str; |
|
|
|
fn nodes_of_type(&self, t: Type) -> Vec<&s::Node>; |
|
|
|
fn nodes_of_type(&self, t: Type) -> Vec<&s::Node>; |
|
|
|
fn get_name(&self) -> &str; |
|
|
|
fn get_name(&self) -> &str; |
|
|
|
fn is_scratchpad(&self) -> bool; |
|
|
|
fn is_scratchpad(&self) -> bool; |
|
|
@ -120,17 +120,17 @@ impl NodeMethods for s::Node { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn get_app_name(&self) -> Result<&str, &str> { |
|
|
|
fn get_app_name(&self) -> &str { |
|
|
|
if let Some(app_id) = &self.app_id { |
|
|
|
if let Some(app_id) = &self.app_id { |
|
|
|
Ok(app_id) |
|
|
|
app_id |
|
|
|
} else if let Some(wp_class) = self |
|
|
|
} else if let Some(wp_class) = self |
|
|
|
.window_properties |
|
|
|
.window_properties |
|
|
|
.as_ref() |
|
|
|
.as_ref() |
|
|
|
.and_then(|wp| wp.class.as_ref()) |
|
|
|
.and_then(|wp| wp.class.as_ref()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Ok(wp_class) |
|
|
|
wp_class |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
Err("<unknown_app>") |
|
|
|
"<unknown_app>" |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -389,71 +389,47 @@ fn maybe_html_escape(do_it: bool, text: &str) -> String { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn format_marks(marks: &Vec<String>) -> String { |
|
|
|
|
|
|
|
if marks.is_empty() { |
|
|
|
|
|
|
|
"".to_string() |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
format!("[{}]", marks.join(", ")) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl DisplayFormat for DisplayNode<'_> { |
|
|
|
impl DisplayFormat for DisplayNode<'_> { |
|
|
|
fn format_for_display(&self, cfg: &config::Config) -> String { |
|
|
|
fn format_for_display(&self, cfg: &config::Config) -> String { |
|
|
|
let indent = cfg.get_format_indent(); |
|
|
|
let indent = cfg.get_format_indent(); |
|
|
|
let html_escape = cfg.get_format_html_escape(); |
|
|
|
let html_escape = cfg.get_format_html_escape(); |
|
|
|
|
|
|
|
let urgency_start = cfg.get_format_urgency_start(); |
|
|
|
|
|
|
|
let urgency_end = cfg.get_format_urgency_end(); |
|
|
|
|
|
|
|
let icon_dirs = cfg.get_format_icon_dirs(); |
|
|
|
|
|
|
|
// fallback_icon has no default value.
|
|
|
|
|
|
|
|
let fallback_icon: Option<Box<std::path::Path>> = cfg |
|
|
|
|
|
|
|
.get_format_fallback_icon() |
|
|
|
|
|
|
|
.as_ref() |
|
|
|
|
|
|
|
.map(|i| std::path::Path::new(i).to_owned().into_boxed_path()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let app_name_no_version = |
|
|
|
|
|
|
|
APP_NAME_AND_VERSION_RX.replace(self.node.get_app_name(), "$1"); |
|
|
|
|
|
|
|
|
|
|
|
match self.node.get_type() { |
|
|
|
let fmt = match self.node.get_type() { |
|
|
|
Type::Root => String::from("Cannot format Root"), |
|
|
|
Type::Root => String::from("Cannot format Root"), |
|
|
|
Type::Output => String::from("Cannot format Output"), |
|
|
|
Type::Output => String::from("Cannot format Output"), |
|
|
|
Type::Workspace => cfg |
|
|
|
Type::Workspace => cfg.get_format_workspace_format(), |
|
|
|
.get_format_workspace_format() |
|
|
|
Type::Container => cfg.get_format_container_format(), |
|
|
|
.replace("{indent}", &indent.repeat(self.get_indent_level())) |
|
|
|
Type::Window => cfg.get_format_window_format(), |
|
|
|
.replace("{layout}", format!("{:?}", self.node.layout).as_str()) |
|
|
|
}; |
|
|
|
.replace("{id}", format!("{}", self.node.id).as_str()) |
|
|
|
fmt.replace("{indent}", &indent.repeat(self.get_indent_level())) |
|
|
|
.replace( |
|
|
|
|
|
|
|
"{name}", |
|
|
|
|
|
|
|
&maybe_html_escape(html_escape, self.node.get_name()), |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
Type::Container => cfg |
|
|
|
|
|
|
|
.get_format_container_format() |
|
|
|
|
|
|
|
.replace("{indent}", &indent.repeat(self.get_indent_level())) |
|
|
|
|
|
|
|
.replace("{layout}", format!("{:?}", self.node.layout).as_str()) |
|
|
|
.replace("{layout}", format!("{:?}", self.node.layout).as_str()) |
|
|
|
.replace("{id}", format!("{}", self.node.id).as_str()) |
|
|
|
.replace("{id}", format!("{}", self.node.id).as_str()) |
|
|
|
.replace( |
|
|
|
.replace( |
|
|
|
"{marks}", |
|
|
|
"{marks}", |
|
|
|
&maybe_html_escape( |
|
|
|
&maybe_html_escape( |
|
|
|
html_escape, |
|
|
|
html_escape, |
|
|
|
&self.node.marks.join(", "), |
|
|
|
&format_marks(&self.node.marks), |
|
|
|
), |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
.replace( |
|
|
|
|
|
|
|
"{workspace_name}", |
|
|
|
|
|
|
|
&maybe_html_escape( |
|
|
|
|
|
|
|
html_escape, |
|
|
|
|
|
|
|
self.tree |
|
|
|
|
|
|
|
.get_workspace_node(self.node.id) |
|
|
|
|
|
|
|
.map_or("<no_workspace>", |w| w.get_name()), |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
), |
|
|
|
), |
|
|
|
Type::Window => { |
|
|
|
|
|
|
|
let urgency_start = cfg.get_format_urgency_start(); |
|
|
|
|
|
|
|
let urgency_end = cfg.get_format_urgency_end(); |
|
|
|
|
|
|
|
let icon_dirs = cfg.get_format_icon_dirs(); |
|
|
|
|
|
|
|
// fallback_icon has no default value.
|
|
|
|
|
|
|
|
let fallback_icon: Option<Box<std::path::Path>> = |
|
|
|
|
|
|
|
cfg.get_format_fallback_icon().as_ref().map(|i| { |
|
|
|
|
|
|
|
std::path::Path::new(i).to_owned().into_boxed_path() |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Some apps report, e.g., Gimp-2.10 but the icon is still named
|
|
|
|
|
|
|
|
// gimp.png.
|
|
|
|
|
|
|
|
let app_name = |
|
|
|
|
|
|
|
self.node.get_app_name().unwrap_or("_unknown_app_"); |
|
|
|
|
|
|
|
let app_name_no_version = |
|
|
|
|
|
|
|
APP_NAME_AND_VERSION_RX.replace(app_name, "$1"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cfg.get_format_window_format() |
|
|
|
|
|
|
|
.replace( |
|
|
|
|
|
|
|
"{indent}", |
|
|
|
|
|
|
|
&indent.repeat(self.get_indent_level()), |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
.replace( |
|
|
|
|
|
|
|
"{layout}", |
|
|
|
|
|
|
|
format!("{:?}", self.node.layout).as_str(), |
|
|
|
|
|
|
|
) |
|
|
|
) |
|
|
|
.replace("{id}", format!("{}", self.node.id).as_str()) |
|
|
|
|
|
|
|
.replace( |
|
|
|
.replace( |
|
|
|
"{urgency_start}", |
|
|
|
"{urgency_start}", |
|
|
|
if self.node.urgent { |
|
|
|
if self.node.urgent { |
|
|
@ -472,10 +448,11 @@ impl DisplayFormat for DisplayNode<'_> { |
|
|
|
) |
|
|
|
) |
|
|
|
.replace( |
|
|
|
.replace( |
|
|
|
"{app_name}", |
|
|
|
"{app_name}", |
|
|
|
&maybe_html_escape( |
|
|
|
&maybe_html_escape(html_escape, self.node.get_app_name()), |
|
|
|
html_escape, |
|
|
|
) |
|
|
|
self.node.get_app_name().unwrap_or_else(|e| e), |
|
|
|
.replace( |
|
|
|
), |
|
|
|
"{name}", |
|
|
|
|
|
|
|
&maybe_html_escape(html_escape, self.node.get_name()), |
|
|
|
) |
|
|
|
) |
|
|
|
.replace( |
|
|
|
.replace( |
|
|
|
"{workspace_name}", |
|
|
|
"{workspace_name}", |
|
|
@ -487,18 +464,17 @@ impl DisplayFormat for DisplayNode<'_> { |
|
|
|
), |
|
|
|
), |
|
|
|
) |
|
|
|
) |
|
|
|
.replace( |
|
|
|
.replace( |
|
|
|
"{marks}", |
|
|
|
"{workspace_name}", |
|
|
|
&maybe_html_escape( |
|
|
|
&maybe_html_escape( |
|
|
|
html_escape, |
|
|
|
html_escape, |
|
|
|
&self.node.marks.join(", "), |
|
|
|
self.tree |
|
|
|
|
|
|
|
.get_workspace_node(self.node.id) |
|
|
|
|
|
|
|
.map_or("<no_workspace>", |w| w.get_name()), |
|
|
|
), |
|
|
|
), |
|
|
|
) |
|
|
|
) |
|
|
|
.replace( |
|
|
|
.replace( |
|
|
|
"{app_icon}", |
|
|
|
"{app_icon}", |
|
|
|
util::get_icon( |
|
|
|
util::get_icon(self.node.get_app_name(), &icon_dirs) |
|
|
|
self.node.get_app_name().unwrap_or_else(|e| e), |
|
|
|
|
|
|
|
&icon_dirs, |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
.or_else(|| { |
|
|
|
.or_else(|| { |
|
|
|
util::get_icon(&app_name_no_version, &icon_dirs) |
|
|
|
util::get_icon(&app_name_no_version, &icon_dirs) |
|
|
|
}) |
|
|
|
}) |
|
|
@ -518,8 +494,6 @@ impl DisplayFormat for DisplayNode<'_> { |
|
|
|
&maybe_html_escape(html_escape, self.node.get_name()), |
|
|
|
&maybe_html_escape(html_escape, self.node.get_name()), |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn get_indent_level(&self) -> usize { |
|
|
|
fn get_indent_level(&self) -> usize { |
|
|
|
match self.indent_level { |
|
|
|
match self.indent_level { |
|
|
|