Skip to content

Commit 80cb86b

Browse files
committed
COD-121: Refactor workspace identification from i32 to WorkspaceType
1 parent 660d055 commit 80cb86b

File tree

3 files changed

+232
-119
lines changed

3 files changed

+232
-119
lines changed

src/config/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,8 @@ fn migrate_config_file(
255255

256256
pub fn create_default_config(cfg_path: &PathBuf) -> Result<String, Box<dyn Error + 'static>> {
257257
// TODO: maybe we should dump the config from the default values of the struct?
258-
let default_config = format!(r#"version = "{VERSION}"
258+
let default_config = format!(
259+
r#"version = "{VERSION}"
259260
260261
# [format]
261262
# Deduplicate icons if enable.
@@ -349,7 +350,8 @@ aProgram = "^$" # will match null title for aProgram
349350
9 = "nine"
350351
10 = "ten"
351352
352-
"#);
353+
"#
354+
);
353355

354356
let mut config_file = File::create(cfg_path)?;
355357
write!(&mut config_file, "{}", default_config.trim())?;

src/renamer/formatter.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@ use crate::renamer::ConfigFile;
22
use crate::renamer::IconStatus::*;
33
use crate::{AppClient, Renamer};
44
use hyprland::data::FullscreenMode;
5+
use hyprland::shared::WorkspaceType;
56
use std::collections::HashMap;
67
use strfmt::strfmt;
78

89
#[derive(Clone)]
910
pub struct AppWorkspace {
10-
pub id: i32,
11+
pub id: WorkspaceType,
1112
pub clients: Vec<AppClient>,
1213
}
1314

1415
impl AppWorkspace {
15-
pub fn new(id: i32, clients: Vec<AppClient>) -> Self {
16+
pub fn new(id: WorkspaceType, clients: Vec<AppClient>) -> Self {
1617
AppWorkspace { id, clients }
1718
}
1819
}
@@ -22,7 +23,7 @@ impl Renamer {
2223
&self,
2324
workspaces: Vec<AppWorkspace>,
2425
config: &ConfigFile,
25-
) -> HashMap<i32, String> {
26+
) -> HashMap<WorkspaceType, String> {
2627
let vars = HashMap::from([("delim".to_string(), config.format.delim.to_string())]);
2728
workspaces
2829
.iter()
@@ -70,7 +71,7 @@ impl Renamer {
7071
let delimiter = formatter("{delim}", &vars);
7172
let joined_string = workspace_output.join(&delimiter);
7273

73-
(workspace.id, joined_string)
74+
(workspace.id.clone(), joined_string)
7475
})
7576
.collect()
7677
}
@@ -231,9 +232,9 @@ mod tests {
231232
is_dedup_inactive_fullscreen: false,
232233
};
233234

234-
let workspace = AppWorkspace::new(1, vec![client]);
235+
let workspace = AppWorkspace::new(WorkspaceType::try_from(1).unwrap(), vec![client]);
235236

236-
assert_eq!(workspace.id, 1);
237+
assert_eq!(workspace.id, WorkspaceType::Regular("1".to_string()));
237238
assert_eq!(workspace.clients.len(), 1);
238239
assert_eq!(workspace.clients[0].class, "Class");
239240
assert_eq!(workspace.clients[0].title, "Title");

0 commit comments

Comments
 (0)