mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-30 03:06:00 +01:00
Allow setting alpha value for ignorezero layer rule (#2477)
* rename ignorezero to ignorealpha * allow setting ignorealpha value This commit allows setting a float value (0-1) for the ignorealpha layer rule. Does not yet have error handling; invalid ignorealpha layer rule will crash Hyprland. * add brackets i forgot to add * prevent crash with invalid ignorealpha value prevents hyprland from immediately crashing with invalid ignorealpha layer rule does not log * don't try to set ignoreAlphaValue if alpha value not specified * add catch to try, reintroduce ignorezero - added catch after try cuz i was an idiot - re-add ignorezero as an alternative to ignorealpha to not introduce a breaking change * add logging for failed ignorealpha layer rule * fix get ignorealpha's get VALUE * check npos and use empty() * rename VALUE cuz no longer const * format Shader.hpp
This commit is contained in:
parent
10fd75c833
commit
e1edfde539
8 changed files with 81 additions and 58 deletions
|
@ -863,7 +863,7 @@ bool windowRuleValid(const std::string& RULE) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool layerRuleValid(const std::string& RULE) {
|
bool layerRuleValid(const std::string& RULE) {
|
||||||
return !(RULE != "noanim" && RULE != "blur" && RULE != "ignorezero");
|
return !(RULE != "noanim" && RULE != "blur" && RULE.find("ignorealpha") != 0 && RULE.find("ignorezero") != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CConfigManager::handleWindowRule(const std::string& command, const std::string& value) {
|
void CConfigManager::handleWindowRule(const std::string& command, const std::string& value) {
|
||||||
|
|
|
@ -10,14 +10,25 @@ SLayerSurface::SLayerSurface() {
|
||||||
void SLayerSurface::applyRules() {
|
void SLayerSurface::applyRules() {
|
||||||
noAnimations = false;
|
noAnimations = false;
|
||||||
forceBlur = false;
|
forceBlur = false;
|
||||||
ignoreZero = false;
|
ignoreAlpha = false;
|
||||||
|
ignoreAlphaValue = 0.f;
|
||||||
|
|
||||||
for (auto& rule : g_pConfigManager->getMatchingRules(this)) {
|
for (auto& rule : g_pConfigManager->getMatchingRules(this)) {
|
||||||
if (rule.rule == "noanim")
|
if (rule.rule == "noanim")
|
||||||
noAnimations = true;
|
noAnimations = true;
|
||||||
else if (rule.rule == "blur")
|
else if (rule.rule == "blur")
|
||||||
forceBlur = true;
|
forceBlur = true;
|
||||||
else if (rule.rule == "ignorezero")
|
else if (rule.rule.find("ignorealpha") == 0 || rule.rule.find("ignorezero") == 0) {
|
||||||
ignoreZero = true;
|
const auto FIRST_SPACE_POS = rule.rule.find_first_of(' ');
|
||||||
|
std::string alphaValue = "";
|
||||||
|
if (FIRST_SPACE_POS != std::string::npos)
|
||||||
|
alphaValue = rule.rule.substr(FIRST_SPACE_POS + 1);
|
||||||
|
|
||||||
|
try {
|
||||||
|
ignoreAlpha = true;
|
||||||
|
if (!alphaValue.empty())
|
||||||
|
ignoreAlphaValue = std::stof(alphaValue);
|
||||||
|
} catch (...) { Debug::log(ERR, "Invalid value passed to ignoreAlpha"); }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -49,7 +49,8 @@ struct SLayerSurface {
|
||||||
bool noAnimations = false;
|
bool noAnimations = false;
|
||||||
|
|
||||||
bool forceBlur = false;
|
bool forceBlur = false;
|
||||||
bool ignoreZero = false;
|
bool ignoreAlpha = false;
|
||||||
|
float ignoreAlphaValue = 0.f;
|
||||||
|
|
||||||
// For the list lookup
|
// For the list lookup
|
||||||
bool operator==(const SLayerSurface& rhs) const {
|
bool operator==(const SLayerSurface& rhs) const {
|
||||||
|
|
|
@ -216,7 +216,8 @@ void CHyprOpenGLImpl::initShaders() {
|
||||||
m_RenderData.pCurrentMonData->m_shRGBA.texAttrib = glGetAttribLocation(prog, "texcoord");
|
m_RenderData.pCurrentMonData->m_shRGBA.texAttrib = glGetAttribLocation(prog, "texcoord");
|
||||||
m_RenderData.pCurrentMonData->m_shRGBA.posAttrib = glGetAttribLocation(prog, "pos");
|
m_RenderData.pCurrentMonData->m_shRGBA.posAttrib = glGetAttribLocation(prog, "pos");
|
||||||
m_RenderData.pCurrentMonData->m_shRGBA.discardOpaque = glGetUniformLocation(prog, "discardOpaque");
|
m_RenderData.pCurrentMonData->m_shRGBA.discardOpaque = glGetUniformLocation(prog, "discardOpaque");
|
||||||
m_RenderData.pCurrentMonData->m_shRGBA.discardAlphaZero = glGetUniformLocation(prog, "discardAlphaZero");
|
m_RenderData.pCurrentMonData->m_shRGBA.discardAlpha = glGetUniformLocation(prog, "discardAlpha");
|
||||||
|
m_RenderData.pCurrentMonData->m_shRGBA.discardAlphaValue = glGetUniformLocation(prog, "discardAlphaValue");
|
||||||
m_RenderData.pCurrentMonData->m_shRGBA.topLeft = glGetUniformLocation(prog, "topLeft");
|
m_RenderData.pCurrentMonData->m_shRGBA.topLeft = glGetUniformLocation(prog, "topLeft");
|
||||||
m_RenderData.pCurrentMonData->m_shRGBA.fullSize = glGetUniformLocation(prog, "fullSize");
|
m_RenderData.pCurrentMonData->m_shRGBA.fullSize = glGetUniformLocation(prog, "fullSize");
|
||||||
m_RenderData.pCurrentMonData->m_shRGBA.radius = glGetUniformLocation(prog, "radius");
|
m_RenderData.pCurrentMonData->m_shRGBA.radius = glGetUniformLocation(prog, "radius");
|
||||||
|
@ -249,7 +250,8 @@ void CHyprOpenGLImpl::initShaders() {
|
||||||
m_RenderData.pCurrentMonData->m_shRGBX.texAttrib = glGetAttribLocation(prog, "texcoord");
|
m_RenderData.pCurrentMonData->m_shRGBX.texAttrib = glGetAttribLocation(prog, "texcoord");
|
||||||
m_RenderData.pCurrentMonData->m_shRGBX.posAttrib = glGetAttribLocation(prog, "pos");
|
m_RenderData.pCurrentMonData->m_shRGBX.posAttrib = glGetAttribLocation(prog, "pos");
|
||||||
m_RenderData.pCurrentMonData->m_shRGBX.discardOpaque = glGetUniformLocation(prog, "discardOpaque");
|
m_RenderData.pCurrentMonData->m_shRGBX.discardOpaque = glGetUniformLocation(prog, "discardOpaque");
|
||||||
m_RenderData.pCurrentMonData->m_shRGBX.discardAlphaZero = glGetUniformLocation(prog, "discardAlphaZero");
|
m_RenderData.pCurrentMonData->m_shRGBX.discardAlpha = glGetUniformLocation(prog, "discardAlpha");
|
||||||
|
m_RenderData.pCurrentMonData->m_shRGBX.discardAlphaValue = glGetUniformLocation(prog, "discardAlphaValue");
|
||||||
m_RenderData.pCurrentMonData->m_shRGBX.topLeft = glGetUniformLocation(prog, "topLeft");
|
m_RenderData.pCurrentMonData->m_shRGBX.topLeft = glGetUniformLocation(prog, "topLeft");
|
||||||
m_RenderData.pCurrentMonData->m_shRGBX.fullSize = glGetUniformLocation(prog, "fullSize");
|
m_RenderData.pCurrentMonData->m_shRGBX.fullSize = glGetUniformLocation(prog, "fullSize");
|
||||||
m_RenderData.pCurrentMonData->m_shRGBX.radius = glGetUniformLocation(prog, "radius");
|
m_RenderData.pCurrentMonData->m_shRGBX.radius = glGetUniformLocation(prog, "radius");
|
||||||
|
@ -265,7 +267,8 @@ void CHyprOpenGLImpl::initShaders() {
|
||||||
m_RenderData.pCurrentMonData->m_shEXT.posAttrib = glGetAttribLocation(prog, "pos");
|
m_RenderData.pCurrentMonData->m_shEXT.posAttrib = glGetAttribLocation(prog, "pos");
|
||||||
m_RenderData.pCurrentMonData->m_shEXT.texAttrib = glGetAttribLocation(prog, "texcoord");
|
m_RenderData.pCurrentMonData->m_shEXT.texAttrib = glGetAttribLocation(prog, "texcoord");
|
||||||
m_RenderData.pCurrentMonData->m_shEXT.discardOpaque = glGetUniformLocation(prog, "discardOpaque");
|
m_RenderData.pCurrentMonData->m_shEXT.discardOpaque = glGetUniformLocation(prog, "discardOpaque");
|
||||||
m_RenderData.pCurrentMonData->m_shEXT.discardAlphaZero = glGetUniformLocation(prog, "discardAlphaZero");
|
m_RenderData.pCurrentMonData->m_shEXT.discardAlpha = glGetUniformLocation(prog, "discardAlpha");
|
||||||
|
m_RenderData.pCurrentMonData->m_shEXT.discardAlphaValue = glGetUniformLocation(prog, "discardAlphaValue");
|
||||||
m_RenderData.pCurrentMonData->m_shEXT.topLeft = glGetUniformLocation(prog, "topLeft");
|
m_RenderData.pCurrentMonData->m_shEXT.topLeft = glGetUniformLocation(prog, "topLeft");
|
||||||
m_RenderData.pCurrentMonData->m_shEXT.fullSize = glGetUniformLocation(prog, "fullSize");
|
m_RenderData.pCurrentMonData->m_shEXT.fullSize = glGetUniformLocation(prog, "fullSize");
|
||||||
m_RenderData.pCurrentMonData->m_shEXT.radius = glGetUniformLocation(prog, "radius");
|
m_RenderData.pCurrentMonData->m_shEXT.radius = glGetUniformLocation(prog, "radius");
|
||||||
|
@ -619,10 +622,11 @@ void CHyprOpenGLImpl::renderTextureInternalWithDamage(const CTexture& tex, wlr_b
|
||||||
|
|
||||||
if (discardActive) {
|
if (discardActive) {
|
||||||
glUniform1i(shader->discardOpaque, !!(m_RenderData.discardMode & DISCARD_OPAQUE));
|
glUniform1i(shader->discardOpaque, !!(m_RenderData.discardMode & DISCARD_OPAQUE));
|
||||||
glUniform1i(shader->discardAlphaZero, !!(m_RenderData.discardMode & DISCARD_ALPHAZERO));
|
glUniform1i(shader->discardAlpha, !!(m_RenderData.discardMode & DISCARD_ALPHA));
|
||||||
|
glUniform1f(shader->discardAlphaValue, m_RenderData.discardOpacity);
|
||||||
} else {
|
} else {
|
||||||
glUniform1i(shader->discardOpaque, 0);
|
glUniform1i(shader->discardOpaque, 0);
|
||||||
glUniform1i(shader->discardAlphaZero, 0);
|
glUniform1i(shader->discardAlpha, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1015,7 +1019,7 @@ void CHyprOpenGLImpl::renderTextureWithBlur(const CTexture& tex, wlr_box* pBox,
|
||||||
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
|
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
|
||||||
|
|
||||||
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
|
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
|
||||||
if (USENEWOPTIMIZE && !(m_RenderData.discardMode & DISCARD_ALPHAZERO))
|
if (USENEWOPTIMIZE && !(m_RenderData.discardMode & DISCARD_ALPHA))
|
||||||
renderRect(pBox, CColor(0, 0, 0, 0), round);
|
renderRect(pBox, CColor(0, 0, 0, 0), round);
|
||||||
else
|
else
|
||||||
renderTexture(tex, pBox, a, round, true, true); // discard opaque
|
renderTexture(tex, pBox, a, round, true, true); // discard opaque
|
||||||
|
|
|
@ -25,7 +25,7 @@ inline const float fanVertsFull[] = {-1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, -1.0
|
||||||
|
|
||||||
enum eDiscardMode {
|
enum eDiscardMode {
|
||||||
DISCARD_OPAQUE = 1,
|
DISCARD_OPAQUE = 1,
|
||||||
DISCARD_ALPHAZERO = 1 << 1
|
DISCARD_ALPHA = 1 << 1
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SRenderModifData {
|
struct SRenderModifData {
|
||||||
|
@ -84,6 +84,7 @@ struct SCurrentRenderData {
|
||||||
wlr_box clipBox = {};
|
wlr_box clipBox = {};
|
||||||
|
|
||||||
uint32_t discardMode = DISCARD_OPAQUE;
|
uint32_t discardMode = DISCARD_OPAQUE;
|
||||||
|
float discardOpacity = 0.f;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CGradientValueData;
|
class CGradientValueData;
|
||||||
|
|
|
@ -392,10 +392,12 @@ void CHyprRenderer::renderLayer(SLayerSurface* pLayer, CMonitor* pMonitor, times
|
||||||
renderdata.h = pLayer->geometry.height;
|
renderdata.h = pLayer->geometry.height;
|
||||||
renderdata.blockBlurOptimization = pLayer->layer == ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM || pLayer->layer == ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND;
|
renderdata.blockBlurOptimization = pLayer->layer == ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM || pLayer->layer == ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND;
|
||||||
|
|
||||||
if (pLayer->ignoreZero)
|
if (pLayer->ignoreAlpha) {
|
||||||
g_pHyprOpenGL->m_RenderData.discardMode |= DISCARD_ALPHAZERO;
|
g_pHyprOpenGL->m_RenderData.discardMode |= DISCARD_ALPHA;
|
||||||
|
g_pHyprOpenGL->m_RenderData.discardOpacity = pLayer->ignoreAlphaValue;
|
||||||
|
}
|
||||||
wlr_surface_for_each_surface(pLayer->layerSurface->surface, renderSurface, &renderdata);
|
wlr_surface_for_each_surface(pLayer->layerSurface->surface, renderSurface, &renderdata);
|
||||||
g_pHyprOpenGL->m_RenderData.discardMode &= ~DISCARD_ALPHAZERO;
|
g_pHyprOpenGL->m_RenderData.discardMode &= ~DISCARD_ALPHA;
|
||||||
|
|
||||||
renderdata.squishOversized = false; // don't squish popups
|
renderdata.squishOversized = false; // don't squish popups
|
||||||
renderdata.dontRound = true;
|
renderdata.dontRound = true;
|
||||||
|
|
|
@ -15,7 +15,8 @@ class CShader {
|
||||||
GLint posAttrib;
|
GLint posAttrib;
|
||||||
GLint texAttrib;
|
GLint texAttrib;
|
||||||
GLint discardOpaque;
|
GLint discardOpaque;
|
||||||
GLint discardAlphaZero;
|
GLint discardAlpha;
|
||||||
|
GLfloat discardAlphaValue;
|
||||||
|
|
||||||
GLint topLeft;
|
GLint topLeft;
|
||||||
GLint bottomRight;
|
GLint bottomRight;
|
||||||
|
|
|
@ -96,7 +96,8 @@ uniform vec2 fullSize;
|
||||||
uniform float radius;
|
uniform float radius;
|
||||||
|
|
||||||
uniform int discardOpaque;
|
uniform int discardOpaque;
|
||||||
uniform int discardAlphaZero;
|
uniform int discardAlpha;
|
||||||
|
uniform float discardAlphaValue;
|
||||||
|
|
||||||
uniform int applyTint;
|
uniform int applyTint;
|
||||||
uniform vec3 tint;
|
uniform vec3 tint;
|
||||||
|
@ -110,7 +111,7 @@ void main() {
|
||||||
if (discardOpaque == 1 && pixColor[3] * alpha == 1.0)
|
if (discardOpaque == 1 && pixColor[3] * alpha == 1.0)
|
||||||
discard;
|
discard;
|
||||||
|
|
||||||
if (discardAlphaZero == 1 && pixColor[3] == 0.0)
|
if (discardAlpha == 1 && pixColor[3] <= discardAlphaValue)
|
||||||
discard;
|
discard;
|
||||||
|
|
||||||
if (applyTint == 1) {
|
if (applyTint == 1) {
|
||||||
|
@ -145,7 +146,8 @@ uniform vec2 fullSize;
|
||||||
uniform float radius;
|
uniform float radius;
|
||||||
|
|
||||||
uniform int discardOpaque;
|
uniform int discardOpaque;
|
||||||
uniform int discardAlphaZero;
|
uniform int discardAlpha;
|
||||||
|
uniform int discardAlphaValue;
|
||||||
|
|
||||||
uniform int applyTint;
|
uniform int applyTint;
|
||||||
uniform vec3 tint;
|
uniform vec3 tint;
|
||||||
|
@ -232,7 +234,8 @@ uniform vec2 fullSize;
|
||||||
uniform float radius;
|
uniform float radius;
|
||||||
|
|
||||||
uniform int discardOpaque;
|
uniform int discardOpaque;
|
||||||
uniform int discardAlphaZero;
|
uniform int discardAlpha;
|
||||||
|
uniform int discardAlphaValue;
|
||||||
|
|
||||||
uniform int applyTint;
|
uniform int applyTint;
|
||||||
uniform vec3 tint;
|
uniform vec3 tint;
|
||||||
|
|
Loading…
Reference in a new issue