Skip to content

Commit

Permalink
fix: add display property as a cmd opt
Browse files Browse the repository at this point in the history
Removed this previously because wm_property was deprecated, but I
should've instead changed it to display_property
  • Loading branch information
roosta committed Nov 12, 2023
1 parent c48394b commit 5f169e6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,11 @@ display_property = "instance"
Possible options are `class`, `instance`, and `name`, and will default to `class`
if not present.

You can alternatively supply cmd argument:

```sh
i3wsr --display-property instance
```
### Icons

You can configure icons for your WM property, a very basic preset for
Expand Down
11 changes: 2 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,8 @@ fn get_title(
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"
}
Some(prop) => prop,
None => "class",
};

// Check for aliases using pre-compiled regex
Expand Down
23 changes: 23 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ enum Icons {
Awesome,
}

#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum, Debug)]
enum Properties {
Class,
Instance,
Name,
}

/// i3wsr config
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
Expand All @@ -34,6 +41,10 @@ struct Args {
#[arg(short, long)]
remove_duplicates: bool,

/// Which window property to use when no alias is found
#[arg(short = 'p', long)]
display_property: Option<Properties>,

/// What character used to split the workspace title string
#[arg(short = 'a', long)]
split_at: Option<String>,
Expand Down Expand Up @@ -95,6 +106,18 @@ fn setup() -> Result<Config, Box<dyn Error>> {
config.general.insert("split_at".to_string(), split_char);
}

// wm property
let display_property = match args.display_property {
Some(prop) => match prop {
Properties::Class => String::from("class"),
Properties::Instance => String::from("instance"),
Properties::Name => String::from("name"),
},
None => String::from("class"),
};
config
.general
.insert("display_property".to_string(), display_property);
Ok(config)
}

Expand Down

0 comments on commit 5f169e6

Please sign in to comment.