From 7a9c8f3a5e9acb54119997170512f3ad8eb8119c Mon Sep 17 00:00:00 2001 From: Thomas Frans Date: Wed, 29 Nov 2023 15:34:02 +0100 Subject: [PATCH] fix: allow any value to set MPRIS volume This fixes a small inconsistency between the MPRIS implementation and the specification. The specification allows any number when setting the volume, which have to be clamped to the effectively allowed range in the application. https://specifications.freedesktop.org/mpris-spec/2.2/Player_Interface.html#Property:Volume --- CHANGELOG.md | 1 + src/mpris.rs | 11 +++++------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5dcfdb0..46da764 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Multiple instances interfering with each other's MPRIS implementation - An unlikely crash when the UNIX IPC socket is removed before `ncspot` is closed - Guaranteed crash while quiting `ncspot` when using MPRIS +- MPRIS volume not being updated when given numbers smaller than 0 or larger than 1 ## [0.13.4] - 2023-07-24 diff --git a/src/mpris.rs b/src/mpris.rs index a7fda8a..2a192d2 100644 --- a/src/mpris.rs +++ b/src/mpris.rs @@ -269,13 +269,12 @@ impl MprisPlayer { } #[dbus_interface(property)] - fn set_volume(&self, volume: f64) { + fn set_volume(&self, mut volume: f64) { log::info!("set volume: {volume}"); - if (0.0..=1.0).contains(&volume) { - let vol = (VOLUME_PERCENT as f64) * volume * 100.0; - self.spotify.set_volume(vol as u16); - self.event.trigger(); - } + volume = volume.clamp(0.0, 1.0); + let vol = (VOLUME_PERCENT as f64) * volume * 100.0; + self.spotify.set_volume(vol as u16); + self.event.trigger(); } #[dbus_interface(property)]