about summary refs log tree commit diff
diff options
context:
space:
mode:
authorIrene Knapp <ireneista@irenes.space>2026-11-26 02:21:13 -0700
committerIrene Knapp <ireneista@irenes.space>2026-11-26 02:21:13 -0700
commit7a46bf472e95f716a39d10eaf398bd9e8444d039 (patch)
treeecc304a3c06085e7984e3c771705779b464aca64
parent66e5b1c78382dfa489c447b4e0cd1dc70c152f96 (diff)
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
-rw-r--r--src/main.rs3
-rw-r--r--src/module/i3_workspace.rs36
2 files changed, 24 insertions, 15 deletions
diff --git a/src/main.rs b/src/main.rs
index 786f0e3..b1d0484 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -386,9 +386,6 @@ impl Dock {
              - self.configuration.edge_inset as u32,
     };
 
-    self.draw_text("playful cool fic tech nonfic",
-                   &mut open_parcel, Alignment::Left)?;
-
     {
       let mut facilities = self.facilities.lock().await;
 
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;
               }
             }