diff --git a/docs/modules/Music.md b/docs/modules/Music.md index 51fbbff..f9bfa7d 100644 --- a/docs/modules/Music.md +++ b/docs/modules/Music.md @@ -11,15 +11,17 @@ in MPRIS mode, the widget will listen to all players and automatically detect/di > Type: `music` -| | Type | Default | Description | -|----------------|------------------|-----------------------------|----------------------------------------------------------------------------------| -| `player_type` | `mpris` or `mpd` | `mpris` | Whether to connect to MPRIS players or an MPD server. | -| `format` | `string` | `{icon} {title} / {artist}` | Format string for the widget. More info below. | -| `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. | +| | Type | Default | Description | +|-------------------------------|------------------------------|-----------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------| +| `player_type` | `mpris` or `mpd` | `mpris` | Whether to connect to MPRIS players or an MPD server. | +| `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. |
JSON @@ -31,6 +33,7 @@ in MPRIS mode, the widget will listen to all players and automatically detect/di "type": "music", "player_type": "mpd", "format": "{icon} {title} / {artist}", + "truncate": "end", "icons": { "play": "", "pause": "" @@ -52,6 +55,7 @@ type = "music" player_type = "mpd" format = "{icon} {title} / {artist}" music_dir = "/home/jake/Music" +truncate = "end" [[start.icons]] play = "" @@ -68,6 +72,7 @@ start: - type: "music" player_type: "mpd" format: "{icon} {title} / {artist}" + truncate: "end" icons: play: "" pause: "" @@ -86,6 +91,7 @@ start: type = "music" player_type = "mpd" format = "{icon} {title} / {artist}" + truncate = "end" icons.play = "" icons.pause = "" music_dir = "/home/jake/Music" diff --git a/src/modules/music.rs b/src/modules/music.rs index 03767f8..1387a7a 100644 --- a/src/modules/music.rs +++ b/src/modules/music.rs @@ -7,6 +7,7 @@ use color_eyre::Result; use dirs::{audio_dir, home_dir}; use glib::Continue; use gtk::gdk_pixbuf::Pixbuf; +use gtk::pango::EllipsizeMode as GtkEllipsizeMode; use gtk::prelude::*; use gtk::{Button, Image, Label, Orientation, Scale}; use regex::Regex; @@ -53,7 +54,6 @@ impl Default for Icons { #[derive(Debug, Deserialize, Clone, Copy)] #[serde(rename_all = "snake_case")] pub enum PlayerType { - // Auto, Mpd, Mpris, } @@ -64,6 +64,50 @@ impl Default for PlayerType { } } +#[derive(Debug, Deserialize, Clone, Copy)] +#[serde(rename_all = "snake_case")] +pub enum EllipsizeMode { + Start, + Middle, + End, +} + +impl From for GtkEllipsizeMode { + fn from(value: EllipsizeMode) -> Self { + match value { + EllipsizeMode::Start => Self::Start, + EllipsizeMode::Middle => Self::Middle, + EllipsizeMode::End => Self::End, + } + } +} + +#[derive(Debug, Deserialize, Clone, Copy)] +#[serde(untagged)] +enum TruncateMode { + Auto(EllipsizeMode), + MaxLength { + mode: EllipsizeMode, + length: Option, + }, +} + +impl TruncateMode { + fn mode(&self) -> EllipsizeMode { + match self { + TruncateMode::Auto(mode) => *mode, + TruncateMode::MaxLength { mode, .. } => *mode, + } + } + + fn length(&self) -> Option { + match self { + TruncateMode::Auto(_) => None, + TruncateMode::MaxLength { length, .. } => *length, + } + } +} + #[derive(Debug, Deserialize, Clone)] pub struct MusicModule { /// Type of player to connect to @@ -78,6 +122,8 @@ pub struct MusicModule { #[serde(default)] icons: Icons, + truncate: Option, + // -- MPD -- /// TCP or Unix socket address. #[serde(default = "default_socket")] @@ -245,8 +291,20 @@ impl Module