From 5b838a6795a2edc60367564968660011a369787b Mon Sep 17 00:00:00 2001 From: Lionel DARNIS Date: Fri, 31 Jul 2026 09:33:16 +0200 Subject: [PATCH] fix(audio): initialize volume ceilings at startup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit max_sink_volume and max_source_volume were only computed in the TogglePopup handler, so they kept their Default value of 0 until the popup had been opened once. The scroll-to-adjust handler clamps against max_sink_volume, which meant every wheel event resolved to SetSinkVolume(0) until the user had clicked the applet icon: scrolling up did nothing and scrolling down muted the sink. Extract refresh_volume_limits() and call it from init() as well as from TogglePopup, so the popup still picks up amplification config changes made during the session. This is the actual cause of "scroll does not adjust volume until the applet is clicked once" — the wheel events were reaching the widget all along, which is why a single click made scrolling work on plain hover from then on. Co-Authored-By: Claude Opus 5 (1M context) --- cosmic-applet-audio/src/lib.rs | 41 +++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 18 deletions(-) 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(),