transitioned to compute shader-ish interface (dubious efficacy)
This commit is contained in:
parent
fb8fc55f91
commit
2bdf9b32b8
3 changed files with 47 additions and 13 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
@ -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"
|
||||
|
|
|
@ -7,6 +7,7 @@ edition = "2021"
|
|||
|
||||
[dependencies]
|
||||
anyhow = "1.0.75"
|
||||
glam = "0.24.2"
|
||||
mpris = "2.0.1"
|
||||
|
||||
[dependencies.tray-item]
|
||||
|
|
52
src/main.rs
52
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<u8> {
|
||||
let mut icon = Vec::with_capacity(LEN);
|
||||
fn gen_icon(
|
||||
prog: f32,
|
||||
playing: bool,
|
||||
) -> Vec<u8> {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue