mirror of
https://github.com/Almamu/linux-wallpaperengine.git
synced 2025-09-14 13:56:48 +08:00
feat: pause mpv when fullscreen
This commit is contained in:
parent
db8179a45e
commit
c659bb19c6
@ -56,7 +56,7 @@ void CWallpaperApplication::setupContainer (CCombinedContainer& container, const
|
||||
try {
|
||||
container.add (new CDirectory (this->m_context.settings.general.assets));
|
||||
} catch (CAssetLoadException&) {
|
||||
sLog.exception("Cannot find a valid assets folder, resolved to ", this->m_context.settings.general.assets);
|
||||
sLog.exception ("Cannot find a valid assets folder, resolved to ", this->m_context.settings.general.assets);
|
||||
}
|
||||
|
||||
// add two possible patches directories to the container
|
||||
@ -173,8 +173,9 @@ void CWallpaperApplication::setupContainer (CCombinedContainer& container, const
|
||||
}
|
||||
|
||||
void CWallpaperApplication::loadBackgrounds () {
|
||||
if (this->m_context.settings.render.mode == CApplicationContext::NORMAL_WINDOW || this->m_context.settings.render.mode == CApplicationContext::EXPLICIT_WINDOW) {
|
||||
this->m_backgrounds ["default"] = this->loadBackground(this->m_context.settings.general.defaultBackground);
|
||||
if (this->m_context.settings.render.mode == CApplicationContext::NORMAL_WINDOW ||
|
||||
this->m_context.settings.render.mode == CApplicationContext::EXPLICIT_WINDOW) {
|
||||
this->m_backgrounds ["default"] = this->loadBackground (this->m_context.settings.general.defaultBackground);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -244,9 +245,9 @@ void CWallpaperApplication::takeScreenshot (const std::filesystem::path& filenam
|
||||
int xfinal = x + xoffset;
|
||||
int yfinal = this->m_renderContext->getOutput ().renderVFlip () ? (viewport->viewport.w - y) : y;
|
||||
|
||||
bitmap[yfinal * width * 3 + xfinal * 3] = *pixel++;
|
||||
bitmap[yfinal * width * 3 + xfinal * 3 + 1] = *pixel++;
|
||||
bitmap[yfinal * width * 3 + xfinal * 3 + 2] = *pixel++;
|
||||
bitmap [yfinal * width * 3 + xfinal * 3] = *pixel++;
|
||||
bitmap [yfinal * width * 3 + xfinal * 3 + 1] = *pixel++;
|
||||
bitmap [yfinal * width * 3 + xfinal * 3 + 2] = *pixel++;
|
||||
}
|
||||
}
|
||||
|
||||
@ -257,14 +258,14 @@ void CWallpaperApplication::takeScreenshot (const std::filesystem::path& filenam
|
||||
delete [] buffer;
|
||||
}
|
||||
|
||||
auto extension = filename.extension();
|
||||
auto extension = filename.extension ();
|
||||
|
||||
if (extension == ".bmp") {
|
||||
stbi_write_bmp (filename.c_str(), width, height, 3, bitmap);
|
||||
stbi_write_bmp (filename.c_str (), width, height, 3, bitmap);
|
||||
} else if (extension == ".png") {
|
||||
stbi_write_png (filename.c_str(), width, height, 3, bitmap, width * 3);
|
||||
stbi_write_png (filename.c_str (), width, height, 3, bitmap, width * 3);
|
||||
} else if (extension == ".jpg" || extension == ".jpeg") {
|
||||
stbi_write_jpg (filename.c_str(), width, height, 3, bitmap, 100);
|
||||
stbi_write_jpg (filename.c_str (), width, height, 3, bitmap, 100);
|
||||
}
|
||||
}
|
||||
|
||||
@ -276,14 +277,14 @@ void CWallpaperApplication::show () {
|
||||
"Cannot read environment variable XDG_SESSION_TYPE, window server detection failed. Please ensure proper values are set");
|
||||
}
|
||||
|
||||
sLog.debug("Checking for window servers: ");
|
||||
sLog.debug ("Checking for window servers: ");
|
||||
|
||||
#ifdef ENABLE_WAYLAND
|
||||
sLog.debug("\twayland");
|
||||
sLog.debug ("\twayland");
|
||||
#endif // ENABLE_WAYLAND
|
||||
|
||||
#ifdef ENABLE_X11
|
||||
sLog.debug("\tx11");
|
||||
sLog.debug ("\tx11");
|
||||
#endif // ENABLE_X11
|
||||
|
||||
#ifdef ENABLE_WAYLAND
|
||||
@ -349,8 +350,9 @@ void CWallpaperApplication::show () {
|
||||
new WallpaperEngine::Render::Drivers::Detectors::CFullScreenDetector (this->m_context);
|
||||
}
|
||||
|
||||
m_inputContext = new WallpaperEngine::Input::CInputContext (new WallpaperEngine::Input::Drivers::CGLFWMouseInput (
|
||||
reinterpret_cast<Render::Drivers::CGLFWOpenGLDriver*> (m_videoDriver)));
|
||||
m_inputContext =
|
||||
new WallpaperEngine::Input::CInputContext (new WallpaperEngine::Input::Drivers::CGLFWMouseInput (
|
||||
reinterpret_cast<Render::Drivers::CGLFWOpenGLDriver*> (m_videoDriver)));
|
||||
}
|
||||
|
||||
if (this->m_context.settings.audio.audioprocessing) {
|
||||
@ -374,9 +376,10 @@ void CWallpaperApplication::show () {
|
||||
|
||||
// set all the specific wallpapers required
|
||||
for (const auto& [background, info] : this->m_backgrounds) {
|
||||
m_renderContext->setWallpaper (background, WallpaperEngine::Render::CWallpaper::fromWallpaper (
|
||||
info->getWallpaper (), *m_renderContext, *m_audioContext, m_browserContext,
|
||||
this->m_context.settings.general.screenScalings [background]));
|
||||
m_renderContext->setWallpaper (background,
|
||||
WallpaperEngine::Render::CWallpaper::fromWallpaper (
|
||||
info->getWallpaper (), *m_renderContext, *m_audioContext, m_browserContext,
|
||||
this->m_context.settings.general.screenScalings [background]));
|
||||
}
|
||||
|
||||
// wallpapers are setup, free browsesr context if possible
|
||||
@ -401,6 +404,13 @@ void CWallpaperApplication::show () {
|
||||
m_audioDriver->update ();
|
||||
// update input information
|
||||
m_inputContext->update ();
|
||||
// check for fullscreen windows and wait until there's none fullscreen
|
||||
if (this->m_fullScreenDetector->anythingFullscreen () && this->m_context.state.general.keepRunning) {
|
||||
m_renderContext->setPause (true);
|
||||
while (this->m_fullScreenDetector->anythingFullscreen () && this->m_context.state.general.keepRunning)
|
||||
usleep (FULLSCREEN_CHECK_WAIT_TIME);
|
||||
m_renderContext->setPause (false);
|
||||
}
|
||||
// process driver events
|
||||
m_videoDriver->dispatchEventQueue ();
|
||||
|
||||
@ -420,10 +430,6 @@ void CWallpaperApplication::show () {
|
||||
}
|
||||
|
||||
void CWallpaperApplication::update (Render::Drivers::Output::COutputViewport* viewport) {
|
||||
// check for fullscreen windows and wait until there's none fullscreen
|
||||
while (this->m_fullScreenDetector->anythingFullscreen () && this->m_context.state.general.keepRunning)
|
||||
usleep (FULLSCREEN_CHECK_WAIT_TIME);
|
||||
|
||||
// render the scene
|
||||
m_renderContext->render (viewport);
|
||||
}
|
||||
@ -443,4 +449,4 @@ CApplicationContext& CWallpaperApplication::getContext () const {
|
||||
const WallpaperEngine::Render::Drivers::Output::COutput& CWallpaperApplication::getOutput () const {
|
||||
return this->m_renderContext->getOutput ();
|
||||
}
|
||||
} // namespace WallpaperEngine::Application
|
||||
} // namespace WallpaperEngine::Application
|
||||
|
@ -42,6 +42,11 @@ void CRenderContext::setWallpaper (const std::string& display, CWallpaper* wallp
|
||||
this->m_wallpapers.insert_or_assign (display, wallpaper);
|
||||
}
|
||||
|
||||
void CRenderContext::setPause (bool newState) {
|
||||
for (auto&& wallpaper : this->m_wallpapers)
|
||||
wallpaper.second->setPause (newState);
|
||||
}
|
||||
|
||||
Input::CInputContext& CRenderContext::getInputContext () const {
|
||||
return this->m_input;
|
||||
}
|
||||
@ -61,4 +66,4 @@ const Drivers::Output::COutput& CRenderContext::getOutput () const {
|
||||
const ITexture* CRenderContext::resolveTexture (const std::string& name) {
|
||||
return this->m_textureCache->resolve (name);
|
||||
}
|
||||
} // namespace WallpaperEngine::Render
|
||||
} // namespace WallpaperEngine::Render
|
||||
|
@ -35,6 +35,7 @@ class CRenderContext {
|
||||
|
||||
void render (Drivers::Output::COutputViewport* viewport);
|
||||
void setWallpaper (const std::string& display, CWallpaper* wallpaper);
|
||||
void setPause (bool newState);
|
||||
[[nodiscard]] Input::CInputContext& getInputContext () const;
|
||||
[[nodiscard]] const CWallpaperApplication& getApp () const;
|
||||
[[nodiscard]] const Drivers::CVideoDriver& getDriver () const;
|
||||
@ -54,4 +55,4 @@ class CRenderContext {
|
||||
CTextureCache* m_textureCache;
|
||||
};
|
||||
} // namespace Render
|
||||
} // namespace WallpaperEngine
|
||||
} // namespace WallpaperEngine
|
||||
|
@ -232,6 +232,8 @@ void CWallpaper::render (glm::ivec4 viewport, bool vflip) {
|
||||
glDrawArrays (GL_TRIANGLES, 0, 6);
|
||||
}
|
||||
|
||||
void CWallpaper::setPause (bool newState) {}
|
||||
|
||||
void CWallpaper::setupFramebuffers () {
|
||||
const uint32_t width = this->getWidth ();
|
||||
const uint32_t height = this->getHeight ();
|
||||
@ -291,4 +293,4 @@ CWallpaper* CWallpaper::fromWallpaper (Core::CWallpaper* wallpaper, CRenderConte
|
||||
scalingMode);
|
||||
else
|
||||
sLog.exception ("Unsupported wallpaper type");
|
||||
}
|
||||
}
|
||||
|
@ -50,6 +50,11 @@ class CWallpaper : public Helpers::CContextAware {
|
||||
*/
|
||||
void render (glm::ivec4 viewport, bool vflip);
|
||||
|
||||
/**
|
||||
* Pause the renderer
|
||||
*/
|
||||
virtual void setPause (bool newState);
|
||||
|
||||
/**
|
||||
* @return The container to resolve files for this wallpaper
|
||||
*/
|
||||
@ -141,7 +146,8 @@ class CWallpaper : public Helpers::CContextAware {
|
||||
* @return
|
||||
*/
|
||||
static CWallpaper* fromWallpaper (Core::CWallpaper* wallpaper, CRenderContext& context, CAudioContext& audioContext,
|
||||
CWebBrowserContext& browserContext, const CWallpaperState::TextureUVsScaling& scalingMode);
|
||||
CWebBrowserContext& browserContext,
|
||||
const CWallpaperState::TextureUVsScaling& scalingMode);
|
||||
|
||||
protected:
|
||||
CWallpaper (Core::CWallpaper* wallpaperData, std::string type, CRenderContext& context, CAudioContext& audioContext,
|
||||
|
@ -15,6 +15,7 @@ CVideo::CVideo (Core::CVideo* video, CRenderContext& context, CAudioContext& aud
|
||||
CWallpaper (video, Type, context, audioContext, scalingMode),
|
||||
m_width (16),
|
||||
m_height (16),
|
||||
m_paused (false),
|
||||
m_mpvGl (nullptr) {
|
||||
double volume = this->getContext ().getApp ().getContext ().settings.audio.volume * 100.0 / 128.0;
|
||||
|
||||
@ -40,7 +41,7 @@ CVideo::CVideo (Core::CVideo* video, CRenderContext& context, CAudioContext& aud
|
||||
mpv_set_option (this->m_mpv, "volume", MPV_FORMAT_DOUBLE, &volume);
|
||||
|
||||
if (!this->getContext ().getApp ().getContext ().settings.audio.enabled) {
|
||||
mpv_set_option_string(this->m_mpv, "mute", "yes");
|
||||
mpv_set_option_string (this->m_mpv, "mute", "yes");
|
||||
}
|
||||
|
||||
// initialize gl context for mpv
|
||||
@ -121,6 +122,14 @@ Core::CVideo* CVideo::getVideo () {
|
||||
return this->getWallpaperData ()->as<Core::CVideo> ();
|
||||
}
|
||||
|
||||
void CVideo::setPause (bool newState) {
|
||||
if (m_paused == newState)
|
||||
return;
|
||||
m_paused = newState;
|
||||
int pause = newState;
|
||||
mpv_set_property (m_mpv, "pause", MPV_FORMAT_FLAG, &pause);
|
||||
}
|
||||
|
||||
int CVideo::getWidth () const {
|
||||
return this->m_width;
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ class CVideo final : public CWallpaper {
|
||||
[[nodiscard]] int getWidth () const override;
|
||||
[[nodiscard]] int getHeight () const override;
|
||||
|
||||
void setPause (bool newState) override;
|
||||
void setSize (int width, int height);
|
||||
|
||||
protected:
|
||||
@ -31,6 +32,7 @@ class CVideo final : public CWallpaper {
|
||||
mpv_handle* m_mpv;
|
||||
mpv_render_context* m_mpvGl;
|
||||
|
||||
bool m_paused;
|
||||
int64_t m_width;
|
||||
int64_t m_height;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user