From 7a46bf472e95f716a39d10eaf398bd9e8444d039 Mon Sep 17 00:00:00 2001 From: Irene Knapp Date: Thu, 26 Nov 2026 02:21:13 -0700 Subject: the workspace module strips leading number tags now this is an i3 cosmetic feature that i3bar and polybar both do, so now we do, as well Force-Push: yes Change-Id: Ia9c06e35fb69840e742c831ad104bc11e9f19f99 --- src/module/i3_workspace.rs | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) (limited to 'src/module/i3_workspace.rs') diff --git a/src/module/i3_workspace.rs b/src/module/i3_workspace.rs index d6a3570..d799b71 100644 --- a/src/module/i3_workspace.rs +++ b/src/module/i3_workspace.rs @@ -25,6 +25,21 @@ struct Workspace { is_focused: bool, } +impl Workspace { + fn new(index: u64, name: &str, is_focused: bool) -> Workspace { + let index_prefix = format!("{}: ", index); + + let stripped_name = if name.starts_with(&index_prefix) { + &name[index_prefix.len() ..] + } else { name }; + + Workspace { + name: stripped_name.to_string(), + is_focused, + } + } +} + impl CreatableModule for I3WorkspaceModule { const REQUIRED_FACILITIES: FacilityType = FacilityType::I3; @@ -52,10 +67,9 @@ impl CreatableModule for I3WorkspaceModule { && let Some(Value::Integer(index)) = entry.get("num") && let Some(Value::Boolean(is_focused)) = entry.get("focused") { - workspaces.insert(*index as u64, Workspace { - name: String::clone(name), - is_focused: *is_focused, - }); + let index = *index as u64; + + workspaces.insert(index, Workspace::new(index, name, *is_focused)); } else { return Err(Error::custom( "Unexpected format of initial i3 workspace data.")); @@ -120,8 +134,8 @@ async fn update_loop(receiver: Receiver<(EventType, String)>, if let Ok(Value::Object(change)) = parse_json(json.as_bytes()) && let Some(Value::String(change_type)) = change.get("change") && let Some(Value::Object(current)) = change.get("current") - && let Some(Value::String(current_name)) = current.get("name") - && let Some(Value::Integer(current_index)) = current.get("num") + && let Some(Value::String(name)) = current.get("name") + && let Some(Value::Integer(index)) = current.get("num") { /* We'll want to release the workspace lock before we're done, so * let's have a scope for that. @@ -138,15 +152,13 @@ async fn update_loop(receiver: Receiver<(EventType, String)>, /* For this event, the meaning of "current" is the workspace * being removed. */ - let _ = workspaces.remove(&(*current_index as u64)); + let _ = workspaces.remove(&(*index as u64)); } else if *change_type == "init" { /* All we do is create the workspace here. We'll get a focus * event right after, and that one will fix the focus. */ - workspaces.insert(*current_index as u64, Workspace { - name: String::clone(current_name), - is_focused: true, - }); + workspaces.insert(*index as u64, + Workspace::new(*index as u64, name, false)); } else if *change_type == "focus" { if let Some(Value::Object(old)) = change.get("old") && let Some(Value::Integer(old_index)) = old.get("num") @@ -158,7 +170,7 @@ async fn update_loop(receiver: Receiver<(EventType, String)>, /* Notice that the workspace already exists; we don't need to * create it as part of "focus". */ - if let Some(entry) = workspaces.get_mut(&(*current_index as u64)) { + if let Some(entry) = workspaces.get_mut(&(*index as u64)) { entry.is_focused = true; } } -- cgit 1.4.1