mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-26 14:45:59 +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) {
|
||||||
|
|
|
@ -8,16 +8,27 @@ 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"); }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -48,8 +48,9 @@ struct SLayerSurface {
|
||||||
bool noProcess = false;
|
bool noProcess = false;
|
||||||
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
|
||||||
|
@ -1030,7 +1034,7 @@ void CHyprOpenGLImpl::renderTextureWithBlur(const CTexture& tex, wlr_box* pBox,
|
||||||
static auto* const PBLURIGNOREOPACITY = &g_pConfigManager->getConfigValuePtr("decoration:blur_ignore_opacity")->intValue;
|
static auto* const PBLURIGNOREOPACITY = &g_pConfigManager->getConfigValuePtr("decoration:blur_ignore_opacity")->intValue;
|
||||||
m_bEndFrame = true; // fix transformed
|
m_bEndFrame = true; // fix transformed
|
||||||
const auto SAVEDRENDERMODIF = m_RenderData.renderModif;
|
const auto SAVEDRENDERMODIF = m_RenderData.renderModif;
|
||||||
m_RenderData.renderModif = {}; // fix shit
|
m_RenderData.renderModif = {}; // fix shit
|
||||||
renderTextureInternalWithDamage(POUTFB->m_cTex, &MONITORBOX, *PBLURIGNOREOPACITY ? 1.f : a, &damage, 0, false, false, false);
|
renderTextureInternalWithDamage(POUTFB->m_cTex, &MONITORBOX, *PBLURIGNOREOPACITY ? 1.f : a, &damage, 0, false, false, false);
|
||||||
m_bEndFrame = false;
|
m_bEndFrame = false;
|
||||||
m_RenderData.renderModif = SAVEDRENDERMODIF;
|
m_RenderData.renderModif = SAVEDRENDERMODIF;
|
||||||
|
|
|
@ -24,8 +24,8 @@ inline const float fullVerts[] = {
|
||||||
inline const float fanVertsFull[] = {-1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f};
|
inline const float fanVertsFull[] = {-1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f};
|
||||||
|
|
||||||
enum eDiscardMode {
|
enum eDiscardMode {
|
||||||
DISCARD_OPAQUE = 1,
|
DISCARD_OPAQUE = 1,
|
||||||
DISCARD_ALPHAZERO = 1 << 1
|
DISCARD_ALPHA = 1 << 1
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SRenderModifData {
|
struct SRenderModifData {
|
||||||
|
@ -35,8 +35,8 @@ struct SRenderModifData {
|
||||||
|
|
||||||
struct SMonitorRenderData {
|
struct SMonitorRenderData {
|
||||||
CFramebuffer primaryFB;
|
CFramebuffer primaryFB;
|
||||||
CFramebuffer mirrorFB; // these are used for some effects,
|
CFramebuffer mirrorFB; // these are used for some effects,
|
||||||
CFramebuffer mirrorSwapFB; // etc
|
CFramebuffer mirrorSwapFB; // etc
|
||||||
|
|
||||||
CFramebuffer monitorMirrorFB; // used for mirroring outputs
|
CFramebuffer monitorMirrorFB; // used for mirroring outputs
|
||||||
|
|
||||||
|
@ -83,7 +83,8 @@ 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;
|
||||||
|
@ -138,9 +139,9 @@ class CHyprOpenGLImpl {
|
||||||
|
|
||||||
bool m_bReloadScreenShader = true; // at launch it can be set
|
bool m_bReloadScreenShader = true; // at launch it can be set
|
||||||
|
|
||||||
CWindow* m_pCurrentWindow = nullptr; // hack to get the current rendered window
|
CWindow* m_pCurrentWindow = nullptr; // hack to get the current rendered window
|
||||||
|
|
||||||
pixman_region32_t m_rOriginalDamageRegion; // used for storing the pre-expanded region
|
pixman_region32_t m_rOriginalDamageRegion; // used for storing the pre-expanded region
|
||||||
|
|
||||||
std::unordered_map<CWindow*, CFramebuffer> m_mWindowFramebuffers;
|
std::unordered_map<CWindow*, CFramebuffer> m_mWindowFramebuffers;
|
||||||
std::unordered_map<SLayerSurface*, CFramebuffer> m_mLayerFramebuffers;
|
std::unordered_map<SLayerSurface*, CFramebuffer> m_mLayerFramebuffers;
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -7,44 +7,45 @@ class CShader {
|
||||||
public:
|
public:
|
||||||
~CShader();
|
~CShader();
|
||||||
|
|
||||||
GLuint program = 0;
|
GLuint program = 0;
|
||||||
GLint proj;
|
GLint proj;
|
||||||
GLint color;
|
GLint color;
|
||||||
GLint tex;
|
GLint tex;
|
||||||
GLint alpha;
|
GLint alpha;
|
||||||
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;
|
||||||
GLint fullSize;
|
GLint fullSize;
|
||||||
GLint fullSizeUntransformed;
|
GLint fullSizeUntransformed;
|
||||||
GLint radius;
|
GLint radius;
|
||||||
GLint primitiveMultisample;
|
GLint primitiveMultisample;
|
||||||
|
|
||||||
GLint thick;
|
GLint thick;
|
||||||
|
|
||||||
GLint halfpixel;
|
GLint halfpixel;
|
||||||
|
|
||||||
GLint range;
|
GLint range;
|
||||||
GLint shadowPower;
|
GLint shadowPower;
|
||||||
|
|
||||||
GLint applyTint;
|
GLint applyTint;
|
||||||
GLint tint;
|
GLint tint;
|
||||||
|
|
||||||
GLint gradient;
|
GLint gradient;
|
||||||
GLint gradientLength;
|
GLint gradientLength;
|
||||||
GLint angle;
|
GLint angle;
|
||||||
|
|
||||||
GLint time;
|
GLint time;
|
||||||
GLint distort;
|
GLint distort;
|
||||||
GLint output;
|
GLint output;
|
||||||
|
|
||||||
GLint getUniformLocation(const std::string&);
|
GLint getUniformLocation(const std::string&);
|
||||||
|
|
||||||
void destroy();
|
void destroy();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unordered_map<std::string, GLint> m_muUniforms;
|
std::unordered_map<std::string, GLint> m_muUniforms;
|
||||||
|
|
|
@ -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