From 14405523bc95f44f3dd4bcd22ae8c08dee8bfffa Mon Sep 17 00:00:00 2001 From: mustafa salih Date: Sat, 9 Jan 2021 03:40:14 +0300 Subject: [PATCH] Added cpu temperature and battery --- Cargo.lock | 2 +- Cargo.toml | 2 +- README.md | 6 +- rsblocks.yml | 12 +++ screenshots/1.png | Bin 6843 -> 0 bytes screenshots/2.png | Bin 0 -> 7810 bytes src/lib.rs | 203 ++++++++++++++++++++++++++++++++++++++-------- 7 files changed, 185 insertions(+), 40 deletions(-) delete mode 100644 screenshots/1.png create mode 100644 screenshots/2.png diff --git a/Cargo.lock b/Cargo.lock index 43bd5a6..a6681e8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -380,7 +380,7 @@ checksum = "4e1b7878800220a76a08f32c057829511440f65528b63b940f2f2bc145d7ac68" [[package]] name = "rsblocks" -version = "0.1.4" +version = "0.1.5" dependencies = [ "alsa", "breadx", diff --git a/Cargo.toml b/Cargo.toml index 5ac12cd..ef392be 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rsblocks" -version = "0.1.4" +version = "0.1.5" authors = ["mustafa salih "] edition = "2018" readme = "README.md" diff --git a/README.md b/README.md index 2cffd71..217937d 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ A multi threaded fast status bar for dwm window manager written in **Rust** 🦀

- +


## Features @@ -14,7 +14,9 @@ A multi threaded fast status bar for dwm window manager written in **Rust** 🦀 * Memory Usage * Disk Usage * Weather Temperature -* Sound volume +* Sound Volume +* Battery Percentage +* Cpu Temperature * Easy to configure with `rsblocks.yml` file diff --git a/rsblocks.yml b/rsblocks.yml index d02f12c..6d0786c 100644 --- a/rsblocks.yml +++ b/rsblocks.yml @@ -46,3 +46,15 @@ weather: format: '%l:+%t' delay: 7200.0 # 7200 seconds = 2 hours + +battery: + source: 'BAT0' + icon: '' + enable: false + delay: 120.0 + + +cpu_temperature: + icon: '' + enable: true + delay: 120.0 diff --git a/screenshots/1.png b/screenshots/1.png deleted file mode 100644 index cac7e46f8d569f056b4cd0ebae9358594b184ed5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6843 zcmV;s8bsxZP) zaB^>EX>4U6ba`-PAZ2)IW&i+q+O3vbvgEi8ME|)8FM%Kl0$dKC5#E89??aXPcHf?{ zJrm(ll%%3qB#@a%DC~dz^Mrr!5z8qQHLtDK$fvZ@Qs>6w=hL3E#PXa!pB2+P`fWT& zekUY`?*04Q`sXU0asBy+AA897J|6silKfprz7~Ey`R<&aNPY>D@$?y&@-Ec&=cYEd zUqc=5Li3&Ygz|pNS6H9R{T;py7$_}eqny&tWc{4|6G6UT$(`%xT$mSge(qyyT<#`D+y>DP_(S48Ri178oR z-_v=&=PW;Gf3oYPf@pme^?)rumSN%m^8Ea*au{Fb-kzgzcA|{I`dH=LqM_3z0m4wg)TXN>|r}ahbbkW9IoA{{dAfV^ACqTp(p1wO#+x8QbIk@fEqBN&MbVEHM?+n+7FDfk>Oq_Knro?A zYqfe!u3NTZYSql#nsv`!T)n!vd-L8>%Xpx++N^nNt@ji<8+F#|%nPuv%)27ch`${V>Y+}`A%U4@{OV~KYE?alqwtctV4_Z62x%n{msltnC%v9gW z)%yx0T~AzdSUkobXkfj@BXQ^3C2L-Gx|TuGR(B(RaG82zOvUn8K7g=RY^1a)d*EJb z#G!;LGPtj;+gvqoTYXrodx)pm%dySGMx(mh?$LEL)o_1!$$KiTb~vH!JN2kHwXNs0 zm~=dmnt~#`timL*l}(Z8gzMc#Fo{zMQueMV)6pw^Po@(i`_6FydBlZ}p3zp0)|OHH zYh?l3Rg#~TM(n|R+G9io<+$C*rpfA1ZnTM`Yi|4W`MItHm-+Q0EMi5n=#{~B3O@r2< zCRj|9o$EY>P7;geJxGeiHq*`jqNa|LI+NRqVU8XZelE(jt|6_lM1lO=cSJ#@V~g5X z>jg3HHu2BlB8TpTUCz<=Xre(kLRm!@ngiX9&O0w<83`e4xhI6u>O`jVwhPeO=G6U} zJGbr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_bw^UJ9T^)vPh<+sCRE)IB|4GSj2*#HXX*}37s9BFOAWB@%8Y=h~HH zh56ZU-Q#CZ>^XblEf;U-4DI0XdAhoWFp=2KZp}=)o0Wd|)w;;Bi0Mnd{&ow2Kx}Pk zj5)duasJ|NU7%2Cv*xZ62>9it1!rRR%$T#{!-?duSiGyd_rsJp1zTPRNsIiv^!&W^ z3H}kNR~zc8q=6dhdO>4-wY>GbK|*&|r-F2)y!R92v0PZ>V&tVR4u^g3?$y-)XHoA7 zLH>bJElmws8TS-0fP5o|!VIXA7#O1Svvd~I8QM%kQ>LM5|KC8^@Z*9G4jWa4{?lKc z?&nVJ4Gx>T`iETznWU%0<>zH6&#?r;%S~ZIA%EMZucUQ^LID7PKzOrA4*D4X)z0P} zr^#gMAHV&(>{z6k zv6$6A{2KSyxu^M=A6M^xyaPBg`b$G2xz1U4H}~*?O&>)^Fc{i_A+rZW=e5N@bAP0xf@91EE z2o~<2g9~T(e;SH#IPA9$tp8@zR+p;qZQW0v89o+#l>bkTM5aD(s4jb!FT0QS(?jL^ z{$<#S0g-qd?(+FV!dF{H)xED);bYX|6XT6a^>0Qi*UKMex>5}_)KEhWHI%`B0o8>8 UM=SSs4*&oF07*qoM6N<$g8ghc$N&HU literal 0 HcmV?d00001 diff --git a/src/lib.rs b/src/lib.rs index ed11c9c..60a4c37 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,4 @@ +use alsa::mixer::{Mixer, SelemChannelId, SelemId}; use breadx::{display::*, window::Window}; use chrono::prelude::*; use minreq; @@ -7,7 +8,6 @@ use std::io::Read; use std::sync::mpsc; use std::thread; use std::time::Duration; -use alsa::mixer::{Mixer, SelemChannelId, SelemId}; use yaml_rust::{yaml, YamlLoader}; #[derive(Debug)] @@ -17,6 +17,8 @@ pub enum ThreadsData { Memory(String), Time(String), Weather(String), + Battery(String), + CpuTemp(String), } #[derive(Clone)] @@ -27,6 +29,8 @@ pub struct Config { pub disk: Disk, pub volume: Volume, pub weather: Weather, + pub battery: Battery, + pub cpu_temperature: CpuTemp, } #[derive(Clone)] @@ -54,7 +58,7 @@ pub struct Volume { pub icon: String, pub enabled: bool, pub delay: f64, - pub card: String + pub card: String, } #[derive(Clone)] @@ -66,10 +70,37 @@ pub struct Weather { pub delay: f64, } -/* -// TODO: error handling required if rsblocks.yml file is empty +#[derive(Clone)] +pub struct Battery { + pub source: String, + pub icon: String, + pub enabled: bool, + pub delay: f64, +} -this function is responsible to check if the rsblocks.yml file +#[derive(Clone)] +pub struct CpuTemp { + pub icon: String, + pub enabled: bool, + pub delay: f64, +} + +/* TODOS + + TODO 1: Error handling required if rsblocks.yml file is empty. + + TODO 2: This lib file growing and soon it will be annoying to move + arround, need fix soon. + + TODO 3: Need a better comments in code, or no one will understand what happens. + + TODO 4: Need a documentation. + + TODO 5: Fix repeated code for threads in `run` function. + +*/ + +/*this function is responsible to check if the rsblocks.yml file exists to call parse_config to read it OTHERWISE it will call load_defaults to load a hardcoded default configuration @@ -116,7 +147,7 @@ fn load_defaults() -> Config { icon: String::from(""), enabled: false, delay: 0.17, - card: String::from("ALSA") + card: String::from("ALSA"), }, weather: Weather { city: String::from(""), @@ -125,6 +156,17 @@ fn load_defaults() -> Config { enabled: false, delay: 7200.0, //7200 seconds = 2 hours }, + battery: Battery { + source: String::from("BAT0"), + icon: String::from(""), + enabled: false, + delay: 120.0, + }, + cpu_temperature: CpuTemp { + icon: String::from(""), + enabled: false, + delay: 120.0, + }, } } @@ -141,6 +183,8 @@ fn parse_config(doc: &yaml::Yaml) -> Config { let disk_icon = get_or_set_string(doc, "disk", "icon", ""); let volume_icon = get_or_set_string(doc, "volume", "icon", ""); let weather_icon = get_or_set_string(doc, "weather", "icon", ""); + let battery_icon = get_or_set_string(doc, "battery", "icon", ""); + let cpu_temperature_icon = get_or_set_string(doc, "cpu_temperature", "icon", ""); //parsing formats and city weather let time_format = get_or_set_string(doc, "time", "format", "%T"); @@ -152,17 +196,24 @@ fn parse_config(doc: &yaml::Yaml) -> Config { let memory_enabled = get_or_set_bool(doc, "memory", "enable"); let volume_enabled = get_or_set_bool(doc, "volume", "enable"); let weather_enabled = get_or_set_bool(doc, "weather", "enable"); + let battery_enabled = get_or_set_bool(doc, "battery", "enable"); + let cpu_temperature_enabled = get_or_set_bool(doc, "cpu_temperature", "enable"); // parsing update_delay state (should be all seconds in f64 type) - let time_delay = get_or_set_f32(doc, "time", "delay", 1.0); - let disk_delay = get_or_set_f32(doc, "disk", "delay", 120.0); - let memory_delay = get_or_set_f32(doc, "memory", "delay", 2.0); - let volume_delay = get_or_set_f32(doc, "volume", "delay", 0.17); - let weather_delay = get_or_set_f32(doc, "weather", "delay", 7200.0); - + let time_delay = get_or_set_f64(doc, "time", "delay", 1.0); + let disk_delay = get_or_set_f64(doc, "disk", "delay", 120.0); + let memory_delay = get_or_set_f64(doc, "memory", "delay", 2.0); + let volume_delay = get_or_set_f64(doc, "volume", "delay", 0.17); + let weather_delay = get_or_set_f64(doc, "weather", "delay", 7200.0); + let battery_delay = get_or_set_f64(doc, "battery", "delay", 120.0); + let cpu_temperature_delay = get_or_set_f64(doc, "cpu_temperature", "delay", 120.0); + // parsing card for volume, ALSA or PULSE let volume_card = get_or_set_string(doc, "volume", "card", "ALSA"); + // parsing battery source name + let battery_source = get_or_set_string(doc, "battery", "source", "BAT0"); + Config { seperator, time: Time { @@ -184,7 +235,7 @@ fn parse_config(doc: &yaml::Yaml) -> Config { icon: volume_icon, enabled: volume_enabled, delay: volume_delay, - card: volume_card + card: volume_card, }, weather: Weather { city: weather_city, @@ -193,11 +244,22 @@ fn parse_config(doc: &yaml::Yaml) -> Config { enabled: weather_enabled, delay: weather_delay, }, + battery: Battery { + source: battery_source, + icon: battery_icon, + enabled: battery_enabled, + delay: battery_delay, + }, + cpu_temperature: CpuTemp { + icon: cpu_temperature_icon, + enabled: cpu_temperature_enabled, + delay: cpu_temperature_delay, + }, } } // getting a f32 value from rsblocks.yml file or set default (last argument) -fn get_or_set_f32(doc: &yaml::Yaml, parent: &str, child: &str, default: f64) -> f64 { +fn get_or_set_f64(doc: &yaml::Yaml, parent: &str, child: &str, default: f64) -> f64 { let val: f64 = if doc[parent][child].is_badvalue() { default } else { @@ -233,9 +295,7 @@ fn get_or_set_string(doc: &yaml::Yaml, parent: &str, child: &str, default_val: & */ -/* Running the program: -TODO: this is sucks, repeated code in threads below, fix me you fucking asshole - */ +// Running the program: pub struct Blocks { disp: Display, @@ -246,10 +306,7 @@ impl Blocks { pub fn new() -> Self { let disp = Display::create(None, None).expect("Failed to create x11 connection"); let root = disp.default_screen().root; - Self { - disp, - root, - } + Self { disp, root } } } @@ -259,15 +316,11 @@ pub fn run(config: Config, mut blocks: Blocks) { if config.volume.enabled { let volume_tx = tx.clone(); let configcp = config.clone(); - thread::spawn(move || { - let mut vol_data = - ThreadsData::Sound(get_volume(&configcp)); - loop { - let _ = volume_tx.send(vol_data); - vol_data = - ThreadsData::Sound(get_volume(&configcp)); - thread::sleep(Duration::from_secs_f64(configcp.volume.delay)) - } + let mut vol_data = ThreadsData::Sound(get_volume(&configcp)); + thread::spawn(move || loop { + volume_tx.send(vol_data).unwrap(); + vol_data = ThreadsData::Sound(get_volume(&configcp)); + thread::sleep(Duration::from_secs_f64(configcp.volume.delay)) }); } @@ -309,6 +362,32 @@ pub fn run(config: Config, mut blocks: Blocks) { }); } + // Battery thread + if config.battery.enabled { + let battery_tx = tx.clone(); + let configcp = config.clone(); + let battery_data = get_battery(&configcp).unwrap(); + let mut battery_data = ThreadsData::Battery(battery_data); + thread::spawn(move || loop { + battery_tx.send(battery_data).unwrap(); + battery_data = ThreadsData::Battery(get_battery(&configcp).unwrap()); + thread::sleep(Duration::from_secs_f64(configcp.battery.delay)) + }); + } + + // Cpu temperature thread + if config.cpu_temperature.enabled { + let cpu_temp_tx = tx.clone(); + let configcp = config.clone(); + let cpu_temp_data = get_cpu_temp(&configcp).unwrap(); + let mut cpu_temp_data = ThreadsData::CpuTemp(cpu_temp_data); + thread::spawn(move || loop { + cpu_temp_tx.send(cpu_temp_data).unwrap(); + cpu_temp_data = ThreadsData::CpuTemp(get_cpu_temp(&configcp).unwrap()); + thread::sleep(Duration::from_secs_f64(configcp.cpu_temperature.delay)) + }); + } + // Time thread { let time_tx = tx; @@ -324,7 +403,7 @@ pub fn run(config: Config, mut blocks: Blocks) { //Main { // NOTE: order matters to the final format - let mut bar: Vec = vec!["".to_string(); 5]; + let mut bar: Vec = vec!["".to_string(); 7]; //iterating the values recieved from the threads for data in rx { match data { @@ -332,7 +411,9 @@ pub fn run(config: Config, mut blocks: Blocks) { ThreadsData::Weather(x) => bar[1] = x, ThreadsData::Disk(x) => bar[2] = x, ThreadsData::Memory(x) => bar[3] = x, - ThreadsData::Time(x) => bar[4] = x, + ThreadsData::CpuTemp(x) => bar[4] = x, + ThreadsData::Battery(x) => bar[5] = x, + ThreadsData::Time(x) => bar[6] = x, } // match ends here @@ -399,6 +480,7 @@ fn get_weather(config: &Config) -> String { format!(" {} {} {}", config.weather.icon, res, config.seperator) } +// getting disk usage pub fn get_disk(config: &Config) -> String { const GB: u64 = (1024 * 1024) * 1024; let statvfs = nix::sys::statvfs::statvfs("/").unwrap(); @@ -408,7 +490,7 @@ pub fn get_disk(config: &Config) -> String { let available = (statvfs.blocks_free() * statvfs.fragment_size()) / GB; let used = total - available; - disk_used.push_str(&format!("{}GB", used)); + disk_used.push_str(&format!("{}G", used)); format!( " {} {} {}", config.disk.icon, disk_used, config.seperator @@ -426,15 +508,15 @@ pub fn get_volume(config: &Config) -> String { let selem_id = SelemId::new("Master", 0); let selem = mixer.find_selem(&selem_id).expect("Couldn't find selem"); let selem_chan_id = SelemChannelId::FrontLeft; - + let (min, max) = selem.get_playback_volume_range(); let mut raw_volume = selem .get_playback_volume(selem_chan_id) .expect("Failed to get raw_volume"); - + let range = max - min; let vol = if range == 0 { - 0 + 0 } else { raw_volume -= min; ((raw_volume as f64 / range as f64) * 100.) as u64 @@ -524,3 +606,52 @@ fn assign_val(line: &str, assignable: &mut u32) { .unwrap(); *assignable = parsed; } + +// getting battery percentage +pub fn get_battery(config: &Config) -> Result { + let battery_full_cap_file = format!( + "/sys/class/power_supply/{}/charge_full_design", + config.battery.source + ); + let battery_charge_now_file = format!( + "/sys/class/power_supply/{}/charge_now", + config.battery.source + ); + + let mut buf = String::new(); + + // FIXME: ugly error handling AGAIN fixing later, im lazy + match File::open(&battery_full_cap_file) { + Ok(mut file) => file.read_to_string(&mut buf)?, + Err(_) => return Ok(String::from("check your battery source name")), + }; + let full_design = buf.trim().parse::().unwrap(); + buf.clear(); + + // NOTE: no need to error check if passed the above match + File::open(&battery_charge_now_file)?.read_to_string(&mut buf)?; + + let charge_now = buf.trim().parse::().unwrap(); + + let battery_percentage = (charge_now as f32 / full_design as f32) * 100.0; + let result = format!( + " {} {:.0}% {}", + config.battery.icon, battery_percentage, config.seperator + ); + Ok(result) +} + +// getting cpu temperature +pub fn get_cpu_temp(config: &Config) -> Result { + let mut buf = String::new(); + File::open("/sys/class/thermal/thermal_zone0/temp")?.read_to_string(&mut buf)?; + let value = buf.trim().parse::().unwrap(); + + let result = format!( + " {} {}° {}", + config.cpu_temperature.icon, + value / 1000.0, + config.seperator + ); + Ok(result) +}