rustfmt
This commit is contained in:
parent
4b5f44524c
commit
60061345fc
1 changed files with 27 additions and 27 deletions
52
src/main.rs
52
src/main.rs
|
@ -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,56 +42,52 @@ 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,
|
||||||
|
})?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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,
|
let mut icon = vec![0; LEN * 4];
|
||||||
playing: bool,
|
|
||||||
) -> Vec<u8> {
|
|
||||||
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;
|
||||||
let y = pix / RES as usize;
|
let y = pix / RES as usize;
|
||||||
icon_cs(
|
icon_cs(
|
||||||
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;
|
||||||
|
|
||||||
let center = Vec2::splat(RES as f32 /2.0);
|
let center = Vec2::splat(RES as f32 / 2.0);
|
||||||
let idx = idx.as_vec2()-center;
|
let idx = idx.as_vec2() - center;
|
||||||
let radius = idx.length() / RES as f32 * 2.0;
|
let radius = idx.length() / RES as f32 * 2.0;
|
||||||
let theta = std::f32::consts::PI - f32::atan2(idx.x, idx.y);
|
let theta = std::f32::consts::PI - f32::atan2(idx.x, idx.y);
|
||||||
|
|
||||||
let offset = theta - progress * std::f32::consts::TAU;
|
let offset = theta - progress * std::f32::consts::TAU;
|
||||||
|
|
||||||
if offset < 0.0 && 0.5 < radius && radius < 1.0 {
|
if offset < 0.0 && 0.5 < radius && radius < 1.0 {
|
||||||
pix[1] = if playing {255} else {0};
|
pix[1] = if playing { 255 } else { 0 };
|
||||||
pix[2] = if playing {0} else {95};
|
pix[2] = if playing { 0 } else { 95 };
|
||||||
pix[3] = 0;
|
pix[3] = 0;
|
||||||
} else if 1.0 > radius {
|
} else if 1.0 > radius {
|
||||||
pix[1] = if playing {60} else {20};
|
pix[1] = if playing { 60 } else { 20 };
|
||||||
pix[2] = 0;
|
pix[2] = 0;
|
||||||
pix[3] = 0;
|
pix[3] = 0;
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue