Эх сурвалжийг харах

Add support for bspwm desktops

Thomas Dy 9 жил өмнө
parent
commit
d7b4a5f4ba
2 өөрчлөгдсөн 26 нэмэгдсэн , 1 устгасан
  1. 24 0
      src/external.rs
  2. 2 1
      src/main.rs

+ 24 - 0
src/external.rs

@@ -14,8 +14,32 @@ pub fn external(tx: &Channel, _cfg: &Config) {
         match kind {
             'T' => comm::send(tx, "title", line),
             'M' => comm::send(tx, "cmus", line),
+            'W' => comm::send(tx, "desktops", &parse_bspwm(line)),
             _ => ()
         }
     }
 }
 
+fn parse_bspwm(line: &str) -> String {
+    let mut out = String::new();
+
+    let elems = line.split(':');
+    for elem in elems {
+        let mut chars = elem.chars();
+        let kind = chars.next().unwrap();
+        let name = chars.collect::<String>();
+
+        if kind != 'M' && kind != 'm' && kind != 'L' {
+            if kind.is_uppercase() {
+                out = format!("{}%{{Bgray}} {} %{{B-}}", out, name);
+            }
+            else if kind == 'U' || kind == 'u' {
+                out = format!("{}%{{Bred}} {} %{{B-}}", out, name);
+            }
+            else if kind == 'O' || kind == 'o' {
+                out = format!("{} {} ", out, name);
+            }
+        }
+    }
+    out
+}

+ 2 - 1
src/main.rs

@@ -30,7 +30,8 @@ fn main() {
         let msg = rx.recv().unwrap();
         data.save(msg);
 
-        topbar.send(&format!("{}%{{r}}{} | {}",
+        topbar.send(&format!("{}| {}%{{r}}{} | {}",
+            data.get("desktops"),
             data.get("title"),
             data.get("netspeed"),
             data.get("sensors")