Added sound muting when apps are fullscreen too

Finally closes #150 and #152

Signed-off-by: Alexis Maiquez <almamu@almamu.com>
This commit is contained in:
Alexis Maiquez 2023-03-24 02:48:49 +01:00
parent 978f56cdca
commit 45761fb858
5 changed files with 57 additions and 31 deletions

View File

@ -266,12 +266,6 @@ namespace WallpaperEngine::Application
void CWallpaperApplication::show ()
{
// audio playing detector
WallpaperEngine::Audio::Detectors::CPulseAudioPlayingDetector audioDetector (this->m_context);
// initialize sdl audio driver
WallpaperEngine::Audio::Drivers::CSDLAudioDriver audioDriver (this->m_context, audioDetector);
// initialize audio context
WallpaperEngine::Audio::CAudioContext audioContext (audioDriver);
// initialize OpenGL driver
WallpaperEngine::Render::Drivers::CX11OpenGLDriver videoDriver ("wallpaperengine");
// initialize the input subsystem
@ -280,6 +274,12 @@ namespace WallpaperEngine::Application
WallpaperEngine::Render::Drivers::Output::COutput* output;
// fullscreen detector is common for the different render modes
WallpaperEngine::Render::Drivers::Detectors::CX11FullScreenDetector fullscreenDetector (videoDriver);
// audio playing detector
WallpaperEngine::Audio::Detectors::CPulseAudioPlayingDetector audioDetector (this->m_context, fullscreenDetector);
// initialize sdl audio driver
WallpaperEngine::Audio::Drivers::CSDLAudioDriver audioDriver (this->m_context, audioDetector);
// initialize audio context
WallpaperEngine::Audio::CAudioContext audioContext (audioDriver);
// initialize the requested output
switch (this->m_context.settings.render.mode)

View File

@ -2,8 +2,11 @@
namespace WallpaperEngine::Audio::Detectors
{
CAudioPlayingDetector::CAudioPlayingDetector (Application::CApplicationContext& appContext) :
m_applicationContext (appContext)
CAudioPlayingDetector::CAudioPlayingDetector (
Application::CApplicationContext& appContext,
Render::Drivers::Detectors::CFullScreenDetector& fullscreenDetector) :
m_applicationContext (appContext),
m_fullscreenDetector (fullscreenDetector)
{
}
@ -11,4 +14,9 @@ namespace WallpaperEngine::Audio::Detectors
{
return this->m_applicationContext;
}
Render::Drivers::Detectors::CFullScreenDetector& CAudioPlayingDetector::getFullscreenDetector ()
{
return this->m_fullscreenDetector;
}
}

View File

@ -1,29 +1,43 @@
#pragma once
#include "WallpaperEngine/Render/Drivers/Detectors/CFullScreenDetector.h"
#include "WallpaperEngine/Application/CApplicationContext.h"
namespace WallpaperEngine::Application
namespace WallpaperEngine
{
class CApplicationContext;
}
namespace WallpaperEngine::Audio::Detectors
{
class CAudioPlayingDetector
namespace Application
{
public:
CAudioPlayingDetector (Application::CApplicationContext& appContext);
class CApplicationContext;
}
/**
* @return If any kind of sound is currently playing on the default audio device
*/
virtual bool anythingPlaying () = 0;
/**
* @return The application context using this detector
*/
[[nodiscard]] Application::CApplicationContext& getApplicationContext ();
namespace Render::Drivers::Detectors
{
class CFullScreenDetector;
}
private:
Application::CApplicationContext& m_applicationContext;
};
namespace Audio::Detectors
{
class CAudioPlayingDetector
{
public:
CAudioPlayingDetector (Application::CApplicationContext& appContext, Render::Drivers::Detectors::CFullScreenDetector& fullscreenDetector);
/**
* @return If any kind of sound is currently playing on the default audio device
*/
virtual bool anythingPlaying () = 0;
/**
* @return The application context using this detector
*/
[[nodiscard]] Application::CApplicationContext& getApplicationContext ();
/**
* @return The fullscreen detector used
*/
[[nodiscard]] Render::Drivers::Detectors::CFullScreenDetector& getFullscreenDetector ();
private:
Application::CApplicationContext& m_applicationContext;
Render::Drivers::Detectors::CFullScreenDetector& m_fullscreenDetector;
};
}
}

View File

@ -30,8 +30,10 @@ namespace WallpaperEngine::Audio::Detectors
pa_operation_unref (op);
}
CPulseAudioPlayingDetector::CPulseAudioPlayingDetector (Application::CApplicationContext& appContext) :
CAudioPlayingDetector (appContext),
CPulseAudioPlayingDetector::CPulseAudioPlayingDetector (
Application::CApplicationContext& appContext,
Render::Drivers::Detectors::CFullScreenDetector& fullscreenDetector) :
CAudioPlayingDetector (appContext, fullscreenDetector),
m_mainloop (nullptr),
m_mainloopApi (nullptr),
m_context (nullptr),
@ -69,6 +71,8 @@ namespace WallpaperEngine::Audio::Detectors
{
if (!this->getApplicationContext ().settings.audio.automute)
return false;
if (this->getFullscreenDetector ().anythingFullscreen ())
return true;
// reset playing state
this->setIsPlaying (false);

View File

@ -10,7 +10,7 @@ namespace WallpaperEngine::Audio::Detectors
class CPulseAudioPlayingDetector : public CAudioPlayingDetector
{
public:
explicit CPulseAudioPlayingDetector (Application::CApplicationContext& appContext);
explicit CPulseAudioPlayingDetector (Application::CApplicationContext& appContext, Render::Drivers::Detectors::CFullScreenDetector&);
~CPulseAudioPlayingDetector ();
[[nodiscard]] bool anythingPlaying () override;