1
Fork 0
This commit is contained in:
Andy Killorin 2023-10-29 11:40:31 -05:00
parent 4b5f44524c
commit 60061345fc
Signed by: ank
GPG key ID: B6241CA3B552BCA4

View file

@ -4,20 +4,24 @@ use std::collections::hash_map::DefaultHasher;
use std::hash::Hash; use std::hash::Hash;
use std::hash::Hasher; use std::hash::Hasher;
use mpris::PlaybackStatus;
use mpris::PlayerFinder;
use anyhow::Result; use anyhow::Result;
use tray_item::IconSource;
use tray_item::TrayItem;
use glam::UVec2; use glam::UVec2;
use glam::Vec2; use glam::Vec2;
use mpris::PlaybackStatus;
use mpris::PlayerFinder;
use tray_item::IconSource;
use tray_item::TrayItem;
fn main() -> Result<()> { fn main() -> Result<()> {
let pf = PlayerFinder::new()?; let pf = PlayerFinder::new()?;
let players = pf.find_all()?; let players = pf.find_all()?;
let mut tracker = players[0].track_progress(25)?; let mut tracker = players[0].track_progress(25)?;
let icon = IconSource::Data{data: gen_icon(0.0, false), 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)?; let mut tray = TrayItem::new("funring", icon)?;
@ -38,7 +42,11 @@ fn main() -> Result<()> {
hasher.finish() hasher.finish()
}; };
if !last_hash.replace(hash).is_some_and(|h| h == hash) { if !last_hash.replace(hash).is_some_and(|h| h == hash) {
tray.set_icon(IconSource::Data{data: buffer, height: RES, width: RES})?; tray.set_icon(IconSource::Data {
data: buffer,
height: RES,
width: RES,
})?;
} }
} }
} }
@ -46,10 +54,7 @@ fn main() -> Result<()> {
const RES: i32 = 32; const RES: i32 = 32;
const LEN: usize = (RES * RES) as usize; const LEN: usize = (RES * RES) as usize;
fn gen_icon( fn gen_icon(prog: f32, playing: bool) -> Vec<u8> {
prog: f32,
playing: bool,
) -> Vec<u8> {
let mut icon = vec![0; LEN * 4]; let mut icon = vec![0; LEN * 4];
for pix in 0..(LEN) { for pix in 0..(LEN) {
let x = pix % RES as usize; let x = pix % RES as usize;
@ -58,19 +63,14 @@ fn gen_icon(
UVec2::new(x as u32, y as u32), UVec2::new(x as u32, y as u32),
prog, prog,
playing, playing,
&mut icon[0..LEN*4] &mut icon[0..LEN * 4],
); );
} }
icon icon
} }
// TODO: integrate rust-gpu // TODO: integrate rust-gpu
fn icon_cs( fn icon_cs(idx: UVec2, progress: f32, playing: bool, buf: &mut [u8]) {
idx: UVec2,
progress: f32,
playing: bool,
buf: &mut [u8],
) {
let index = (idx.y * RES as u32 + idx.x) as usize; let index = (idx.y * RES as u32 + idx.x) as usize;
let pix = &mut buf[4 * index..4 * index + 4]; let pix = &mut buf[4 * index..4 * index + 4];
pix[0] = 1; pix[0] = 1;