From 96141d49907412ea26d23ef30c10ade8b32b89b9 Mon Sep 17 00:00:00 2001 From: Jake Stanger Date: Sun, 29 Jan 2023 22:49:22 +0000 Subject: [PATCH] feat(music): support for using images in `name_map`, additional icon options --- docs/modules/Music.md | 60 +++++++++-------- src/modules/music/config.rs | 49 +++++++++++++- src/modules/music/mod.rs | 128 +++++++++++++++++++++--------------- 3 files changed, 158 insertions(+), 79 deletions(-) diff --git a/docs/modules/Music.md b/docs/modules/Music.md index f9bfa7d..71fe7c7 100644 --- a/docs/modules/Music.md +++ b/docs/modules/Music.md @@ -17,11 +17,18 @@ in MPRIS mode, the widget will listen to all players and automatically detect/di | `format` | `string` | `{icon} {title} / {artist}` | Format string for the widget. More info below. | | `truncate` or `truncate.mode` | `start` or `middle` or `end` | `null` | The location of the ellipses and where to truncate text from. Leave null to avoid truncating. Use the long-hand version if specifying a length. | | `truncate.length` | `integer` | `null` | The maximum number of characters before truncating. Leave blank to let GTK automatically handle. | -| `icons.play` | `string` | `` | Icon to show when playing. | -| `icons.pause` | `string` | `` | Icon to show when paused. | -| `icons.volume` | `string` | `墳` | Icon to show under popup volume slider. | -| `host` | `string` | `localhost:6600` | [MPD Only] TCP or Unix socket for the MPD server. | -| `music_dir` | `string` | `$HOME/Music` | [MPD Only] Path to MPD server's music directory on disc. Required for album art. | +| `icons.play` | `string/image` | `` | Icon to show when playing. | +| `icons.pause` | `string/image` | `` | Icon to show when paused. | +| `icons.prev` | `string/image` | `玲` | Icon to show on previous button. | +| `icons.next` | `string/image` | `怜` | Icon to show on next button. | +| `icons.volume` | `string/image` | `墳` | Icon to show under popup volume slider. | +| `icons.track` | `string/image` | `` | Icon to show next to track title. | +| `icons.album` | `string/image` | `` | Icon to show next to album name. | +| `icons.artist` | `string/image` | `ﴁ` | Icon to show next to artist name. | +| `host` | `string/image` | `localhost:6600` | [MPD Only] TCP or Unix socket for the MPD server. | +| `music_dir` | `string/image` | `$HOME/Music` | [MPD Only] Path to MPD server's music directory on disc. Required for album art. | + +See [here](images) for information on images.
JSON @@ -122,24 +129,25 @@ and will be replaced with values from the currently playing track: ## Styling -| Selector | Description | -|------------------------------------------|------------------------------------------| -| `#music` | Tray widget button | -| `#popup-music` | Popup box | -| `#popup-music #album-art` | Album art image inside popup box | -| `#popup-music #title` | Track title container inside popup box | -| `#popup-music #title .icon` | Track title icon label inside popup box | -| `#popup-music #title .label` | Track title label inside popup box | -| `#popup-music #album` | Track album container inside popup box | -| `#popup-music #album .icon` | Track album icon label inside popup box | -| `#popup-music #album .label` | Track album label inside popup box | -| `#popup-music #artist` | Track artist container inside popup box | -| `#popup-music #artist .icon` | Track artist icon label inside popup box | -| `#popup-music #artist .label` | Track artist label inside popup box | -| `#popup-music #controls` | Controls container inside popup box | -| `#popup-music #controls #btn-prev` | Previous button inside popup box | -| `#popup-music #controls #btn-play-pause` | Play/pause button inside popup box | -| `#popup-music #controls #btn-next` | Next button inside popup box | -| `#popup-music #volume` | Volume container inside popup box | -| `#popup-music #volume #slider` | Volume slider popup box | -| `#popup-music #volume .icon` | Volume icon label inside popup box | \ No newline at end of file +| Selector | Description | +|-------------------------------------|------------------------------------------| +| `#music` | Tray widget button | +| `#popup-music` | Popup box | +| `#popup-music #album-art` | Album art image inside popup box | +| `#popup-music #title` | Track title container inside popup box | +| `#popup-music #title .icon` | Track title icon label inside popup box | +| `#popup-music #title .label` | Track title label inside popup box | +| `#popup-music #album` | Track album container inside popup box | +| `#popup-music #album .icon` | Track album icon label inside popup box | +| `#popup-music #album .label` | Track album label inside popup box | +| `#popup-music #artist` | Track artist container inside popup box | +| `#popup-music #artist .icon` | Track artist icon label inside popup box | +| `#popup-music #artist .label` | Track artist label inside popup box | +| `#popup-music #controls` | Controls container inside popup box | +| `#popup-music #controls #btn-prev` | Previous button inside popup box | +| `#popup-music #controls #btn-play` | Play button inside popup box | +| `#popup-music #controls #btn-pause` | Pause button inside popup box | +| `#popup-music #controls #btn-next` | Next button inside popup box | +| `#popup-music #volume` | Volume container inside popup box | +| `#popup-music #volume #slider` | Volume slider popup box | +| `#popup-music #volume .icon` | Volume icon label inside popup box | \ No newline at end of file diff --git a/src/modules/music/config.rs b/src/modules/music/config.rs index e52b824..72b47cc 100644 --- a/src/modules/music/config.rs +++ b/src/modules/music/config.rs @@ -8,12 +8,34 @@ pub struct Icons { /// Icon to display when playing. #[serde(default = "default_icon_play")] pub(crate) play: String, + /// Icon to display when paused. #[serde(default = "default_icon_pause")] pub(crate) pause: String, + + /// Icon to display for previous button. + #[serde(default = "default_icon_prev")] + pub(crate) prev: String, + + /// Icon to display for next button. + #[serde(default = "default_icon_next")] + pub(crate) next: String, + /// Icon to display under volume slider #[serde(default = "default_icon_volume")] pub(crate) volume: String, + + /// Icon to display nex to track title + #[serde(default = "default_icon_track")] + pub(crate) track: String, + + /// Icon to display nex to album name + #[serde(default = "default_icon_album")] + pub(crate) album: String, + + /// Icon to display nex to artist name + #[serde(default = "default_icon_artist")] + pub(crate) artist: String, } impl Default for Icons { @@ -21,7 +43,12 @@ impl Default for Icons { Self { pause: default_icon_pause(), play: default_icon_play(), + prev: default_icon_prev(), + next: default_icon_next(), volume: default_icon_volume(), + track: default_icon_track(), + album: default_icon_album(), + artist: default_icon_artist(), } } } @@ -73,7 +100,7 @@ fn default_socket() -> String { } fn default_format() -> String { - String::from("{icon} {title} / {artist}") + String::from("{title} / {artist}") } fn default_icon_play() -> String { @@ -84,10 +111,30 @@ fn default_icon_pause() -> String { String::from("") } +fn default_icon_prev() -> String { + String::from("\u{f9ad}") +} + +fn default_icon_next() -> String { + String::from("\u{f9ac}") +} + fn default_icon_volume() -> String { String::from("墳") } +fn default_icon_track() -> String { + String::from("\u{f886}") +} + +fn default_icon_album() -> String { + String::from("\u{f524}") +} + +fn default_icon_artist() -> String { + String::from("\u{fd01}") +} + fn default_music_dir() -> PathBuf { audio_dir().unwrap_or_else(|| home_dir().map(|dir| dir.join("Music")).unwrap_or_default()) } diff --git a/src/modules/music/mod.rs b/src/modules/music/mod.rs index 38f762a..1d84f39 100644 --- a/src/modules/music/mod.rs +++ b/src/modules/music/mod.rs @@ -1,7 +1,7 @@ mod config; use crate::clients::music::{self, MusicClient, PlayerState, PlayerUpdate, Status, Track}; -use crate::image::ImageProvider; +use crate::image::{new_icon_button, new_icon_label, ImageProvider}; use crate::modules::{Module, ModuleInfo, ModuleUpdateEvent, ModuleWidget, WidgetContext}; use crate::popup::Popup; use crate::{send_async, try_send}; @@ -18,7 +18,7 @@ use tokio::sync::mpsc::{Receiver, Sender}; use tracing::error; pub use self::config::MusicModule; -use self::config::{Icons, PlayerType}; +use self::config::PlayerType; #[derive(Debug)] pub enum PlayerCommand { @@ -80,7 +80,6 @@ impl Module