fix(audio): initialize volume ceilings at startup

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) <noreply@anthropic.com>
This commit is contained in:
Lionel DARNIS 2026-07-31 09:33:16 +02:00
parent a9f15d67a2
commit 5b838a6795

View file

@ -111,6 +111,21 @@ impl Audio {
"microphone-sensitivity-high-symbolic" "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)] #[derive(Debug, PartialEq, Eq, Default)]
@ -256,13 +271,13 @@ impl cosmic::Application for Audio {
const APP_ID: &'static str = "com.system76.CosmicAppletAudio"; const APP_ID: &'static str = "com.system76.CosmicAppletAudio";
fn init(core: cosmic::app::Core, _flags: ()) -> (Self, app::Task<Message>) { fn init(core: cosmic::app::Core, _flags: ()) -> (Self, app::Task<Message>) {
( let mut app = Self {
Self { core,
core, ..Default::default()
..Default::default() };
}, app.refresh_volume_limits();
Task::none(),
) (app, Task::none())
} }
fn core(&self) -> &cosmic::app::Core { fn core(&self) -> &cosmic::app::Core {
@ -295,17 +310,7 @@ impl cosmic::Application for Audio {
let new_id = window::Id::unique(); let new_id = window::Id::unique();
self.popup.replace(new_id); self.popup.replace(new_id);
(self.max_sink_volume, self.sink_breakpoints) = if amplification_sink() { self.refresh_volume_limits();
(150, &[100][..])
} else {
(100, &[][..])
};
(self.max_source_volume, self.source_breakpoints) = if amplification_source() {
(150, &[100][..])
} else {
(100, &[][..])
};
let mut popup_settings = self.core.applet.get_popup_settings( let mut popup_settings = self.core.applet.get_popup_settings(
self.core.main_window_id().unwrap(), self.core.main_window_id().unwrap(),