Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reload backgrounds and not just images #583

Merged
merged 6 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
widgets: Reload background and fade
  • Loading branch information
robin-carlier committed Dec 16, 2024
commit e8b7c580afdb4d3954a255dbe23a0b12b2634fd6
6 changes: 6 additions & 0 deletions src/config/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ void CConfigManager::init() {
m_config.addSpecialConfigValue("background", "vibrancy", Hyprlang::FLOAT{0.1686});
m_config.addSpecialConfigValue("background", "vibrancy_darkness", Hyprlang::FLOAT{0.05});
m_config.addSpecialConfigValue("background", "zindex", Hyprlang::INT{-1});
m_config.addSpecialConfigValue("background", "reload_time", Hyprlang::INT{-1});
m_config.addSpecialConfigValue("background", "reload_cmd", Hyprlang::STRING{""});
m_config.addSpecialConfigValue("background", "crossfade_time", Hyprlang::FLOAT{-1.0});

m_config.addSpecialCategory("shape", Hyprlang::SSpecialCategoryOptions{.key = nullptr, .anonymousKeyBased = true});
m_config.addSpecialConfigValue("shape", "monitor", Hyprlang::STRING{""});
Expand Down Expand Up @@ -316,6 +319,9 @@ std::vector<CConfigManager::SWidgetConfig> CConfigManager::getWidgetConfigs() {
{"brightness", m_config.getSpecialConfigValue("background", "brightness", k.c_str())},
{"vibrancy_darkness", m_config.getSpecialConfigValue("background", "vibrancy_darkness", k.c_str())},
{"zindex", m_config.getSpecialConfigValue("background", "zindex", k.c_str())},
{"reload_time", m_config.getSpecialConfigValue("background", "reload_time", k.c_str())},
{"reload_cmd", m_config.getSpecialConfigValue("background", "reload_cmd", k.c_str())},
{"crossfade_time", m_config.getSpecialConfigValue("background", "crossfade_time", k.c_str())},
}
});
// clang-format on
Expand Down
69 changes: 68 additions & 1 deletion src/renderer/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,27 @@ CRenderer::CRenderer() {
texShader.tint = glGetUniformLocation(prog, "tint");
texShader.useAlphaMatte = glGetUniformLocation(prog, "useAlphaMatte");

prog = createProgram(TEXVERTSRC, TEXMIXFRAGSRCRGBA);
texMixShader.program = prog;
texMixShader.proj = glGetUniformLocation(prog, "proj");
texMixShader.tex = glGetUniformLocation(prog, "tex1");
texMixShader.tex2 = glGetUniformLocation(prog, "tex2");
texMixShader.alphaMatte = glGetUniformLocation(prog, "texMatte");
texMixShader.alpha = glGetUniformLocation(prog, "alpha");
texMixShader.mixFactor = glGetUniformLocation(prog, "mixFactor");
texMixShader.texAttrib = glGetAttribLocation(prog, "texcoord");
texMixShader.matteTexAttrib = glGetAttribLocation(prog, "texcoordMatte");
texMixShader.posAttrib = glGetAttribLocation(prog, "pos");
texMixShader.discardOpaque = glGetUniformLocation(prog, "discardOpaque");
texMixShader.discardAlpha = glGetUniformLocation(prog, "discardAlpha");
texMixShader.discardAlphaValue = glGetUniformLocation(prog, "discardAlphaValue");
texMixShader.topLeft = glGetUniformLocation(prog, "topLeft");
texMixShader.fullSize = glGetUniformLocation(prog, "fullSize");
texMixShader.radius = glGetUniformLocation(prog, "radius");
texMixShader.applyTint = glGetUniformLocation(prog, "applyTint");
texMixShader.tint = glGetUniformLocation(prog, "tint");
texMixShader.useAlphaMatte = glGetUniformLocation(prog, "useAlphaMatte");

prog = createProgram(TEXVERTSRC, FRAGBLUR1);
blurShader1.program = prog;
blurShader1.tex = glGetUniformLocation(prog, "tex");
Expand Down Expand Up @@ -347,6 +368,52 @@ void CRenderer::renderTexture(const CBox& box, const CTexture& tex, float a, int
glBindTexture(tex.m_iTarget, 0);
}

void CRenderer::renderTextureMix(const CBox& box, const CTexture& tex, const CTexture& tex2, float a, float mixFactor, int rounding, std::optional<eTransform> tr) {
const auto ROUNDEDBOX = box.copy().round();
Mat3x3 matrix = projMatrix.projectBox(ROUNDEDBOX, tr.value_or(HYPRUTILS_TRANSFORM_FLIPPED_180), box.rot);
Mat3x3 glMatrix = projection.copy().multiply(matrix);

CShader* shader = &texMixShader;

glActiveTexture(GL_TEXTURE0);
glBindTexture(tex.m_iTarget, tex.m_iTexID);

glActiveTexture(GL_TEXTURE1);
glBindTexture(tex2.m_iTarget, tex2.m_iTexID);

glUseProgram(shader->program);

glUniformMatrix3fv(shader->proj, 1, GL_TRUE, glMatrix.getMatrix().data());
glUniform1i(shader->tex, 0);
glUniform1i(shader->tex2, 1);
glUniform1f(shader->alpha, a);
glUniform1f(shader->mixFactor, mixFactor);
const auto TOPLEFT = Vector2D(ROUNDEDBOX.x, ROUNDEDBOX.y);
const auto FULLSIZE = Vector2D(ROUNDEDBOX.width, ROUNDEDBOX.height);

// Rounded corners
glUniform2f(shader->topLeft, TOPLEFT.x, TOPLEFT.y);
glUniform2f(shader->fullSize, FULLSIZE.x, FULLSIZE.y);
glUniform1f(shader->radius, rounding);

glUniform1i(shader->discardOpaque, 0);
glUniform1i(shader->discardAlpha, 0);
glUniform1i(shader->applyTint, 0);

glVertexAttribPointer(shader->posAttrib, 2, GL_FLOAT, GL_FALSE, 0, fullVerts);
glVertexAttribPointer(shader->texAttrib, 2, GL_FLOAT, GL_FALSE, 0, fullVerts);

glEnableVertexAttribArray(shader->posAttrib);
glEnableVertexAttribArray(shader->texAttrib);

glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

glDisableVertexAttribArray(shader->posAttrib);
glDisableVertexAttribArray(shader->texAttrib);

glBindTexture(tex.m_iTarget, 0);
}

std::vector<std::unique_ptr<IWidget>>* CRenderer::getOrCreateWidgetsFor(const CSessionLockSurface* surf) {
if (!widgets.contains(surf)) {

Expand Down Expand Up @@ -570,4 +637,4 @@ void CRenderer::popFb() {

void CRenderer::removeWidgetsFor(const CSessionLockSurface* surf) {
widgets.erase(surf);
}
}
2 changes: 2 additions & 0 deletions src/renderer/Renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class CRenderer {
void renderRect(const CBox& box, const CColor& col, int rounding = 0);
void renderBorder(const CBox& box, const CGradientValueData& gradient, int thickness, int rounding = 0, float alpha = 1.0);
void renderTexture(const CBox& box, const CTexture& tex, float a = 1.0, int rounding = 0, std::optional<eTransform> tr = {});
void renderTextureMix(const CBox& box, const CTexture& tex, const CTexture& tex2, float a = 1.0, float mixFactor = 0.0, int rounding = 0, std::optional<eTransform> tr = {});
void blurFB(const CFramebuffer& outfb, SBlurParams params);

std::unique_ptr<CAsyncResourceGatherer> asyncResourceGatherer;
Expand All @@ -50,6 +51,7 @@ class CRenderer {

CShader rectShader;
CShader texShader;
CShader texMixShader;
CShader blurShader1;
CShader blurShader2;
CShader blurPrepareShader;
Expand Down
4 changes: 3 additions & 1 deletion src/renderer/Shader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ class CShader {
GLint color = -1;
GLint alphaMatte = -1;
GLint tex = -1;
GLint tex2 = -1;
GLint alpha = -1;
GLfloat mixFactor = -1;
GLint posAttrib = -1;
GLint texAttrib = -1;
GLint matteTexAttrib = -1;
Expand Down Expand Up @@ -70,4 +72,4 @@ class CShader {

private:
std::unordered_map<std::string, GLint> m_muUniforms;
};
};
45 changes: 44 additions & 1 deletion src/renderer/Shaders.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,49 @@ void main() {
gl_FragColor = pixColor * alpha;
})#";

inline const std::string TEXMIXFRAGSRCRGBA = R"#(
precision highp float;
varying vec2 v_texcoord; // is in 0-1
uniform sampler2D tex1;
uniform sampler2D tex2;
uniform float mixFactor;
uniform float alpha;

uniform vec2 topLeft;
uniform vec2 fullSize;
uniform float radius;

uniform int discardOpaque;
uniform int discardAlpha;
uniform float discardAlphaValue;

uniform int applyTint;
uniform vec3 tint;

void main() {

vec4 pixColor = mix(texture2D(tex1, v_texcoord), texture2D(tex2, v_texcoord), smoothstep(0.0, 1.0, mixFactor));

if (discardOpaque == 1 && pixColor[3] * alpha == 1.0)
discard;

if (discardAlpha == 1 && pixColor[3] <= discardAlphaValue)
discard;

if (applyTint == 1) {
pixColor[0] = pixColor[0] * tint[0];
pixColor[1] = pixColor[1] * tint[1];
pixColor[2] = pixColor[2] * tint[2];
}

if (radius > 0.0) {
)#" +
ROUNDED_SHADER_FUNC("pixColor") + R"#(
}

gl_FragColor = pixColor * alpha;
})#";

inline const std::string FRAGBLUR1 = R"#(
#version 100
precision highp float;
Expand Down Expand Up @@ -490,4 +533,4 @@ void main() {

gl_FragColor = pixColor;
}
)#";
)#";
Loading