Skip to content

Commit 2e8fe1b

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

File tree

3 files changed

+395
-209
lines changed

3 files changed

+395
-209
lines changed

src/config/mod.rs

Lines changed: 5 additions & 9 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())?;
@@ -482,13 +484,7 @@ fn generate_workspaces_name_config(
482484
) -> Vec<(String, String)> {
483485
workspaces_name
484486
.iter()
485-
.filter_map(|(id, name)| {
486-
if id.parse::<i32>().is_ok() {
487-
Some((id.to_string(), name.to_string()))
488-
} else {
489-
None
490-
}
491-
})
487+
.map(|(id, name)| (id.to_string(), name.to_string()))
492488
.collect()
493489
}
494490

src/renamer/formatter.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,24 @@ use crate::renamer::ConfigFile;
22
use crate::renamer::IconStatus::*;
33
use crate::{AppClient, Renamer};
44
use hyprland::data::FullscreenMode;
5+
use hyprland::shared::{WorkspaceId, 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,
12+
pub hyprland_id: WorkspaceId,
1113
pub clients: Vec<AppClient>,
1214
}
1315

1416
impl AppWorkspace {
15-
pub fn new(id: i32, clients: Vec<AppClient>) -> Self {
16-
AppWorkspace { id, clients }
17+
pub fn new(id: WorkspaceType, hyprland_id: WorkspaceId, clients: Vec<AppClient>) -> Self {
18+
AppWorkspace {
19+
id,
20+
hyprland_id,
21+
clients,
22+
}
1723
}
1824
}
1925

@@ -22,7 +28,7 @@ impl Renamer {
2228
&self,
2329
workspaces: Vec<AppWorkspace>,
2430
config: &ConfigFile,
25-
) -> HashMap<i32, String> {
31+
) -> HashMap<WorkspaceType, String> {
2632
let vars = HashMap::from([("delim".to_string(), config.format.delim.to_string())]);
2733
workspaces
2834
.iter()
@@ -70,7 +76,7 @@ impl Renamer {
7076
let delimiter = formatter("{delim}", &vars);
7177
let joined_string = workspace_output.join(&delimiter);
7278

73-
(workspace.id, joined_string)
79+
(workspace.id.clone(), joined_string)
7480
})
7581
.collect()
7682
}
@@ -231,9 +237,10 @@ mod tests {
231237
is_dedup_inactive_fullscreen: false,
232238
};
233239

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

236-
assert_eq!(workspace.id, 1);
242+
assert_eq!(workspace.id, WorkspaceType::try_from(1).unwrap());
243+
assert_eq!(workspace.hyprland_id, 1);
237244
assert_eq!(workspace.clients.len(), 1);
238245
assert_eq!(workspace.clients[0].class, "Class");
239246
assert_eq!(workspace.clients[0].title, "Title");

0 commit comments

Comments
 (0)