Skip to content

Commit 815d093

Browse files
authored
music: add format_alt (#1960)
1 parent 69b3843 commit 815d093

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/blocks/music.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
//! Key | Values | Default
2020
//! ----|--------|--------
2121
//! `format` | A string to customise the output of this block. See below for available placeholders. | <code>" $icon {$combo.str(max_w:25,rot_interval:0.5) $play &vert;}"</code>
22+
//! `format_alt` | If set, block will switch between `format` and `format_alt` on every click | `None`
2223
//! `player` | Name(s) of the music player(s) MPRIS interface. This can be either a music player name or an array of music player names. Run <code>busctl --user list &vert; grep "org.mpris.MediaPlayer2." &vert; cut -d' ' -f1</code> and the name is the part after "org.mpris.MediaPlayer2.". | `None`
2324
//! `interface_name_exclude` | A list of regex patterns for player MPRIS interface names to ignore. | `["playerctld"]`
2425
//! `separator` | String to insert between artist and title. | `" - "`
@@ -53,6 +54,7 @@
5354
//! `seek_backward` | Wheel Down
5455
//! `volume_up` | -
5556
//! `volume_down` | -
57+
//! `toggle_format` | Left
5658
//!
5759
//! # Examples
5860
//!
@@ -84,14 +86,19 @@
8486
//! interface_name_exclude = [".*kdeconnect.*", "mpd"]
8587
//! ```
8688
//!
87-
//! Click anywhere to play/pause:
89+
//! Click anywhere to play/pause, middle click to toggle format:
8890
//!
8991
//! ```toml
9092
//! [[block]]
9193
//! block = "music"
94+
//! format = " format 1 "
95+
//! format_alt = " format 2 "
9296
//! [[block.click]]
9397
//! button = "left"
9498
//! action = "play_pause"
99+
//! [[block.click]]
100+
//! button = "middle"
101+
//! action = "toggle_format"
95102
//! ```
96103
//!
97104
//! Scroll to change the player volume, use the forward and back buttons to seek:
@@ -147,6 +154,7 @@ const PREV_BTN: &str = "prev_btn";
147154
#[serde(deny_unknown_fields, default)]
148155
pub struct Config {
149156
pub format: FormatConfig,
157+
pub format_alt: Option<FormatConfig>,
150158
pub player: PlayerName,
151159
#[default(vec!["playerctld".into()])]
152160
pub interface_name_exclude: Vec<String>,
@@ -175,13 +183,18 @@ pub async fn run(config: &Config, api: &CommonApi) -> Result<()> {
175183
(MouseButton::Right, None, "next_player"),
176184
(MouseButton::WheelUp, None, "seek_forward"),
177185
(MouseButton::WheelDown, None, "seek_backward"),
186+
(MouseButton::Left, None, "toggle_format"),
178187
])?;
179188

180189
let dbus_conn = new_dbus_connection().await?;
181190

182-
let format = config
191+
let mut format = config
183192
.format
184193
.with_default(" $icon {$combo.str(max_w:25,rot_interval:0.5) $play |}")?;
194+
let mut format_alt = match &config.format_alt {
195+
Some(f) => Some(f.with_default("")?),
196+
None => None,
197+
};
185198

186199
let volume_step = config.volume_step.clamp(0.0, 50.0) / 100.0;
187200

@@ -453,6 +466,12 @@ pub async fn run(config: &Config, api: &CommonApi) -> Result<()> {
453466
"volume_down" => {
454467
player.set_volume(-volume_step).await?;
455468
}
469+
"toggle_format" => {
470+
if let Some(format_alt) = &mut format_alt {
471+
std::mem::swap(format_alt, &mut format);
472+
break;
473+
}
474+
}
456475
_ => (),
457476
}
458477
}

0 commit comments

Comments
 (0)