Skip to content

Commit 02626c1

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

File tree

2 files changed

+273
-184
lines changed

2 files changed

+273
-184
lines changed

src/renamer/formatter.rs

Lines changed: 16 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
}
@@ -217,6 +223,7 @@ pub fn to_superscript(number: i32) -> String {
217223
mod tests {
218224
use super::*;
219225
use crate::renamer::IconConfig::*;
226+
use hyprland::shared::WorkspaceType;
220227

221228
#[test]
222229
fn test_app_workspace_new() {
@@ -231,9 +238,11 @@ mod tests {
231238
is_dedup_inactive_fullscreen: false,
232239
};
233240

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

236-
assert_eq!(workspace.id, 1);
244+
assert_eq!(workspace.id, WorkspaceType::Regular("1".to_string()));
245+
assert_eq!(workspace.hyprland_id, 1);
237246
assert_eq!(workspace.clients.len(), 1);
238247
assert_eq!(workspace.clients[0].class, "Class");
239248
assert_eq!(workspace.clients[0].title, "Title");

0 commit comments

Comments
 (0)