diff --git a/CHANGELOG.md b/CHANGELOG.md index 0318ab6..3c7f80a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ One section per version, newest first. +## v0.6.6 (2026-11-04) + +### Features + +- Volume control for remus's own playback, leaving the system volume alone. Right stick up and down changes it and clicking the right stick mutes; on a keyboard, + and - change it and m mutes. A level shows briefly after each change, the now-playing screen shows it under the times, and it is kept across restarts. + ## v0.6.5 (2026-11-04) ### Features diff --git a/Cargo.lock b/Cargo.lock index 0f6a082..b4bd28c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4385,7 +4385,7 @@ checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4" [[package]] name = "remus" -version = "0.6.5" +version = "0.6.6" dependencies = [ "anyhow", "directories", diff --git a/Cargo.toml b/Cargo.toml index aed1613..24ec859 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "remus" -version = "0.6.5" +version = "0.6.6" edition = "2024" license = "MIT" diff --git a/flatpak/me.anshorei.Fettleshed.Remus.metainfo.xml b/flatpak/me.anshorei.Fettleshed.Remus.metainfo.xml index ef63f80..8fbdfe7 100644 --- a/flatpak/me.anshorei.Fettleshed.Remus.metainfo.xml +++ b/flatpak/me.anshorei.Fettleshed.Remus.metainfo.xml @@ -20,6 +20,7 @@ + diff --git a/src/app.rs b/src/app.rs index 6bf2ecb..4ec6b81 100644 --- a/src/app.rs +++ b/src/app.rs @@ -65,6 +65,12 @@ pub fn shutdown() { let app = APP.with(|cell| cell.borrow_mut().take()); if let Some(mut app) = app { app.save_queue(); + // A volume change made just before quitting is still waiting to save. + if app.volume_save_timer.running() + && let Err(e) = config::save_settings(&app.settings) + { + log::warn!("saving settings: {e:#}"); + } if let Some(i) = app.inhibitor.take() { i.shutdown(); } @@ -247,6 +253,10 @@ pub struct App { last_save: Instant, login_focus: i32, toast_timer: Timer, + /// Hides the volume overlay a moment after the last change. + volume_timer: Timer, + /// Saves the volume once a run of changes is over. + volume_save_timer: Timer, /// Keyboard keys or the buttons of the controller used last. prompts: Prompts, /// Decoded hint icons, so a selection move does not parse SVG again. @@ -323,6 +333,8 @@ impl App { last_save: Instant::now(), login_focus: 0, toast_timer: Timer::default(), + volume_timer: Timer::default(), + volume_save_timer: Timer::default(), art_shown: None, flip_timer: Timer::default(), prompts: Prompts::Keyboard, @@ -352,6 +364,7 @@ impl App { self.toast(format!("Playback unavailable: {e:#}")); } } + self.apply_volume(); match config::load() { Ok(Some(cfg)) => { @@ -509,6 +522,16 @@ impl App { w.set_fullscreen(!w.is_fullscreen()); return; } + // Everywhere, the login screen included. + Action::VolumeUp | Action::VolumeDown => { + self.change_volume(a == Action::VolumeUp); + return; + } + Action::ToggleMute => { + self.settings.muted = !self.settings.muted; + self.volume_changed(); + return; + } _ => {} } match self.screen { @@ -935,6 +958,53 @@ impl App { self.ui.set_np_backdrop_right(right); } + // ---------------------------------------------------------------- volume + + fn change_volume(&mut self, up: bool) { + let v = step_volume(self.settings.volume, up); + // Any change unmutes, as on a phone: turning it up while muted should + // be heard. + let unmute = self.settings.muted; + if v == self.settings.volume && !unmute { + self.show_volume(); + return; + } + self.settings.volume = v; + self.settings.muted = false; + self.volume_changed(); + } + + fn volume_changed(&mut self) { + self.apply_volume(); + self.show_volume(); + // Saved once the changes stop, not for every step of a held stick. + self.volume_save_timer + .start(slint::TimerMode::SingleShot, Duration::from_millis(800), || { + with_app(|app| { + if let Err(e) = config::save_settings(&app.settings) { + app.toast(format!("Could not save settings: {e:#}")); + } + }) + }); + } + + fn apply_volume(&self) { + if let Some(p) = &self.player { + p.set_volume(self.settings.volume); + p.set_muted(self.settings.muted); + } + self.ui.set_volume(self.settings.volume as i32); + self.ui.set_muted(self.settings.muted); + } + + fn show_volume(&mut self) { + self.ui.set_volume_shown(true); + self.volume_timer + .start(slint::TimerMode::SingleShot, Duration::from_millis(1500), || { + with_app(|app| app.ui.set_volume_shown(false)) + }); + } + // ---------------------------------------------------------------- theme /// The palette the UI should show: from the playing track's cover when @@ -1428,6 +1498,8 @@ impl App { h(Control::PlayPause, "Play / Pause"); h(Control::Skip, "Skip"); h(Control::Seek, "Seek"); + h(Control::Volume, "Volume"); + h(Control::Mute, "Mute"); } } self.ui.set_hints(ModelRc::new(VecModel::from(hints))); @@ -2181,6 +2253,12 @@ fn settings_data(s: &Settings) -> PageData { } } +/// One step of the volume, kept within 0 to 100. +fn step_volume(v: u8, up: bool) -> u8 { + let v = v.min(100); + if up { (v + 5).min(100) } else { v.saturating_sub(5) } +} + /// One step of the cover backdrop setting, kept within 0 to 100. fn step_backdrop(v: u8, up: bool) -> u8 { let v = v.min(100); @@ -2396,6 +2474,17 @@ mod tests { assert_ne!(a, c); } + #[test] + fn volume_steps_stay_in_range() { + assert_eq!(step_volume(50, true), 55); + assert_eq!(step_volume(50, false), 45); + assert_eq!(step_volume(100, true), 100); + assert_eq!(step_volume(98, true), 100); + assert_eq!(step_volume(0, false), 0); + assert_eq!(step_volume(3, false), 0); + assert_eq!(step_volume(200, false), 95); + } + #[test] fn default_backdrop_looks_like_before_it_was_a_setting() { assert_eq!(backdrop_look(config::COVER_BACKDROP_DEFAULT), (0.16, 0.67, 0.95)); diff --git a/src/config.rs b/src/config.rs index 07a6c2a..feb2f31 100644 --- a/src/config.rs +++ b/src/config.rs @@ -95,6 +95,10 @@ pub struct Settings { pub album_art_colours: bool, /// How strongly the cover shows behind the now-playing screen, 0 to 100. pub cover_backdrop: u8, + /// Playback volume, 0 to 100. Only remus's own stream, not the system's. + pub volume: u8, + /// Muted, keeping `volume` for when it is unmuted. + pub muted: bool, } /// The cover backdrop strength that looks like it did before it was a setting. @@ -105,6 +109,8 @@ impl Default for Settings { Settings { album_art_colours: false, cover_backdrop: COVER_BACKDROP_DEFAULT, + volume: 100, + muted: false, } } } @@ -208,6 +214,8 @@ mod tests { assert_eq!(s, Settings::default()); assert!(!s.album_art_colours); assert_eq!(s.cover_backdrop, COVER_BACKDROP_DEFAULT); + assert_eq!(s.volume, 100); + assert!(!s.muted); } #[test] @@ -222,6 +230,8 @@ mod tests { let s = Settings { album_art_colours: true, cover_backdrop: 70, + volume: 35, + muted: true, }; let back: Settings = toml::from_str(&toml::to_string(&s).unwrap()).unwrap(); assert_eq!(back, s); diff --git a/src/devscript.rs b/src/devscript.rs index 4f1aeca..8008748 100644 --- a/src/devscript.rs +++ b/src/devscript.rs @@ -91,6 +91,9 @@ fn step(ui: slint::Weak, steps: Vec, i: usize) { "now-playing" => Action::NowPlaying, "search" => Action::Search, "quit" => Action::Quit, + "volume-up" => Action::VolumeUp, + "volume-down" => Action::VolumeDown, + "mute" => Action::ToggleMute, other => { log::warn!("unknown dev script step {other}"); Action::None diff --git a/src/input.rs b/src/input.rs index 0c6acc9..efa11ee 100644 --- a/src/input.rs +++ b/src/input.rs @@ -93,7 +93,7 @@ pub fn spawn_gamepad(emit: impl Fn(PadEvent) + Send + 'static) { EventType::AxisChanged(axis, value, _) => { let source = match axis { Axis::LeftStickX | Axis::LeftStickY => Source::LeftStick, - Axis::RightStickX => Source::RightStick, + Axis::RightStickX | Axis::RightStickY => Source::RightStick, _ => continue, }; let pad = gilrs.gamepad(ev.id); @@ -226,6 +226,7 @@ fn button_action(b: Button) -> Option { Button::RightTrigger2 => Action::SectionNext, Button::Start => Action::NowPlaying, Button::Select => Action::Search, + Button::RightThumb => Action::ToggleMute, _ => return None, }) } @@ -247,12 +248,17 @@ fn stick_direction(source: Source, pad: &gilrs::Gamepad<'_>, _changed: f32, held Some(if y > 0.0 { Action::Up } else { Action::Down }) } } + // Across seeks, up and down set the volume. The dominant axis wins, so + // a diagonal push does only one of them. Source::RightStick => { let x = pad.value(Axis::RightStickX); - if x.abs() < threshold { + let y = pad.value(Axis::RightStickY); + if x.abs() < threshold && y.abs() < threshold { None - } else { + } else if x.abs() > y.abs() { Some(if x > 0.0 { Action::SeekForward } else { Action::SeekBack }) + } else { + Some(if y > 0.0 { Action::VolumeUp } else { Action::VolumeDown }) } } Source::DPad => None, diff --git a/src/player.rs b/src/player.rs index d70afeb..6308492 100644 --- a/src/player.rs +++ b/src/player.rs @@ -177,6 +177,17 @@ impl Player { } } + /// Sets remus's own playback volume, 0 to 100. Cubic, so equal steps + /// sound equally loud apart. + pub fn set_volume(&self, level: u8) { + let v = level.min(100) as f64 / 100.0; + self.playbin.set_property("volume", v * v * v); + } + + pub fn set_muted(&self, muted: bool) { + self.playbin.set_property("mute", muted); + } + pub fn seek(&self, seconds: f64) { let Some(pos) = self.playbin.query_position::() else { return; diff --git a/src/prompts.rs b/src/prompts.rs index f374b03..9672378 100644 --- a/src/prompts.rs +++ b/src/prompts.rs @@ -33,6 +33,8 @@ pub enum Control { Search, NowPlaying, Seek, + Volume, + Mute, /// Steam + X brings up Steam's on-screen keyboard. Nothing to show for a /// real keyboard. OnScreenKeyboard, @@ -40,7 +42,7 @@ pub enum Control { #[cfg(test)] impl Control { - pub const ALL: [Control; 10] = [ + pub const ALL: [Control; 12] = [ Control::Activate, Control::Back, Control::PlayPause, @@ -50,6 +52,8 @@ impl Control { Control::Search, Control::NowPlaying, Control::Seek, + Control::Volume, + Control::Mute, Control::OnScreenKeyboard, ]; } @@ -75,6 +79,8 @@ pub fn icons(prompts: Prompts, control: Control) -> &'static [&'static [u8]] { Search => &[icon!("keyboard", "keyboard_slash_forward")], NowPlaying => &[icon!("keyboard", "keyboard_f")], Seek => &[icon!("keyboard", "keyboard_arrows_horizontal")], + Volume => &[icon!("keyboard", "keyboard_minus"), icon!("keyboard", "keyboard_plus")], + Mute => &[icon!("keyboard", "keyboard_m")], OnScreenKeyboard => &[], }, Prompts::Pad(Family::Xbox) => match control { @@ -87,6 +93,8 @@ pub fn icons(prompts: Prompts, control: Control) -> &'static [&'static [u8]] { Search => &[icon!("xbox", "xbox_button_view")], NowPlaying => &[icon!("xbox", "xbox_button_menu")], Seek => &[icon!("xbox", "xbox_dpad_horizontal")], + Volume => &[icon!("xbox", "xbox_stick_r_vertical")], + Mute => &[icon!("xbox", "xbox_stick_r_press")], OnScreenKeyboard => &[icon!("xbox", "xbox_guide"), icon!("xbox", "xbox_button_color_x")], }, Prompts::Pad(Family::PlayStation) => match control { @@ -105,6 +113,8 @@ pub fn icons(prompts: Prompts, control: Control) -> &'static [&'static [u8]] { Search => &[icon!("playstation", "playstation5_button_create")], NowPlaying => &[icon!("playstation", "playstation5_button_options")], Seek => &[icon!("playstation", "playstation_dpad_horizontal")], + Volume => &[icon!("playstation", "playstation_stick_r_vertical")], + Mute => &[icon!("playstation", "playstation_stick_r_press")], // The pack has no PS button; Steam's own label says the same thing. OnScreenKeyboard => &[ icon!("steamdeck", "steamdeck_button_guide"), @@ -122,6 +132,8 @@ pub fn icons(prompts: Prompts, control: Control) -> &'static [&'static [u8]] { Search => &[icon!("switch", "switch_button_minus")], NowPlaying => &[icon!("switch", "switch_button_plus")], Seek => &[icon!("switch", "switch_dpad_horizontal")], + Volume => &[icon!("switch", "switch_stick_r_vertical")], + Mute => &[icon!("switch", "switch_stick_r_press")], OnScreenKeyboard => &[ icon!("switch", "switch_button_home"), icon!("switch", "switch_button_y"), @@ -143,6 +155,8 @@ pub fn icons(prompts: Prompts, control: Control) -> &'static [&'static [u8]] { Search => &[icon!("steamdeck", "steamdeck_button_view")], NowPlaying => &[icon!("steamdeck", "steamdeck_button_options")], Seek => &[icon!("steamdeck", "steamdeck_dpad_horizontal")], + Volume => &[icon!("steamdeck", "steamdeck_stick_r_vertical")], + Mute => &[icon!("steamdeck", "steamdeck_stick_r_press")], OnScreenKeyboard => &[ icon!("steamdeck", "steamdeck_button_guide"), icon!("steamdeck", "steamdeck_button_x"), diff --git a/ui/app.slint b/ui/app.slint index d991d7d..945a57f 100644 --- a/ui/app.slint +++ b/ui/app.slint @@ -9,6 +9,7 @@ export enum Action { none, up, down, left, right, page-up, page-down, activate, back, play-pause, next, prev, queue, section-next, section-prev, now-playing, search, seek-forward, seek-back, toggle-fullscreen, quit, + volume-up, volume-down, toggle-mute, } export enum Screen { login, browse, now-playing } @@ -537,6 +538,90 @@ component PlayState { } } +// A speaker with sound waves, or with a cross when muted. +component Speaker { + in property muted; + in property tint: Theme.text; + in property size: 16px * Theme.s; + width: root.size; + height: root.size; + + Path { + width: root.size; + height: root.size; + viewbox-width: 16; + viewbox-height: 16; + commands: "M 1 5.5 L 4.5 5.5 L 8.5 2 L 8.5 14 L 4.5 10.5 L 1 10.5 Z"; + fill: root.tint; + } + Path { + width: root.size; + height: root.size; + viewbox-width: 16; + viewbox-height: 16; + commands: root.muted + ? "M 10.5 5.5 L 15 10 M 15 5.5 L 10.5 10" + : "M 10.5 5.5 A 3.2 3.2 0 0 1 10.5 10.5 M 12.5 3.5 A 6 6 0 0 1 12.5 12.5"; + stroke: root.tint; + stroke-width: 1.6px * root.size / 16px; + } +} + +// The level after a volume change, faded out again by the app after a moment. +component VolumeOverlay inherits Rectangle { + in property shown; + in property level; + in property muted; + + width: 300px * Theme.s; + height: 56px * Theme.s; + border-radius: 28px * Theme.s; + background: Theme.raised; + border-width: 1px * Theme.s; + border-color: Theme.line; + drop-shadow-blur: 20px * Theme.s; + drop-shadow-color: #00000080; + opacity: root.shown ? 1 : 0; + animate opacity { duration: 180ms; } + + HorizontalLayout { + padding-left: 22px * Theme.s; + padding-right: 22px * Theme.s; + spacing: 14px * Theme.s; + VerticalLayout { + alignment: center; + Speaker { + muted: root.muted || root.level == 0; + size: 22px * Theme.s; + } + } + VerticalLayout { + alignment: center; + horizontal-stretch: 1; + Rectangle { + height: 6px * Theme.s; + border-radius: 3px * Theme.s; + background: Theme.line; + Rectangle { + x: 0; + width: parent.width * (root.muted ? 0 : root.level / 100); + border-radius: 3px * Theme.s; + background: Theme.highlight; + animate width { duration: 100ms; easing: ease-out; } + } + } + } + Text { + min-width: 48px * Theme.s; + text: root.muted ? "Muted" : root.level; + font-size: 16px * Theme.s; + color: Theme.text; + horizontal-alignment: right; + vertical-alignment: center; + } + } +} + component NowBar inherits Rectangle { in property has-track; in property title; @@ -823,6 +908,8 @@ component NowPlayingView inherits Rectangle { in property has-track; // From the cover backdrop setting: the blown-up cover's opacity and the // alpha of the background drawn over it, at the left and right edges. + in property volume: 100; + in property muted; in property backdrop-opacity: 0.16; in property backdrop-left: 0.67; in property backdrop-right: 0.95; @@ -929,6 +1016,38 @@ component NowPlayingView inherits Rectangle { color: Theme.muted; } } + HorizontalLayout { + spacing: 10px * Theme.s; + alignment: start; + VerticalLayout { + alignment: center; + Speaker { + muted: root.muted || root.volume == 0; + tint: Theme.muted; + size: 14px * Theme.s; + } + } + VerticalLayout { + alignment: center; + Rectangle { + width: 90px * Theme.s; + height: 4px * Theme.s; + border-radius: 2px * Theme.s; + background: Theme.raised; + Rectangle { + x: 0; + width: parent.width * (root.muted ? 0 : root.volume / 100); + border-radius: 2px * Theme.s; + background: Theme.muted; + } + } + } + Text { + text: root.muted ? "Muted" : root.volume; + font-size: 13px * Theme.s; + color: Theme.muted; + } + } } VerticalLayout { @@ -1041,6 +1160,10 @@ export component AppWindow inherits Window { in property <[Hint]> hints; in property toast; + // The volume overlay, shown briefly after any volume change. + in property volume-shown; + in property volume; + in property muted; in property version; public function focus-main() { @@ -1094,6 +1217,10 @@ export component AppWindow inherits Window { if (e.text == "f") { root.action(Action.now-playing); return accept; } if (e.text == ",") { root.action(Action.seek-back); return accept; } if (e.text == ".") { root.action(Action.seek-forward); return accept; } + // = is + without shift on most layouts. + if (e.text == "+" || e.text == "=") { root.action(Action.volume-up); return accept; } + if (e.text == "-") { root.action(Action.volume-down); return accept; } + if (e.text == "m") { root.action(Action.toggle-mute); return accept; } reject } @@ -1196,6 +1323,8 @@ export component AppWindow inherits Window { paused: root.np-paused; has-track: root.np-has-track; flip-out: root.np-flip-out; + volume: root.volume; + muted: root.muted; backdrop-opacity: root.np-backdrop-opacity; backdrop-left: root.np-backdrop-left; backdrop-right: root.np-backdrop-right; @@ -1223,6 +1352,14 @@ export component AppWindow inherits Window { color: Theme.text; } } + + VolumeOverlay { + x: (parent.width - self.width) / 2; + y: parent.height - self.height - 32px * Theme.s; + shown: root.volume-shown; + level: root.volume; + muted: root.muted; + } } if root.screen == Screen.browse: NowBar { diff --git a/ui/prompts/keyboard/keyboard_m.svg b/ui/prompts/keyboard/keyboard_m.svg new file mode 100644 index 0000000..b9d4dde --- /dev/null +++ b/ui/prompts/keyboard/keyboard_m.svg @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ui/prompts/keyboard/keyboard_minus.svg b/ui/prompts/keyboard/keyboard_minus.svg new file mode 100644 index 0000000..92e5c34 --- /dev/null +++ b/ui/prompts/keyboard/keyboard_minus.svg @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ui/prompts/keyboard/keyboard_plus.svg b/ui/prompts/keyboard/keyboard_plus.svg new file mode 100644 index 0000000..5dbba82 --- /dev/null +++ b/ui/prompts/keyboard/keyboard_plus.svg @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ui/prompts/playstation/playstation_stick_r_press.svg b/ui/prompts/playstation/playstation_stick_r_press.svg new file mode 100644 index 0000000..11162d5 --- /dev/null +++ b/ui/prompts/playstation/playstation_stick_r_press.svg @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ui/prompts/playstation/playstation_stick_r_vertical.svg b/ui/prompts/playstation/playstation_stick_r_vertical.svg new file mode 100644 index 0000000..bd73c3f --- /dev/null +++ b/ui/prompts/playstation/playstation_stick_r_vertical.svg @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ui/prompts/steamdeck/steamdeck_stick_r_press.svg b/ui/prompts/steamdeck/steamdeck_stick_r_press.svg new file mode 100644 index 0000000..11162d5 --- /dev/null +++ b/ui/prompts/steamdeck/steamdeck_stick_r_press.svg @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ui/prompts/steamdeck/steamdeck_stick_r_vertical.svg b/ui/prompts/steamdeck/steamdeck_stick_r_vertical.svg new file mode 100644 index 0000000..bd73c3f --- /dev/null +++ b/ui/prompts/steamdeck/steamdeck_stick_r_vertical.svg @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ui/prompts/switch/switch_stick_r_press.svg b/ui/prompts/switch/switch_stick_r_press.svg new file mode 100644 index 0000000..11162d5 --- /dev/null +++ b/ui/prompts/switch/switch_stick_r_press.svg @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ui/prompts/switch/switch_stick_r_vertical.svg b/ui/prompts/switch/switch_stick_r_vertical.svg new file mode 100644 index 0000000..bd73c3f --- /dev/null +++ b/ui/prompts/switch/switch_stick_r_vertical.svg @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ui/prompts/xbox/xbox_stick_r_press.svg b/ui/prompts/xbox/xbox_stick_r_press.svg new file mode 100644 index 0000000..11162d5 --- /dev/null +++ b/ui/prompts/xbox/xbox_stick_r_press.svg @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ui/prompts/xbox/xbox_stick_r_vertical.svg b/ui/prompts/xbox/xbox_stick_r_vertical.svg new file mode 100644 index 0000000..bd73c3f --- /dev/null +++ b/ui/prompts/xbox/xbox_stick_r_vertical.svg @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file