feat: add mouse scroll to incease/decrease volume#931
feat: add mouse scroll to incease/decrease volume#931aome510 merged 4 commits intoaome510:masterfrom
Conversation
spotify_player/src/config/keymap.rs
Outdated
| Keymap { | ||
| key_sequence: "m s u".into(), | ||
| command: Command::VolumeUp, | ||
| }, | ||
| Keymap { | ||
| key_sequence: "m s d".into(), | ||
| command: Command::VolumeDown, | ||
| }, |
There was a problem hiding this comment.
there is already VolumeChange command, why did you add new ones?
There was a problem hiding this comment.
oh my bad! i will use VolumeChange instead
There was a problem hiding this comment.
Pull request overview
This PR adds mouse scroll support to control playback volume in response to issue #446, which requested the ability to bind mouse scroll events to volume control. The implementation introduces two new commands (VolumeUp and VolumeDown), adds corresponding player requests, and implements mouse scroll event handling with a configurable volume step.
Changes:
- Added
VolumeUpandVolumeDowncommands with default key bindings to "m s u" and "m s d" - Implemented mouse scroll event handlers (ScrollUp/ScrollDown) that trigger volume changes
- Added
volume_scroll_stepconfiguration option (default: 5%) to control the volume increment/decrement size
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| spotify_player/src/event/mod.rs | Added mouse scroll event handlers and VolumeUp/VolumeDown command handlers |
| spotify_player/src/config/mod.rs | Added volume_scroll_step configuration field with default value of 5 |
| spotify_player/src/config/keymap.rs | Added default keymaps for VolumeUp ("m s u") and VolumeDown ("m s d") |
| spotify_player/src/command.rs | Added VolumeUp and VolumeDown command enum variants with descriptions |
| spotify_player/src/client/request.rs | Added VolumeUp and VolumeDown request enum variants |
| spotify_player/src/client/mod.rs | Implemented VolumeUp and VolumeDown request handlers with volume bounds checking |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
spotify_player/src/event/mod.rs
Outdated
| if keymap_config | ||
| .find_command_or_action_from_key_sequence(&key_sequence) | ||
| .is_some() | ||
| { | ||
| let _ = client_pub.try_send(ClientRequest::Player(PlayerRequest::VolumeUp)); | ||
| } | ||
| } | ||
| crossterm::event::MouseEventKind::ScrollDown => { | ||
| let key_sequence: KeySequence = "m s d".into(); | ||
| let keymap_config = &config::get_config().keymap_config; | ||
| if keymap_config | ||
| .find_command_or_action_from_key_sequence(&key_sequence) | ||
| .is_some() | ||
| { | ||
| let _ = client_pub.try_send(ClientRequest::Player(PlayerRequest::VolumeDown)); |
There was a problem hiding this comment.
The mouse scroll handler hardcodes the key sequences "m s u" and the VolumeUp command. This implementation checks if "m s u" exists in the keymap config but then always sends VolumeUp regardless of what command is actually mapped to that sequence. Instead, the handler should retrieve the command from the keymap using find_command_or_action_from_key_sequence and execute whatever command is mapped to "m s u", similar to how handle_key_event works (lines 149-157). This would allow users to customize what mouse scroll does, not just limit it to volume control.
| if keymap_config | |
| .find_command_or_action_from_key_sequence(&key_sequence) | |
| .is_some() | |
| { | |
| let _ = client_pub.try_send(ClientRequest::Player(PlayerRequest::VolumeUp)); | |
| } | |
| } | |
| crossterm::event::MouseEventKind::ScrollDown => { | |
| let key_sequence: KeySequence = "m s d".into(); | |
| let keymap_config = &config::get_config().keymap_config; | |
| if keymap_config | |
| .find_command_or_action_from_key_sequence(&key_sequence) | |
| .is_some() | |
| { | |
| let _ = client_pub.try_send(ClientRequest::Player(PlayerRequest::VolumeDown)); | |
| if let Some(command_or_action) = | |
| keymap_config.find_command_or_action_from_key_sequence(&key_sequence) | |
| { | |
| // Execute whatever command or action is mapped to "m s u" | |
| handle_command_or_action(command_or_action, client_pub, state)?; | |
| } | |
| } | |
| crossterm::event::MouseEventKind::ScrollDown => { | |
| let key_sequence: KeySequence = "m s d".into(); | |
| let keymap_config = &config::get_config().keymap_config; | |
| if let Some(command_or_action) = | |
| keymap_config.find_command_or_action_from_key_sequence(&key_sequence) | |
| { | |
| // Execute whatever command or action is mapped to "m s d" | |
| handle_command_or_action(command_or_action, client_pub, state)?; |
spotify_player/src/event/mod.rs
Outdated
| if keymap_config | ||
| .find_command_or_action_from_key_sequence(&key_sequence) | ||
| .is_some() | ||
| { | ||
| let _ = client_pub.try_send(ClientRequest::Player(PlayerRequest::VolumeUp)); | ||
| } | ||
| } | ||
| crossterm::event::MouseEventKind::ScrollDown => { | ||
| let key_sequence: KeySequence = "m s d".into(); | ||
| let keymap_config = &config::get_config().keymap_config; | ||
| if keymap_config | ||
| .find_command_or_action_from_key_sequence(&key_sequence) | ||
| .is_some() | ||
| { | ||
| let _ = client_pub.try_send(ClientRequest::Player(PlayerRequest::VolumeDown)); |
There was a problem hiding this comment.
Same issue as ScrollUp handler: this hardcodes the key sequence "m s d" and always sends VolumeDown. The handler should retrieve and execute the actual command mapped to "m s d" from the keymap config using find_command_or_action_from_key_sequence, allowing users to customize mouse scroll behavior beyond just volume control.
| if keymap_config | |
| .find_command_or_action_from_key_sequence(&key_sequence) | |
| .is_some() | |
| { | |
| let _ = client_pub.try_send(ClientRequest::Player(PlayerRequest::VolumeUp)); | |
| } | |
| } | |
| crossterm::event::MouseEventKind::ScrollDown => { | |
| let key_sequence: KeySequence = "m s d".into(); | |
| let keymap_config = &config::get_config().keymap_config; | |
| if keymap_config | |
| .find_command_or_action_from_key_sequence(&key_sequence) | |
| .is_some() | |
| { | |
| let _ = client_pub.try_send(ClientRequest::Player(PlayerRequest::VolumeDown)); | |
| if let Some(command_or_action) = | |
| keymap_config.find_command_or_action_from_key_sequence(&key_sequence) | |
| { | |
| // Execute the command or action mapped to "m s u" so users can customize | |
| // scroll-up behavior (e.g. volume up or something else). | |
| command::handle_command_or_action(command_or_action, &state, client_pub)?; | |
| } | |
| } | |
| crossterm::event::MouseEventKind::ScrollDown => { | |
| let key_sequence: KeySequence = "m s d".into(); | |
| let keymap_config = &config::get_config().keymap_config; | |
| if let Some(command_or_action) = | |
| keymap_config.find_command_or_action_from_key_sequence(&key_sequence) | |
| { | |
| // Execute the command or action mapped to "m s d" so users can customize | |
| // scroll-down behavior (e.g. volume down or something else). | |
| command::handle_command_or_action(command_or_action, &state, client_pub)?; |
spotify_player/src/event/mod.rs
Outdated
| .find_command_or_action_from_key_sequence(&key_sequence) | ||
| .is_some() | ||
| { | ||
| let _ = client_pub.try_send(ClientRequest::Player(PlayerRequest::VolumeUp)); |
There was a problem hiding this comment.
Error handling is silently discarded with the underscore pattern. This is inconsistent with the rest of the function which uses ? to propagate errors (see line 103-105). If the VolumeUp request fails to send, the user should be notified. Consider using the same error handling pattern as the SeekTrack request below.
spotify_player/src/event/mod.rs
Outdated
| .find_command_or_action_from_key_sequence(&key_sequence) | ||
| .is_some() | ||
| { | ||
| let _ = client_pub.try_send(ClientRequest::Player(PlayerRequest::VolumeDown)); |
There was a problem hiding this comment.
Error handling is silently discarded with the underscore pattern. This is inconsistent with the rest of the function which uses ? to propagate errors (see line 103-105). If the VolumeDown request fails to send, the user should be notified. Consider using the same error handling pattern as the SeekTrack request below.
spotify_player/src/event/mod.rs
Outdated
| crossterm::event::MouseEventKind::ScrollUp => { | ||
| let key_sequence: KeySequence = "m s u".into(); | ||
| let keymap_config = &config::get_config().keymap_config; | ||
| if keymap_config | ||
| .find_command_or_action_from_key_sequence(&key_sequence) | ||
| .is_some() | ||
| { | ||
| let _ = client_pub.try_send(ClientRequest::Player(PlayerRequest::VolumeUp)); | ||
| } | ||
| } | ||
| crossterm::event::MouseEventKind::ScrollDown => { | ||
| let key_sequence: KeySequence = "m s d".into(); | ||
| let keymap_config = &config::get_config().keymap_config; | ||
| if keymap_config | ||
| .find_command_or_action_from_key_sequence(&key_sequence) | ||
| .is_some() | ||
| { | ||
| let _ = client_pub.try_send(ClientRequest::Player(PlayerRequest::VolumeDown)); | ||
| } |
There was a problem hiding this comment.
The PR description states users can configure keymaps in keymap.toml to bind VolumeUp/VolumeDown commands to key sequences "m s u" and "m s d". However, the mouse scroll implementation hardcodes these key sequences and always executes VolumeUp/VolumeDown regardless of what users actually configure. This creates a discrepancy between what the PR description promises (configurability) and what the code delivers (hardcoded behavior). The implementation should honor user-configured keymaps by retrieving and executing the mapped command, not bypassing the keymap system.
|
would changing it to use a bool like |
|
one problem i faced is that i had to reuse some of the of A potential fix would be to add a small helper function that the mouse handler could use. |
- add `enable_mouse_scroll_volume` to config - fix error handling to properly propagate errors - remove `VolumeUp` and `VolumeDown` entirely
1167478 to
4c68534
Compare
Adds mouse scroll support to increase/decrease volume.
Resolves #446.
In
app.toml: