Skip to content

Commit

Permalink
fix: handle no alias by adding display_prop conf
Browse files Browse the repository at this point in the history
After my last refactor of alias handling, there was one case I didn't
consider:

What happens if no alias is defined, but you still want to
display a different window property than class as the title value?, and
match icons on that.

This fixes that by adding a new config value "display_property". It will
be checked when no alias is located, and return a title based of that.
Finally class is used, and if no properties are found it will return
with error, reporting in stdout.
  • Loading branch information
roosta committed Nov 11, 2023
1 parent ea1b130 commit 2e1d4a7
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ fn get_title(
let wm_class = props.get(&WindowProperty::Class);
let wm_instance = props.get(&WindowProperty::Instance);
let wm_name = props.get(&WindowProperty::Title);
let display_prop = match config.general.get("display_property") {
Some(prop) => {
match prop.as_ref() {
"class" | "instance" | "name" => prop,
_ => "class"
}
},
None => {
"class"
}
};

// Check for aliases using pre-compiled regex
let title = {
Expand All @@ -54,12 +65,18 @@ fn get_title(
}) {
alias
} else {
if let Some(class) = wm_class {
class
// Handle display prop, if no alias is located, then check for existiance and
// display_prop to set a fallback title
if wm_name.is_some() && display_prop == "name" {
wm_name.unwrap()
} else if wm_instance.is_some() && display_prop == "instance" {
wm_instance.unwrap()
} else if wm_class.is_some() {
wm_class.unwrap()
} else {
Err(format!(
"failed to get any class given these window properties {:#?}",
props
"failed to get alias, display_prop {}, or class",
display_prop
))?
}
}
Expand Down Expand Up @@ -150,7 +167,7 @@ fn collect_titles(workspace: &Node, config: &Config, res: &regex::Compiled) -> V
let title = match get_title(&props, config, res) {
Ok(title) => title,
Err(e) => {
eprintln!("get_title error: {}", e);
eprintln!("get_title error: \"{}\" for workspace {:#?}", e, workspace);
continue;
}
};
Expand Down

0 comments on commit 2e1d4a7

Please sign in to comment.