mirror of
https://mzte.de/git/LordMZTE/dotfiles.git
synced 2024-05-18 23:14:24 +02:00
feat: add GPU block to i3status
This commit is contained in:
parent
5fba20762f
commit
f5f7404e59
22
scripts/i3status/src/gpu.rs
Normal file
22
scripts/i3status/src/gpu.rs
Normal file
|
@ -0,0 +1,22 @@
|
|||
//! Utilities to determine the GPU the system is running.
|
||||
|
||||
pub enum Type {
|
||||
NVidia,
|
||||
Amd,
|
||||
Unknown,
|
||||
}
|
||||
|
||||
impl Type {
|
||||
pub fn get() -> anyhow::Result<Self> {
|
||||
if std::fs::try_exists("/sys/module/nvidia")? {
|
||||
return Ok(Type::NVidia);
|
||||
}
|
||||
|
||||
// TODO: is it called amdgpu?
|
||||
if std::fs::try_exists("/sys/module/amdgpu")? {
|
||||
return Ok(Type::Amd);
|
||||
}
|
||||
|
||||
Ok(Type::Unknown)
|
||||
}
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
#![warn(clippy::pedantic)]
|
||||
#![feature(fs_try_exists)]
|
||||
use std::sync::Arc;
|
||||
use unicode_segmentation::UnicodeSegmentation;
|
||||
|
||||
|
@ -18,6 +19,7 @@ use i3status_rs::{
|
|||
};
|
||||
|
||||
mod catppuccin;
|
||||
mod gpu;
|
||||
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
async fn main() {
|
||||
|
@ -78,6 +80,15 @@ async fn try_main() -> anyhow::Result<()> {
|
|||
..Default::default()
|
||||
});
|
||||
|
||||
spawn_blocks(&mut bar).await?;
|
||||
|
||||
bar.run_event_loop(|| panic!("Hey! No restarting!")).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[allow(clippy::needless_pass_by_ref_mut)] // clippy is to stupid to reason about my macro
|
||||
async fn spawn_blocks(bar: &mut BarState) -> anyhow::Result<()> {
|
||||
macro_rules! spawn {
|
||||
($mod:ident $structinit:tt) => {
|
||||
bar.spawn_block(BlockConfigEntry {
|
||||
|
@ -110,6 +121,22 @@ async fn try_main() -> anyhow::Result<()> {
|
|||
..Default::default()
|
||||
});
|
||||
|
||||
match gpu::Type::get()? {
|
||||
gpu::Type::NVidia => {
|
||||
spawn!(nvidia_gpu {
|
||||
format: " $icon $utilization $memory $temperature $fan_speed $power".parse()?,
|
||||
..Default::default()
|
||||
});
|
||||
},
|
||||
gpu::Type::Amd => {
|
||||
spawn!(amd_gpu {
|
||||
format: " $icon $utilization $vram_used_percents".parse()?,
|
||||
..Default::default()
|
||||
});
|
||||
},
|
||||
gpu::Type::Unknown => {}, // no GPU block
|
||||
}
|
||||
|
||||
spawn!(music {
|
||||
interface_name_exclude: vec![".*kdeconnect.*".to_string(), "mpd".to_string()],
|
||||
format: " $icon {$combo.str(max_w:20, rot_interval:0.1) $prev $play $next|}".parse()?,
|
||||
|
@ -134,7 +161,5 @@ async fn try_main() -> anyhow::Result<()> {
|
|||
..Default::default()
|
||||
});
|
||||
|
||||
bar.run_event_loop(|| panic!("Hey! No restarting!")).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue