From 2bdf9b32b8ef86e209310c610f9048253cb498d1 Mon Sep 17 00:00:00 2001 From: Andy Killorin <37423245+Speedy6451@users.noreply.github.com> Date: Sat, 28 Oct 2023 23:35:36 -0500 Subject: [PATCH] transitioned to compute shader-ish interface (dubious efficacy) --- Cargo.lock | 7 +++++++ Cargo.toml | 1 + src/main.rs | 52 +++++++++++++++++++++++++++++++++++++++------------- 3 files changed, 47 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b14344e..6657782 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -272,10 +272,17 @@ name = "funring" version = "0.1.0" dependencies = [ "anyhow", + "glam", "mpris", "tray-item", ] +[[package]] +name = "glam" +version = "0.24.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5418c17512bdf42730f9032c74e1ae39afc408745ebb2acf72fbc4691c17945" + [[package]] name = "heck" version = "0.3.3" diff --git a/Cargo.toml b/Cargo.toml index 85a6057..9221fce 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,7 @@ edition = "2021" [dependencies] anyhow = "1.0.75" +glam = "0.24.2" mpris = "2.0.1" [dependencies.tray-item] diff --git a/src/main.rs b/src/main.rs index 71a08e4..ba681ac 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,14 +1,16 @@ +use mpris::PlaybackStatus; use mpris::PlayerFinder; use anyhow::Result; use tray_item::IconSource; use tray_item::TrayItem; +use glam::UVec2; fn main() -> Result<()> { let pf = PlayerFinder::new()?; let players = pf.find_all()?; let mut tracker = players[0].track_progress(400)?; - let icon = IconSource::Data{data: gen_icon(0.0), height: RES, width: RES}; + let icon = IconSource::Data{data: gen_icon(0.0, false), height: RES, width: RES}; let mut tray = TrayItem::new("funring", icon)?; @@ -20,9 +22,10 @@ fn main() -> Result<()> { * tick.progress.playback_rate(); let total = tick.progress.length().unwrap().as_millis(); let prog = elapsed as f32 / total as f32; + let playing = tick.progress.playback_status() == PlaybackStatus::Playing; tray.set_icon( - IconSource::Data{data: gen_icon(prog), height: RES, width: RES} + IconSource::Data{data: gen_icon(prog, playing), height: RES, width: RES} )?; } } @@ -30,20 +33,43 @@ fn main() -> Result<()> { const RES: i32 = 8; const LEN: usize = (RES*RES) as usize; -fn gen_icon(prog: f32) -> Vec { - let mut icon = Vec::with_capacity(LEN); +fn gen_icon( + prog: f32, + playing: bool, +) -> Vec { + let mut icon = Vec::with_capacity(LEN*4); + (0..LEN*4).for_each(|_| icon.push(0)); for pix in 0..(LEN) { let x = pix % RES as usize; let y = pix / RES as usize; - icon.push(1); - icon.push( - if prog > pix as f32 / LEN as f32 { - 255 - } else { - 127 - }); - icon.push(0); - icon.push(0); + icon_cs( + UVec2::new(x as u32,y as u32), + prog, + playing, + &mut icon[0..LEN*4] + ); } icon } + +// TODO: integrate rust-gpu +fn icon_cs( + pix: UVec2, + progress: f32, + playing: bool, + buf: &mut [u8], +) { + let idx = (pix.y * RES as u32 + pix.x) as usize; + let pix = &mut buf[4*idx..4*idx+4]; + pix[0] = 1; + + if progress > idx as f32 / LEN as f32 { + pix[1] = 255; + pix[2] = 0; + pix[3] = 0; + } else { + pix[1] = 0; + pix[2] = 0; + pix[3] = 0; + } +}