Compare commits
4 commits
015da43d1b
...
8e6305d934
Author | SHA1 | Date | |
---|---|---|---|
8e6305d934 | |||
1b92da1ab2 | |||
00240e4205 | |||
e4cdccce63 |
5 changed files with 41 additions and 18 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -1616,7 +1616,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mpd_info_screen"
|
name = "mpd_info_screen"
|
||||||
version = "0.4.11"
|
version = "0.4.12"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bindgen",
|
"bindgen",
|
||||||
"clap",
|
"clap",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "mpd_info_screen"
|
name = "mpd_info_screen"
|
||||||
version = "0.4.11"
|
version = "0.4.12"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "Displays info on currently playing music from an MPD daemon"
|
description = "Displays info on currently playing music from an MPD daemon"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|
|
@ -54,6 +54,8 @@ or through crates.io:
|
||||||
disable album display
|
disable album display
|
||||||
--disable-show-filename
|
--disable-show-filename
|
||||||
disable filename display
|
disable filename display
|
||||||
|
--disable-show-percentage
|
||||||
|
disable percentage display
|
||||||
--pprompt
|
--pprompt
|
||||||
input password via prompt
|
input password via prompt
|
||||||
--pfile <PASSWORD_FILE>
|
--pfile <PASSWORD_FILE>
|
||||||
|
|
|
@ -54,6 +54,14 @@ fn seconds_to_time(seconds: f64) -> String {
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn time_to_percentage(total: f64, current: f64) -> String {
|
||||||
|
let result = (100.0f64 * current / total).round().to_string();
|
||||||
|
match result.split_once('.') {
|
||||||
|
Some((a, _)) => a.to_string() + "%",
|
||||||
|
None => result + "%",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "unicode_support"))]
|
#[cfg(not(feature = "unicode_support"))]
|
||||||
#[allow(clippy::ptr_arg)]
|
#[allow(clippy::ptr_arg)]
|
||||||
fn string_to_text(
|
fn string_to_text(
|
||||||
|
@ -227,6 +235,7 @@ pub struct MPDDisplay {
|
||||||
text_bg_mesh: Option<Mesh>,
|
text_bg_mesh: Option<Mesh>,
|
||||||
hide_text: bool,
|
hide_text: bool,
|
||||||
tried_album_art_in_dir: bool,
|
tried_album_art_in_dir: bool,
|
||||||
|
prev_mpd_play_state: MPDPlayState,
|
||||||
mpd_play_state: MPDPlayState,
|
mpd_play_state: MPDPlayState,
|
||||||
loaded_fonts: Vec<(PathBuf, String)>,
|
loaded_fonts: Vec<(PathBuf, String)>,
|
||||||
}
|
}
|
||||||
|
@ -267,6 +276,7 @@ impl MPDDisplay {
|
||||||
text_bg_mesh: None,
|
text_bg_mesh: None,
|
||||||
hide_text: false,
|
hide_text: false,
|
||||||
tried_album_art_in_dir: false,
|
tried_album_art_in_dir: false,
|
||||||
|
prev_mpd_play_state: MPDPlayState::Playing,
|
||||||
mpd_play_state: MPDPlayState::Playing,
|
mpd_play_state: MPDPlayState::Playing,
|
||||||
loaded_fonts: Vec::new(),
|
loaded_fonts: Vec::new(),
|
||||||
filename_string_cache: String::new(),
|
filename_string_cache: String::new(),
|
||||||
|
@ -714,10 +724,8 @@ impl MPDDisplay {
|
||||||
Color::from_rgba(0, 0, 0, self.opts.text_bg_opacity),
|
Color::from_rgba(0, 0, 0, self.opts.text_bg_opacity),
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
let mesh: Mesh = Mesh::from_data(
|
if self.mpd_play_state == MPDPlayState::Playing {
|
||||||
ctx,
|
mesh_builder.rectangle(
|
||||||
mesh_builder
|
|
||||||
.rectangle(
|
|
||||||
DrawMode::fill(),
|
DrawMode::fill(),
|
||||||
Rect {
|
Rect {
|
||||||
x: TEXT_X_OFFSET,
|
x: TEXT_X_OFFSET,
|
||||||
|
@ -726,9 +734,9 @@ impl MPDDisplay {
|
||||||
h: timer_dimensions.h,
|
h: timer_dimensions.h,
|
||||||
},
|
},
|
||||||
Color::from_rgba(0, 0, 0, self.opts.text_bg_opacity),
|
Color::from_rgba(0, 0, 0, self.opts.text_bg_opacity),
|
||||||
)?
|
)?;
|
||||||
.build(),
|
}
|
||||||
);
|
let mesh: Mesh = Mesh::from_data(ctx, mesh_builder.build());
|
||||||
|
|
||||||
self.text_bg_mesh = Some(mesh);
|
self.text_bg_mesh = Some(mesh);
|
||||||
|
|
||||||
|
@ -831,8 +839,10 @@ impl EventHandler for MPDDisplay {
|
||||||
self.length = 0.0;
|
self.length = 0.0;
|
||||||
self.album_art = None;
|
self.album_art = None;
|
||||||
}
|
}
|
||||||
|
self.prev_mpd_play_state = self.mpd_play_state;
|
||||||
self.mpd_play_state = shared.mpd_play_state;
|
self.mpd_play_state = shared.mpd_play_state;
|
||||||
} else {
|
} else {
|
||||||
|
self.prev_mpd_play_state = self.mpd_play_state;
|
||||||
self.mpd_play_state = MPDPlayState::Playing;
|
self.mpd_play_state = MPDPlayState::Playing;
|
||||||
if !shared.title.is_empty() {
|
if !shared.title.is_empty() {
|
||||||
if shared.title != self.title_string_cache {
|
if shared.title != self.title_string_cache {
|
||||||
|
@ -929,7 +939,11 @@ impl EventHandler for MPDDisplay {
|
||||||
|
|
||||||
let delta = ctx.time.delta();
|
let delta = ctx.time.delta();
|
||||||
self.timer += delta.as_secs_f64();
|
self.timer += delta.as_secs_f64();
|
||||||
let timer_diff = seconds_to_time(self.length - self.timer);
|
let mut timer_diff = seconds_to_time(self.length - self.timer);
|
||||||
|
if !self.opts.disable_show_percentage {
|
||||||
|
let timer_percentage = time_to_percentage(self.length, self.timer);
|
||||||
|
timer_diff = timer_diff + " " + &timer_percentage;
|
||||||
|
}
|
||||||
let timer_diff_len = timer_diff.len();
|
let timer_diff_len = timer_diff.len();
|
||||||
self.timer_text = Text::new(timer_diff);
|
self.timer_text = Text::new(timer_diff);
|
||||||
self.timer_text.set_scale(PxScale {
|
self.timer_text.set_scale(PxScale {
|
||||||
|
@ -939,6 +953,11 @@ impl EventHandler for MPDDisplay {
|
||||||
if timer_diff_len != self.timer_text_len {
|
if timer_diff_len != self.timer_text_len {
|
||||||
self.timer_text_len = timer_diff_len;
|
self.timer_text_len = timer_diff_len;
|
||||||
self.update_bg_mesh(ctx)?;
|
self.update_bg_mesh(ctx)?;
|
||||||
|
} else if self.mpd_play_state != MPDPlayState::Playing
|
||||||
|
&& self.prev_mpd_play_state == MPDPlayState::Playing
|
||||||
|
{
|
||||||
|
self.update_bg_mesh(ctx)?;
|
||||||
|
self.prev_mpd_play_state = self.mpd_play_state;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -35,6 +35,8 @@ pub struct Opt {
|
||||||
disable_show_album: bool,
|
disable_show_album: bool,
|
||||||
#[arg(long = "disable-show-filename", help = "disable filename display")]
|
#[arg(long = "disable-show-filename", help = "disable filename display")]
|
||||||
disable_show_filename: bool,
|
disable_show_filename: bool,
|
||||||
|
#[arg(long = "disable-show-percentage", help = "disable percentage display")]
|
||||||
|
disable_show_percentage: bool,
|
||||||
#[arg(long = "pprompt", help = "input password via prompt")]
|
#[arg(long = "pprompt", help = "input password via prompt")]
|
||||||
enable_prompt_password: bool,
|
enable_prompt_password: bool,
|
||||||
#[arg(long = "pfile", help = "read password from file")]
|
#[arg(long = "pfile", help = "read password from file")]
|
||||||
|
|
Loading…
Reference in a new issue