opacity windowrule support 2 values

This commit is contained in:
vaxerski 2022-05-31 17:35:50 +02:00
parent e73df80782
commit 8de7cc5a8d
3 changed files with 14 additions and 2 deletions

View File

@ -9,6 +9,7 @@
struct SWindowSpecialRenderData {
float alpha = 1.f;
float alphaInactive = -1.f; // -1 means unset
};
struct SWindowAdditionalConfigData {

View File

@ -114,7 +114,15 @@ void Events::listener_mapWindow(void* owner, void* data) {
}
} else if (r.szRule.find("opacity") == 0) {
try {
PWINDOW->m_sSpecialRenderData.alpha = std::stof(r.szRule.substr(r.szRule.find_first_of(' ') + 1));
std::string alphaPart = r.szRule.substr(r.szRule.find_first_of(' ') + 1);
if (alphaPart.find_first_of(' ') != std::string::npos) {
// we have a comma, 2 values
PWINDOW->m_sSpecialRenderData.alpha = std::stof(alphaPart.substr(0, alphaPart.find_first_of(' ')));
PWINDOW->m_sSpecialRenderData.alphaInactive = std::stof(alphaPart.substr(alphaPart.find_first_of(' ') + 1));
} else {
PWINDOW->m_sSpecialRenderData.alpha = std::stof(alphaPart);
}
} catch(std::exception& e) {
Debug::log(ERR, "Opacity rule \"%s\" failed with: %s", r.szRule.c_str(), e.what());
}

View File

@ -130,7 +130,10 @@ void CHyprRenderer::renderWindow(CWindow* pWindow, SMonitor* pMonitor, timespec*
renderdata.rounding = pWindow->m_sAdditionalConfigData.rounding;
// apply window special data
renderdata.alpha *= pWindow->m_sSpecialRenderData.alpha;
if (pWindow->m_sSpecialRenderData.alphaInactive == -1)
renderdata.alpha *= pWindow->m_sSpecialRenderData.alpha;
else
renderdata.alpha *= pWindow == g_pCompositor->m_pLastWindow ? pWindow->m_sSpecialRenderData.alpha : pWindow->m_sSpecialRenderData.alphaInactive;
g_pHyprOpenGL->m_pCurrentWindow = pWindow;