Thomas Dy 7 жил өмнө
parent
commit
0fd7961fd6
8 өөрчлөгдсөн 0 нэмэгдсэн , 382 устгасан
  1. 0 85
      src/bar.rs
  2. 0 75
      src/bspwm.rs
  3. 0 18
      src/comm.rs
  4. 0 48
      src/main.rs
  5. 0 35
      src/music.rs
  6. 0 23
      src/store.rs
  7. 0 29
      src/tray.rs
  8. 0 69
      src/wm.rs

+ 0 - 85
src/bar.rs

@@ -1,85 +0,0 @@
-use config::Config;
-use std::io::prelude::*;
-use std::io::BufReader;
-use std::process::{ChildStdin, ChildStdout, Command, Stdio};
-use std::thread;
-
-pub struct Bar {
-    stdin: ChildStdin
-}
-
-impl Bar {
-    pub fn new(top: bool, cfg: &Config) -> Bar {
-        let val = cfg.lookup("bar.fonts").unwrap();
-        let fonts = val.as_slice().unwrap();
-        let fonts = fonts.iter().flat_map(|elem| elem.as_str());
-
-        let mut bar = Command::new("lemonbar");
-        bar.stdin(Stdio::piped());
-        bar.stdout(Stdio::piped());
-
-        bar.arg("-n");
-        if top {
-            bar.arg("__panel_top");
-        }
-        else {
-            bar.arg("__panel_bot");
-        }
-
-        bar.arg("-B");
-        bar.arg("#FF000000");
-
-        if !top {
-            bar.arg("-b");
-        }
-
-        for font in fonts {
-            bar.arg("-f");
-            bar.arg(font);
-        }
-
-        let child = bar.spawn()
-            .ok()
-            .expect("Failed to start lemonbar");
-
-        let stdout = child.stdout.unwrap();
-        Bar::read_loop(stdout);
-
-        Bar { stdin: child.stdin.unwrap() }
-    }
-
-    fn read_loop(stdout: ChildStdout) {
-        thread::spawn(move || {
-            let mut s = String::new();
-            let mut reader = BufReader::new(stdout);
-            loop {
-                s.clear();
-                reader.read_line(&mut s).ok().expect("Failed to read from lemonbar");
-
-                let mut chars = s.trim().chars();
-                let kind = chars.next().unwrap();
-                let name = chars.collect::<String>();
-
-                match kind {
-                    'w' => Command::new("bspc")
-                        .arg("desktop")
-                        .arg("-f")
-                        .arg(&name)
-                        .output()
-                        .ok(),
-
-                    'm' => Command::new("mpc")
-                        .arg("toggle")
-                        .output()
-                        .ok(),
-
-                    _ => None
-                };
-            }
-        });
-    }
-
-    pub fn send(&mut self, text: &str) {
-        writeln!(&mut self.stdin, "{}", text).ok();
-    }
-}

+ 0 - 75
src/bspwm.rs

@@ -1,75 +0,0 @@
-use comm;
-use comm::Channel;
-use config::Config;
-use std::io::prelude::*;
-use std::io::BufReader;
-use std::process::{Command, Stdio};
-
-pub fn bspwm(tx: &Channel, _cfg: &Config) {
-    let bspc = Command::new("bspc")
-        .arg("subscribe")
-        .arg("report")
-        .stdout(Stdio::piped())
-        .spawn()
-        .ok()
-        .expect("Failed to start bspc subscribe");
-
-    let stdout = bspc.stdout.unwrap();
-    let mut reader = BufReader::new(stdout);
-
-    let mut line = String::new();
-    loop {
-        line.clear();
-        reader.read_line(&mut line).ok().expect("Failed to read line");
-        let kind = line.remove(0);
-        let line = line.trim();
-
-        match kind {
-            'W' => comm::send(tx, "desktops", &parse_bspwm(line)),
-            _ => ()
-        }
-    }
-}
-
-fn parse_bspwm(line: &str) -> String {
-    let mut out = String::new();
-    let mut monitor_count = 0;
-    let mut monitor_selected = false;
-
-    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' {
-            out = format!("{}%{{S{num}}}", out, num = monitor_count);
-            monitor_count += 1;
-            monitor_selected = kind.is_uppercase();
-        }
-        else if kind == 'L' {
-        }
-        else if kind == 'G' {
-        }
-        else if kind == 'T' {
-        }
-        else {
-            let desktop = format!("%{{A:w{name}:}} {name} %{{A}}", name = name);
-            if kind.is_uppercase() {
-                if monitor_selected {
-                    out = format!("{}%{{B#66CC66}}{}%{{B-}}", out, desktop);
-                }
-                else {
-                    out = format!("{}%{{B#666666}}{}%{{B-}}", out, desktop);
-                }
-            }
-            else if kind == 'U' || kind == 'u' {
-                out = format!("{}%{{B#CC0033}}{}%{{B-}}", out, desktop);
-            }
-            else if kind == 'O' || kind == 'o' {
-                out = format!("{}{}", out, desktop);
-            }
-        }
-    }
-    out
-}

+ 0 - 18
src/comm.rs

@@ -1,18 +0,0 @@
-use std::sync::mpsc::{Sender};
-
-pub type Channel = Sender<Message>;
-
-#[derive(Debug)]
-pub struct Message {
-    pub kind: String,
-    pub text: String
-}
-
-pub fn send(tx: &Channel, kind: &str, text: &str) {
-    tx.send(Message {
-        kind: kind.to_string(),
-        text: text.to_string()
-    })
-    .ok()
-    .expect(&format!("Failed to send message: [{}] {}", kind, text))
-}

+ 0 - 48
src/main.rs

@@ -6,62 +6,14 @@ extern crate freetype;
 extern crate fontconfig_sys;
 
 mod sensors;
-//mod comm;
 mod config;
-//mod bspwm;
-//mod bar;
-//mod tray;
-//mod store;
-//mod music;
-//mod wm;
-//mod x11;
 mod ui;
 
-//use comm::{Channel, Message};
-//use config::Config;
 use std::env;
-//use std::sync::Arc;
-//use std::sync::mpsc;
 use std::process;
-//use std::thread;
 
 fn main() {
     let config_path = env::args().nth(1).unwrap_or("./panel.toml".to_string());
     let cfg = config::load(&config_path);
-//
-//    let mut topbar = bar::Bar::new(true, &cfg);
-//    let _tray = tray::Tray::new();
-//
-//    let cfg = Arc::new(cfg);
-//    let (tx, rx) = mpsc::channel::<Message>();
-//    make_thread(&tx, &cfg, bspwm::bspwm);
-//    make_thread(&tx, &cfg, sensors::sensors);
-//    make_thread(&tx, &cfg, music::music);
-//    make_thread(&tx, &cfg, wm::wm);
-//
-//    let mut data = store::Store::new();
-//
-//    loop {
-//        let msg = rx.recv().unwrap();
-//        data.save(msg);
-//
-//        topbar.send(&format!("{}| {}%{{r}}{}{}",
-//            data.get("desktops"),
-//            data.get("title"),
-//            data.get("sensors"),
-//            data.get("spacer")
-//        ));
-//    }
-
     process::exit(ui::ui_main(&cfg));
 }
-
-//fn make_thread(tx: &Channel, cfg: &Arc<Config>, func: fn(&Channel, &Config) -> ()) {
-//    let thread_tx = tx.clone();
-//    let thread_cfg = cfg.clone();
-//    thread::spawn(move || {
-//        func(&thread_tx, &thread_cfg);
-//    });
-//}
-
-

+ 0 - 35
src/music.rs

@@ -1,35 +0,0 @@
-extern crate mpd;
-
-use comm;
-use comm::Channel;
-use config::Config;
-use self::mpd::client::Client;
-use self::mpd::song::Song;
-use self::mpd::idle;
-use self::mpd::idle::Idle;
-use self::mpd::status::State;
-
-pub fn music(tx: &Channel, _cfg: &Config) {
-    let mut conn = Client::connect("127.0.0.1:6600").unwrap();
-    loop {
-        let state = match conn.status().unwrap().state {
-            State::Play => "",
-            State::Pause => "",
-            State::Stop => ""
-        };
-
-        let song = conn.currentsong().unwrap();
-        let stopped = "Stopped".to_string();
-        let display = song.as_ref().map(get_display).unwrap_or(stopped);
-        comm::send(tx, "mpd", &format!("%{{A:mpd:}}{} {}%{{A}}", state, display));
-        conn.wait(&[idle::Subsystem::Player]).ok();
-    }
-}
-
-fn get_display(song: &Song) -> String {
-    let unknown = "Unknown".to_string();
-    let artist = song.tags.get("Artist").unwrap_or(&unknown);
-    let title = song.title.as_ref().unwrap_or(&unknown);
-
-    format!("{} - {}", artist, title)
-}

+ 0 - 23
src/store.rs

@@ -1,23 +0,0 @@
-use comm::Message;
-use std::collections::HashMap;
-
-pub struct Store {
-    data: HashMap<String, String>
-}
-
-impl Store {
-    pub fn new() -> Store {
-        Store { data: HashMap::new() }
-    }
-
-    pub fn save(&mut self, msg: Message) {
-        self.data.insert(msg.kind, msg.text);
-    }
-
-    pub fn get(&self, kind: &str) -> &str {
-        match self.data.get(kind) {
-            Some(res) => res,
-            None => ""
-        }
-    }
-}

+ 0 - 29
src/tray.rs

@@ -1,29 +0,0 @@
-use std::process::{Child, Command};
-
-pub struct Tray {
-    child: Child
-}
-
-impl Tray {
-    pub fn new() -> Tray {
-        let child = Command::new("stalonetray")
-            .arg("-c").arg("/dev/null")
-            .arg("--geometry").arg("1x1-0+0")
-            .arg("-bg").arg("black")
-            .arg("--grow-gravity").arg("SE")
-            .arg("--icon-size").arg("20")
-            .arg("--kludges").arg("force_icons_size")
-            .spawn()
-            .unwrap_or_else(|e| { panic!("Could not start stalonetray: {}", e) });
-
-        Tray {
-            child: child
-        }
-    }
-}
-
-impl Drop for Tray {
-    fn drop(&mut self) {
-        self.child.kill().ok();
-    }
-}

+ 0 - 69
src/wm.rs

@@ -1,69 +0,0 @@
-use xcb;
-use x11;
-use comm;
-use comm::Channel;
-use config::Config;
-use std::thread;
-use std::time::Duration;
-
-pub fn wait_for<F>(f: F) -> xcb::Window where F: Fn() -> xcb::Window {
-    loop {
-        let w = f();
-        if w == 0 {
-            thread::sleep(Duration::from_millis(100));
-        }
-        else {
-            return w;
-        }
-    }
-}
-
-pub fn wm(tx: &Channel, _config: &Config) {
-    if let Some(conn) = x11::Connection::new() {
-        let screen = conn.default_screen();
-        let mut last_win = screen.get_active_window();
-        comm::send(tx, "title", conn.get_window_name(last_win).as_ref());
-
-        let stalonetray = wait_for(|| screen.search_by_class("stalonetray"));
-        let panel = wait_for(|| screen.search_by_name("__panel_top"));
-        let width = xcb::get_geometry(&conn, stalonetray).get_reply().unwrap().width();
-
-        xcb::configure_window(&conn, stalonetray, &[
-            (xcb::CONFIG_WINDOW_X as u16, (screen.width - width) as u32),
-            (xcb::CONFIG_WINDOW_SIBLING as u16, panel),
-            (xcb::CONFIG_WINDOW_STACK_MODE as u16, xcb::STACK_MODE_ABOVE)
-        ]);
-        xcb::change_window_attributes(&conn, stalonetray, &[(xcb::CW_EVENT_MASK, xcb::EVENT_MASK_STRUCTURE_NOTIFY)]);
-        conn.watch(screen.root, true);
-        conn.watch(last_win, true);
-        conn.flush();
-
-        conn.event_loop(&mut |event: &xcb::GenericEvent| {
-            match event.response_type() {
-                xcb::PROPERTY_NOTIFY => {
-                    let prop_event: &xcb::PropertyNotifyEvent = xcb::cast_event(event);
-                    if prop_event.atom() == conn.atom(x11::_NET_ACTIVE_WINDOW) {
-                        let new_win = screen.get_active_window();
-                        conn.watch(last_win, false);
-                        conn.watch(new_win, true);
-                        conn.flush();
-                        last_win = new_win;
-                        comm::send(tx, "title", conn.get_window_name(last_win).as_ref());
-                    }
-                    else if prop_event.atom() == conn.atom(x11::_NET_WM_NAME) {
-                        comm::send(tx, "title", conn.get_window_name(last_win).as_ref());
-                    }
-                },
-                xcb::CONFIGURE_NOTIFY => {
-                    let event: &xcb::ConfigureNotifyEvent = unsafe { xcb::cast_event(&event) };
-                    let spacer = format!("%{{O{}}}", event.width()+5);
-                    comm::send(tx, "spacer", spacer.as_ref());
-                },
-                _ => ()
-            }
-        });
-    } else {
-        println!("Could not connect to X!");
-    }
-}
-