Skip to content

Commit 4c39bc2

Browse files
authored
Merge pull request #36 from cyrinux/35-variables-in-config
2 parents 670789f + a7e12b0 commit 4c39bc2

File tree

5 files changed

+36
-17
lines changed

5 files changed

+36
-17
lines changed

Cargo.lock

+9-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "hyprland-autoname-workspaces"
33
authors = ["Cyril Levis", "Maxim Baz"]
4-
version = "0.4.1"
4+
version = "0.4.2"
55
edition = "2021"
66
categories = ["gui"]
77
keywords = ["linux", "desktop-application", "hyprland","waybar","wayland"]

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ _You can use regex everywhere, and its case sensitive by default_
4545

4646
Edit the mapping of applications with `class = "icon"` in the `[icons]` part.
4747

48+
In icons value, you can use the placeholder `${class}` and `${title}`.
49+
50+
Example:
51+
52+
```
53+
[icons]
54+
DEFAULT = "${class}: ${title}"
55+
...
56+
```
57+
4858
- You can exclude applications in the `[exclude]` with `class = title`.
4959

5060
In the `exclude` part, the key is the window `class`, and the value the `title`.

src/config/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ pub fn create_default_config(cfg_path: &PathBuf) -> Result<&'static str, Box<dyn
107107
# Add your icons mapping
108108
# use double quote the key and the value
109109
# take class name from 'hyprctl clients'
110-
"DEFAULT" = ""
110+
"DEFAULT" = " ${class}: ${title}"
111111
"(?i)Kitty" = "term"
112112
"[Ff]irefox" = "browser"
113113
"(?i)waydroid.*" = "droid"

src/renamer/mod.rs

+15-6
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl Renamer {
6565
let workspace_id = client.workspace.id;
6666
let icon = self
6767
.class_title_to_icon(&class, &title)
68-
.unwrap_or_else(|| self.class_to_icon(&class));
68+
.unwrap_or_else(|| self.class_to_icon(&class, &title));
6969

7070
let is_dup = !deduper.insert(format!("{workspace_id}-{icon}"));
7171
let should_dedup = self.args.dedup && is_dup;
@@ -161,7 +161,7 @@ impl Renamer {
161161
}
162162

163163
#[inline(always)]
164-
fn class_to_icon(&self, class: &str) -> String {
164+
fn class_to_icon(&self, class: &str, title: &str) -> String {
165165
let default_value = String::from("no default icon");
166166
let cfg = &self.cfg.lock().expect("Unable to obtain lock for config");
167167
cfg.config
@@ -180,6 +180,8 @@ impl Renamer {
180180
.map(|(_, icon)| icon.clone())
181181
.unwrap_or(default_value)
182182
})
183+
.replace("${class}", &class)
184+
.replace("${title}", &title)
183185
}
184186

185187
#[inline(always)]
@@ -193,7 +195,11 @@ impl Renamer {
193195
title_icon
194196
.iter()
195197
.find(|(re_title, _)| re_title.is_match(title))
196-
.map(|(_, icon)| icon.to_string())
198+
.map(|(_, icon)| {
199+
icon.to_string()
200+
.replace("${class}", &class)
201+
.replace("${title}", &title)
202+
})
197203
})
198204
}
199205

@@ -234,8 +240,8 @@ mod tests {
234240
dedup: false,
235241
},
236242
);
237-
assert_eq!(renamer.class_to_icon("kittY"), "term");
238-
assert_eq!(renamer.class_to_icon("Kitty"), "term");
243+
assert_eq!(renamer.class_to_icon("kittY", "#"), "term");
244+
assert_eq!(renamer.class_to_icon("Kitty", "~"), "term");
239245
}
240246

241247
#[test]
@@ -250,7 +256,10 @@ mod tests {
250256
dedup: false,
251257
},
252258
);
253-
assert_eq!(renamer.class_to_icon("shoudBeDefault"), "\u{f059}");
259+
assert_eq!(
260+
renamer.class_to_icon("class", "title"),
261+
"\u{f059} class: title"
262+
);
254263
}
255264

256265
#[test]

0 commit comments

Comments
 (0)