From fd302b697577b5ec7de2c24ebca4d6d461c1eff6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Capucho?= Date: Sun, 18 Apr 2021 19:30:22 +0100 Subject: [PATCH] Voxygen: Add inactive window volume --- voxygen/src/run.rs | 9 +++++++++ voxygen/src/settings/audio.rs | 2 ++ 2 files changed, 11 insertions(+) diff --git a/voxygen/src/run.rs b/voxygen/src/run.rs index f7647fd5c6..774d7bf65d 100644 --- a/voxygen/src/run.rs +++ b/voxygen/src/run.rs @@ -61,6 +61,15 @@ pub fn run(mut global_state: GlobalState, event_loop: EventLoop) { }, winit::event::Event::WindowEvent { event, .. } => { span!(_guard, "Handle WindowEvent"); + + if let winit::event::WindowEvent::Focused(focused) = event { + global_state.audio.set_master_volume(if focused { + global_state.settings.audio.master_volume + } else { + global_state.settings.audio.inactive_master_volume + }); + } + global_state .window .handle_window_event(event, &mut global_state.settings) diff --git a/voxygen/src/settings/audio.rs b/voxygen/src/settings/audio.rs index f48d445d3e..70e5bc125b 100644 --- a/voxygen/src/settings/audio.rs +++ b/voxygen/src/settings/audio.rs @@ -21,6 +21,7 @@ impl AudioOutput { #[serde(default)] pub struct AudioSettings { pub master_volume: f32, + pub inactive_master_volume: f32, pub music_volume: f32, pub sfx_volume: f32, pub max_sfx_channels: usize, @@ -33,6 +34,7 @@ impl Default for AudioSettings { fn default() -> Self { Self { master_volume: 1.0, + inactive_master_volume: 0.5, music_volume: 0.4, sfx_volume: 0.6, max_sfx_channels: 30,