aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/blockmanager.rs11
-rw-r--r--src/config/brightness.rs21
-rw-r--r--src/config/mod.rs6
-rw-r--r--src/run.rs10
-rw-r--r--src/types.rs10
-rw-r--r--src/utils/brightness.rs28
-rw-r--r--src/utils/mod.rs1
7 files changed, 82 insertions, 5 deletions
diff --git a/src/blockmanager.rs b/src/blockmanager.rs
index aa92b64..9a256b1 100644
--- a/src/blockmanager.rs
+++ b/src/blockmanager.rs
@@ -13,11 +13,11 @@ impl BlockManager {
let root = disp.default_screen().root;
Self {
disp,
- blocks: vec![String::from(""); 15],
+ blocks: vec![String::from(""); 16],
root,
}
}
-
+ // TODO let the user control the indexes of the blocks
pub fn update(&mut self, data: ThreadsData) {
match data {
ThreadsData::Spotify(x) => self.blocks[0] = x,
@@ -32,9 +32,10 @@ impl BlockManager {
ThreadsData::Memory(x) => self.blocks[9] = x,
ThreadsData::CpuTemp(x) => self.blocks[10] = x,
ThreadsData::LoadAvg(x) => self.blocks[11] = x,
- ThreadsData::Battery(x) => self.blocks[12] = x,
- ThreadsData::Uptime(x) => self.blocks[13] = x,
- ThreadsData::Time(x) => self.blocks[14] = x,
+ ThreadsData::Brightness(x) => self.blocks[12] = x,
+ ThreadsData::Battery(x) => self.blocks[13] = x,
+ ThreadsData::Uptime(x) => self.blocks[14] = x,
+ ThreadsData::Time(x) => self.blocks[15] = x,
}
let mut x = String::new();
for i in self.blocks.iter() {
diff --git a/src/config/brightness.rs b/src/config/brightness.rs
new file mode 100644
index 0000000..b0b3696
--- /dev/null
+++ b/src/config/brightness.rs
@@ -0,0 +1,21 @@
+use serde::{Deserialize, Serialize};
+use std::default::Default;
+
+#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
+pub struct Brightness {
+ pub icon: String,
+ pub enabled: bool,
+ pub delay: f64,
+ pub path: String,
+}
+
+impl Default for Brightness {
+ fn default() -> Self {
+ Brightness {
+ icon: String::from(""),
+ enabled: false,
+ delay: 120.0,
+ path: String::from("/sys/class/backlight/intel_backlight"),
+ }
+ }
+}
diff --git a/src/config/mod.rs b/src/config/mod.rs
index 48809a6..83f0491 100644
--- a/src/config/mod.rs
+++ b/src/config/mod.rs
@@ -1,5 +1,6 @@
mod battery;
mod bitcoins;
+mod brightness;
mod cputemp;
mod disk;
mod loadavg;
@@ -17,6 +18,7 @@ mod weather;
use self::battery::Battery;
use self::mpd::Mpd;
use bitcoins::BitCoins;
+use brightness::Brightness;
use cputemp::CpuTemp;
use disk::Disk;
use loadavg::LoadAvg;
@@ -83,6 +85,9 @@ pub struct Config {
pub battery: Battery,
#[serde(default)]
+ pub brightness: Brightness,
+
+ #[serde(default)]
pub cpu_temperature: CpuTemp,
#[serde(default)]
@@ -120,6 +125,7 @@ impl Default for Config {
volume: Default::default(),
weather: Default::default(),
battery: Default::default(),
+ brightness: Default::default(),
cpu_temperature: Default::default(),
uptime: Default::default(),
mpd: Default::default(),
diff --git a/src/run.rs b/src/run.rs
index 2ec6889..02a6b25 100644
--- a/src/run.rs
+++ b/src/run.rs
@@ -95,6 +95,16 @@ pub async fn run(mut blocks: BlockManager) {
task::spawn(b);
}
+ // brightness task
+ if CONFIG.brightness.enabled {
+ let b = init_block(
+ tx.clone(),
+ brightness::get_brightness,
+ CONFIG.brightness.delay,
+ );
+ task::spawn(b);
+ }
+
// BTC task
if CONFIG.bitcoins.enabled {
let b = init_block(tx.clone(), bitcoins::get_price, CONFIG.bitcoins.delay);
diff --git a/src/types.rs b/src/types.rs
index 3cadf01..a26ffc2 100644
--- a/src/types.rs
+++ b/src/types.rs
@@ -15,6 +15,7 @@ pub enum ThreadsData {
PubIp(String),
LocalIp(String),
BitCoins(String),
+ Brightness(String),
}
#[derive(Clone)]
@@ -34,6 +35,7 @@ pub struct Config {
pub pub_ip: PubIp,
pub local_ip: LocalIp,
pub bitcoins: BitCoins,
+ pub brightness: Brightness,
}
#[derive(Clone)]
@@ -146,3 +148,11 @@ pub struct BitCoins {
pub enabled: bool,
pub delay: f64,
}
+
+#[derive(Clone)]
+pub struct Brightness {
+ pub icon: String,
+ pub enabled: bool,
+ pub delay: f64,
+ pub path: String,
+}
diff --git a/src/utils/brightness.rs b/src/utils/brightness.rs
new file mode 100644
index 0000000..b340907
--- /dev/null
+++ b/src/utils/brightness.rs
@@ -0,0 +1,28 @@
+use crate::config::CONFIG;
+use crate::types::ThreadsData;
+use std::fs::read_to_string;
+use std::path::Path;
+
+// getting brightness
+pub async fn get_brightness() -> ThreadsData {
+ let brightness_path = Path::new(&CONFIG.brightness.path);
+ if !brightness_path.exists() {
+ return ThreadsData::Brightness(String::from("brightness path not found"));
+ };
+ let current_brightness = match read_to_string(Path::new(brightness_path).join("brightness")) {
+ Ok(brightness) => brightness.trim().to_owned().parse::<f32>().unwrap(),
+ _ => return ThreadsData::Brightness(String::from("error reading current brightness")),
+ };
+ let max_brightness = match read_to_string(Path::new(brightness_path).join("max_brightness")) {
+ Ok(brightness) => brightness.trim().to_owned().parse::<f32>().unwrap(),
+ _ => return ThreadsData::Brightness(String::from("error reading max brightness")),
+ };
+
+ let value = (current_brightness / max_brightness) * 100.0;
+
+ let result = format!(
+ " {} {:.0}% {}",
+ CONFIG.brightness.icon, value, CONFIG.seperator
+ );
+ ThreadsData::Brightness(result)
+}
diff --git a/src/utils/mod.rs b/src/utils/mod.rs
index cf9ea0d..c565434 100644
--- a/src/utils/mod.rs
+++ b/src/utils/mod.rs
@@ -1,5 +1,6 @@
pub mod battery;
pub mod bitcoins;
+pub mod brightness;
pub mod cpu;
pub mod disk;
pub mod load_average;