diff --git a/cosmic-applet-audio/src/lib.rs b/cosmic-applet-audio/src/lib.rs index bd62dfbd..7647100d 100644 --- a/cosmic-applet-audio/src/lib.rs +++ b/cosmic-applet-audio/src/lib.rs @@ -111,6 +111,21 @@ impl Audio { "microphone-sensitivity-high-symbolic" } } + + /// Refresh the volume ceilings and slider breakpoints from the + /// amplification config. + /// + /// Must run at startup, not only when the popup opens: the + /// scroll-to-adjust handler clamps against `max_sink_volume`, which + /// `Default` leaves at 0. Until the popup had been opened once, every + /// wheel event therefore resolved to `SetSinkVolume(0)`. + fn refresh_volume_limits(&mut self) { + (self.max_sink_volume, self.sink_breakpoints) = + if amplification_sink() { (150, &[100][..]) } else { (100, &[][..]) }; + + (self.max_source_volume, self.source_breakpoints) = + if amplification_source() { (150, &[100][..]) } else { (100, &[][..]) }; + } } #[derive(Debug, PartialEq, Eq, Default)] @@ -256,13 +271,13 @@ impl cosmic::Application for Audio { const APP_ID: &'static str = "com.system76.CosmicAppletAudio"; fn init(core: cosmic::app::Core, _flags: ()) -> (Self, app::Task) { - ( - Self { - core, - ..Default::default() - }, - Task::none(), - ) + let mut app = Self { + core, + ..Default::default() + }; + app.refresh_volume_limits(); + + (app, Task::none()) } fn core(&self) -> &cosmic::app::Core { @@ -295,17 +310,7 @@ impl cosmic::Application for Audio { let new_id = window::Id::unique(); self.popup.replace(new_id); - (self.max_sink_volume, self.sink_breakpoints) = if amplification_sink() { - (150, &[100][..]) - } else { - (100, &[][..]) - }; - - (self.max_source_volume, self.source_breakpoints) = if amplification_source() { - (150, &[100][..]) - } else { - (100, &[][..]) - }; + self.refresh_volume_limits(); let mut popup_settings = self.core.applet.get_popup_settings( self.core.main_window_id().unwrap(),