diff --git a/README.md b/README.md index 23b22d74..336c4fd6 100644 --- a/README.md +++ b/README.md @@ -321,8 +321,7 @@ List of supported commands: | `Repeat` | cycle the repeat mode | `C-r` | | `ToggleFakeTrackRepeatMode` | toggle fake track repeat mode | `M-r` | | `Shuffle` | toggle the shuffle mode | `C-s` | -| `VolumeUp` | increase playback volume by 5% | `+` | -| `VolumeDown` | decrease playback volume by 5% | `-` | +| `VolumeChange` | change playback volume by an offset (default shortcuts use 5%) | `+`, `-` | | `Mute` | toggle playback volume between 0% and previous level | `_` | | `SeekForward` | seek forward by 5s | `>` | | `SeekBackward` | seek backward by 5s | `<` | diff --git a/docs/config.md b/docs/config.md index 0aaeec09..6c764de3 100644 --- a/docs/config.md +++ b/docs/config.md @@ -284,6 +284,9 @@ key_sequence = "M-enter" [[keymaps]] command = "None" key_sequence = "q" +[[keymaps]] +command = { VolumeChange = { offset = 1 } } +key_sequence = "-" ``` ## Actions diff --git a/spotify_player/src/command.rs b/spotify_player/src/command.rs index d8625fcc..90bab2f6 100644 --- a/spotify_player/src/command.rs +++ b/spotify_player/src/command.rs @@ -16,8 +16,9 @@ pub enum Command { Repeat, ToggleFakeTrackRepeatMode, Shuffle, - VolumeUp, - VolumeDown, + VolumeChange { + offset: i32, + }, Mute, SeekForward, SeekBackward, @@ -284,7 +285,11 @@ pub fn construct_episode_actions(episode: &Episode, _data: &DataReadGuard) -> Ve } impl Command { - pub fn desc(self) -> &'static str { + pub fn desc(self) -> String { + if let Self::VolumeChange { offset } = self { + return format!("change playback volume by {offset}"); + } + match self { Self::None => "do nothing", Self::NextTrack => "next track", @@ -294,8 +299,6 @@ impl Command { Self::Repeat => "cycle the repeat mode", Self::ToggleFakeTrackRepeatMode => "toggle fake track repeat mode", Self::Shuffle => "toggle the shuffle mode", - Self::VolumeUp => "increase playback volume by 5%", - Self::VolumeDown => "decrease playback volume by 5%", Self::Mute => "toggle playback volume between 0% and previous level", Self::SeekForward => "seek forward by 5s", Self::SeekBackward => "seek backward by 5s", @@ -355,6 +358,8 @@ impl Command { Self::MovePlaylistItemUp => "move playlist item up one position", Self::MovePlaylistItemDown => "move playlist item down one position", Self::CreatePlaylist => "create a new playlist", + Self::VolumeChange { offset: _ } => unreachable!(), } + .to_string() } } diff --git a/spotify_player/src/config/keymap.rs b/spotify_player/src/config/keymap.rs index 256db7e3..ea0f346b 100644 --- a/spotify_player/src/config/keymap.rs +++ b/spotify_player/src/config/keymap.rs @@ -65,11 +65,11 @@ impl Default for KeymapConfig { }, Keymap { key_sequence: "+".into(), - command: Command::VolumeUp, + command: Command::VolumeChange { offset: 5 }, }, Keymap { key_sequence: "-".into(), - command: Command::VolumeDown, + command: Command::VolumeChange { offset: -5 }, }, Keymap { key_sequence: "_".into(), diff --git a/spotify_player/src/event/mod.rs b/spotify_player/src/event/mod.rs index e529503f..b1e9afa8 100644 --- a/spotify_player/src/event/mod.rs +++ b/spotify_player/src/event/mod.rs @@ -547,18 +547,10 @@ fn handle_global_command( Command::Shuffle => { client_pub.send(ClientRequest::Player(PlayerRequest::Shuffle))?; } - Command::VolumeUp => { + Command::VolumeChange { offset } => { if let Some(ref playback) = state.player.read().buffered_playback { if let Some(volume) = playback.volume { - let volume = std::cmp::min(volume + 5, 100_u32); - client_pub.send(ClientRequest::Player(PlayerRequest::Volume(volume as u8)))?; - } - } - } - Command::VolumeDown => { - if let Some(ref playback) = state.player.read().buffered_playback { - if let Some(volume) = playback.volume { - let volume = volume.saturating_sub(5_u32); + let volume = std::cmp::min(volume as i32 + offset, 100_i32); client_pub.send(ClientRequest::Player(PlayerRequest::Volume(volume as u8)))?; } }