|
19 | 19 | //! Key | Values | Default
|
20 | 20 | //! ----|--------|--------
|
21 | 21 | //! `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 |}"</code>
|
| 22 | +//! `format_alt` | If set, block will switch between `format` and `format_alt` on every click | `None` |
22 | 23 | //! `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 | grep "org.mpris.MediaPlayer2." | cut -d' ' -f1</code> and the name is the part after "org.mpris.MediaPlayer2.". | `None`
|
23 | 24 | //! `interface_name_exclude` | A list of regex patterns for player MPRIS interface names to ignore. | `["playerctld"]`
|
24 | 25 | //! `separator` | String to insert between artist and title. | `" - "`
|
|
53 | 54 | //! `seek_backward` | Wheel Down
|
54 | 55 | //! `volume_up` | -
|
55 | 56 | //! `volume_down` | -
|
| 57 | +//! `toggle_format` | Left |
56 | 58 | //!
|
57 | 59 | //! # Examples
|
58 | 60 | //!
|
|
84 | 86 | //! interface_name_exclude = [".*kdeconnect.*", "mpd"]
|
85 | 87 | //! ```
|
86 | 88 | //!
|
87 |
| -//! Click anywhere to play/pause: |
| 89 | +//! Click anywhere to play/pause, middle click to toggle format: |
88 | 90 | //!
|
89 | 91 | //! ```toml
|
90 | 92 | //! [[block]]
|
91 | 93 | //! block = "music"
|
| 94 | +//! format = " format 1 " |
| 95 | +//! format_alt = " format 2 " |
92 | 96 | //! [[block.click]]
|
93 | 97 | //! button = "left"
|
94 | 98 | //! action = "play_pause"
|
| 99 | +//! [[block.click]] |
| 100 | +//! button = "middle" |
| 101 | +//! action = "toggle_format" |
95 | 102 | //! ```
|
96 | 103 | //!
|
97 | 104 | //! Scroll to change the player volume, use the forward and back buttons to seek:
|
@@ -147,6 +154,7 @@ const PREV_BTN: &str = "prev_btn";
|
147 | 154 | #[serde(deny_unknown_fields, default)]
|
148 | 155 | pub struct Config {
|
149 | 156 | pub format: FormatConfig,
|
| 157 | + pub format_alt: Option<FormatConfig>, |
150 | 158 | pub player: PlayerName,
|
151 | 159 | #[default(vec!["playerctld".into()])]
|
152 | 160 | pub interface_name_exclude: Vec<String>,
|
@@ -175,13 +183,18 @@ pub async fn run(config: &Config, api: &CommonApi) -> Result<()> {
|
175 | 183 | (MouseButton::Right, None, "next_player"),
|
176 | 184 | (MouseButton::WheelUp, None, "seek_forward"),
|
177 | 185 | (MouseButton::WheelDown, None, "seek_backward"),
|
| 186 | + (MouseButton::Left, None, "toggle_format"), |
178 | 187 | ])?;
|
179 | 188 |
|
180 | 189 | let dbus_conn = new_dbus_connection().await?;
|
181 | 190 |
|
182 |
| - let format = config |
| 191 | + let mut format = config |
183 | 192 | .format
|
184 | 193 | .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 | + }; |
185 | 198 |
|
186 | 199 | let volume_step = config.volume_step.clamp(0.0, 50.0) / 100.0;
|
187 | 200 |
|
@@ -453,6 +466,12 @@ pub async fn run(config: &Config, api: &CommonApi) -> Result<()> {
|
453 | 466 | "volume_down" => {
|
454 | 467 | player.set_volume(-volume_step).await?;
|
455 | 468 | }
|
| 469 | + "toggle_format" => { |
| 470 | + if let Some(format_alt) = &mut format_alt { |
| 471 | + std::mem::swap(format_alt, &mut format); |
| 472 | + break; |
| 473 | + } |
| 474 | + } |
456 | 475 | _ => (),
|
457 | 476 | }
|
458 | 477 | }
|
|
0 commit comments