aboutsummaryrefslogtreecommitdiff
path: root/src/blockmanager.rs
diff options
context:
space:
mode:
authorShoelace <pierre.leidbring@gmail.com>2021-05-19 21:44:58 +0200
committerGitHub <noreply@github.com>2021-05-19 22:44:58 +0300
commit2a23bd20440b0d1a359c6bb4385b6771f2657a3b (patch)
treeec4052da5dff822c70ab20216298fe5be4abfeb7 /src/blockmanager.rs
parentb1d81bf8c936509b6f83b2eac98da8ae72e0a4e3 (diff)
Threaded to async (#58)
* Add async deps * Rename blocks to 'BlockManager' * Refactor "Blocks" to own module * Make all util fn async * Remove stray println
Diffstat (limited to 'src/blockmanager.rs')
-rw-r--r--src/blockmanager.rs54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/blockmanager.rs b/src/blockmanager.rs
new file mode 100644
index 0000000..b0b3b5e
--- /dev/null
+++ b/src/blockmanager.rs
@@ -0,0 +1,54 @@
+use breadx::{display::*, window::Window};
+use crate::types::ThreadsData;
+
+pub struct BlockManager {
+ pub disp: Display<name::NameConnection>,
+ blocks: Vec<String>,
+ pub root: Window,
+}
+
+impl BlockManager {
+ pub fn new() -> Self {
+ let disp = Display::create(None, None).expect("Failed to create x11 connection");
+ let root = disp.default_screen().root;
+ Self {
+ disp,
+ blocks: vec![String::from(""); 14],
+ root,
+ }
+ }
+
+ pub fn update(&mut self, data: ThreadsData) {
+ match data {
+ ThreadsData::Spotify(x) => self.blocks[0] = x,
+ ThreadsData::Mpd(x) => self.blocks[1] = x,
+ ThreadsData::Sound(x) => self.blocks[2] = x,
+ ThreadsData::Weather(x) => self.blocks[3] = x,
+ ThreadsData::NetSpeed(x) => self.blocks[4] = x,
+ ThreadsData::BitCoins(x) => self.blocks[5] = x,
+ ThreadsData::PubIp(x) => self.blocks[6] = x,
+ ThreadsData::Disk(x) => self.blocks[7] = x,
+ ThreadsData::Memory(x) => self.blocks[8] = x,
+ ThreadsData::CpuTemp(x) => self.blocks[9] = x,
+ ThreadsData::LoadAvg(x) => self.blocks[10] = x,
+ ThreadsData::Battery(x) => self.blocks[11] = x,
+ ThreadsData::Uptime(x) => self.blocks[12] = x,
+ ThreadsData::Time(x) => self.blocks[13] = x,
+ }
+ let mut x = String::new();
+ for i in self.blocks.iter() {
+ x.push_str(i.as_str());
+ }
+
+ self.root
+ .set_title(&mut self.disp, &x)
+ .expect("Failed to set title");
+
+ }
+}
+
+impl Default for BlockManager {
+ fn default() -> Self {
+ Self::new()
+ }
+}