shadow: add sharp and refactor options

options moved to decoration:shadow:
This commit is contained in:
Vaxry 2024-11-05 15:44:40 +00:00
parent e3882b23d0
commit d1638a09ba
7 changed files with 58 additions and 38 deletions

View file

@ -1893,8 +1893,8 @@ void CCompositor::updateWindowAnimatedDecorationValues(PHLWINDOW pWindow) {
static auto PINACTIVEALPHA = CConfigValue<Hyprlang::FLOAT>("decoration:inactive_opacity"); static auto PINACTIVEALPHA = CConfigValue<Hyprlang::FLOAT>("decoration:inactive_opacity");
static auto PACTIVEALPHA = CConfigValue<Hyprlang::FLOAT>("decoration:active_opacity"); static auto PACTIVEALPHA = CConfigValue<Hyprlang::FLOAT>("decoration:active_opacity");
static auto PFULLSCREENALPHA = CConfigValue<Hyprlang::FLOAT>("decoration:fullscreen_opacity"); static auto PFULLSCREENALPHA = CConfigValue<Hyprlang::FLOAT>("decoration:fullscreen_opacity");
static auto PSHADOWCOL = CConfigValue<Hyprlang::INT>("decoration:col.shadow"); static auto PSHADOWCOL = CConfigValue<Hyprlang::INT>("decoration:shadow:color");
static auto PSHADOWCOLINACTIVE = CConfigValue<Hyprlang::INT>("decoration:col.shadow_inactive"); static auto PSHADOWCOLINACTIVE = CConfigValue<Hyprlang::INT>("decoration:shadow:color_inactive");
static auto PDIMSTRENGTH = CConfigValue<Hyprlang::FLOAT>("decoration:dim_strength"); static auto PDIMSTRENGTH = CConfigValue<Hyprlang::FLOAT>("decoration:dim_strength");
static auto PDIMENABLED = CConfigValue<Hyprlang::INT>("decoration:dim_inactive"); static auto PDIMENABLED = CConfigValue<Hyprlang::INT>("decoration:dim_inactive");
@ -1965,11 +1965,10 @@ void CCompositor::updateWindowAnimatedDecorationValues(PHLWINDOW pWindow) {
// shadow // shadow
if (!pWindow->isX11OverrideRedirect() && !pWindow->m_bX11DoesntWantBorders) { if (!pWindow->isX11OverrideRedirect() && !pWindow->m_bX11DoesntWantBorders) {
if (pWindow == m_pLastWindow) { if (pWindow == m_pLastWindow)
pWindow->m_cRealShadowColor = CColor(*PSHADOWCOL); pWindow->m_cRealShadowColor = CColor(*PSHADOWCOL);
} else { else
pWindow->m_cRealShadowColor = CColor(*PSHADOWCOLINACTIVE != INT_MAX ? *PSHADOWCOLINACTIVE : *PSHADOWCOL); pWindow->m_cRealShadowColor = CColor(*PSHADOWCOLINACTIVE != INT64_MAX ? *PSHADOWCOLINACTIVE : *PSHADOWCOL);
}
} else { } else {
pWindow->m_cRealShadowColor.setValueAndWarp(CColor(0, 0, 0, 0)); // no shadow pWindow->m_cRealShadowColor.setValueAndWarp(CColor(0, 0, 0, 0)); // no shadow
} }

View file

@ -158,49 +158,55 @@ inline static const std::vector<SConfigOptionDescription> CONFIG_OPTIONS = {
.data = SConfigOptionDescription::SFloatData{1, 0, 1}, .data = SConfigOptionDescription::SFloatData{1, 0, 1},
}, },
SConfigOptionDescription{ SConfigOptionDescription{
.value = "decoration:drop_shadow", .value = "decoration:shadow:enabled",
.description = "enable drop shadows on windows", .description = "enable drop shadows on windows",
.type = CONFIG_OPTION_BOOL, .type = CONFIG_OPTION_BOOL,
.data = SConfigOptionDescription::SBoolData{true}, .data = SConfigOptionDescription::SBoolData{true},
}, },
SConfigOptionDescription{ SConfigOptionDescription{
.value = "decoration:shadow_range", .value = "decoration:shadow:range",
.description = "Shadow range (size) in layout px", .description = "Shadow range (size) in layout px",
.type = CONFIG_OPTION_INT, .type = CONFIG_OPTION_INT,
.data = SConfigOptionDescription::SRangeData{4, 0, 100}, .data = SConfigOptionDescription::SRangeData{4, 0, 100},
}, },
SConfigOptionDescription{ SConfigOptionDescription{
.value = "decoration:shadow_render_power", .value = "decoration:shadow:render_power",
.description = "in what power to render the falloff (more power, the faster the falloff) [1 - 4]", .description = "in what power to render the falloff (more power, the faster the falloff) [1 - 4]",
.type = CONFIG_OPTION_INT, .type = CONFIG_OPTION_INT,
.data = SConfigOptionDescription::SRangeData{3, 1, 4}, .data = SConfigOptionDescription::SRangeData{3, 1, 4},
}, },
SConfigOptionDescription{ SConfigOptionDescription{
.value = "decoration:shadow_ignore_window", .value = "decoration:shadow:sharp",
.description = "whether the shadow should be sharp or not. Akin to an infinitely high render power.",
.type = CONFIG_OPTION_BOOL,
.data = SConfigOptionDescription::SBoolData{false},
},
SConfigOptionDescription{
.value = "decoration:shadow:ignore_window",
.description = "if true, the shadow will not be rendered behind the window itself, only around it.", .description = "if true, the shadow will not be rendered behind the window itself, only around it.",
.type = CONFIG_OPTION_BOOL, .type = CONFIG_OPTION_BOOL,
.data = SConfigOptionDescription::SBoolData{true}, .data = SConfigOptionDescription::SBoolData{true},
}, },
SConfigOptionDescription{ SConfigOptionDescription{
.value = "decoration:col.shadow", .value = "decoration:shadow:color",
.description = "shadow's color. Alpha dictates shadow's opacity.", .description = "shadow's color. Alpha dictates shadow's opacity.",
.type = CONFIG_OPTION_COLOR, .type = CONFIG_OPTION_COLOR,
.data = SConfigOptionDescription::SColorData{0xee1a1a1a}, .data = SConfigOptionDescription::SColorData{0xee1a1a1a},
}, },
SConfigOptionDescription{ SConfigOptionDescription{
.value = "decoration:col.shadow_inactive", .value = "decoration:shadow:color_inactive",
.description = "inactive shadow color. (if not set, will fall back to col.shadow)", .description = "inactive shadow color. (if not set, will fall back to col.shadow)",
.type = CONFIG_OPTION_COLOR, .type = CONFIG_OPTION_COLOR,
.data = SConfigOptionDescription::SColorData{}, //##TODO UNSET? .data = SConfigOptionDescription::SColorData{}, //TODO: UNSET?
}, },
SConfigOptionDescription{ SConfigOptionDescription{
.value = "decoration:shadow_offset", .value = "decoration:shadow:offset",
.description = "shadow's rendering offset.", .description = "shadow's rendering offset.",
.type = CONFIG_OPTION_VECTOR, .type = CONFIG_OPTION_VECTOR,
.data = SConfigOptionDescription::SVectorData{{}, {-250, -250}, {250, 250}}, .data = SConfigOptionDescription::SVectorData{{}, {-250, -250}, {250, 250}},
}, },
SConfigOptionDescription{ SConfigOptionDescription{
.value = "decoration:shadow_scale", .value = "decoration:shadow:scale",
.description = "shadow's scale. [0.0 - 1.0]", .description = "shadow's scale. [0.0 - 1.0]",
.type = CONFIG_OPTION_FLOAT, .type = CONFIG_OPTION_FLOAT,
.data = SConfigOptionDescription::SFloatData{1, 0, 1}, .data = SConfigOptionDescription::SFloatData{1, 0, 1},

View file

@ -431,14 +431,15 @@ CConfigManager::CConfigManager() {
m_pConfig->addConfigValue("decoration:inactive_opacity", {1.F}); m_pConfig->addConfigValue("decoration:inactive_opacity", {1.F});
m_pConfig->addConfigValue("decoration:fullscreen_opacity", {1.F}); m_pConfig->addConfigValue("decoration:fullscreen_opacity", {1.F});
m_pConfig->addConfigValue("decoration:no_blur_on_oversized", Hyprlang::INT{0}); m_pConfig->addConfigValue("decoration:no_blur_on_oversized", Hyprlang::INT{0});
m_pConfig->addConfigValue("decoration:drop_shadow", Hyprlang::INT{1}); m_pConfig->addConfigValue("decoration:shadow:enabled", Hyprlang::INT{1});
m_pConfig->addConfigValue("decoration:shadow_range", Hyprlang::INT{4}); m_pConfig->addConfigValue("decoration:shadow:range", Hyprlang::INT{4});
m_pConfig->addConfigValue("decoration:shadow_render_power", Hyprlang::INT{3}); m_pConfig->addConfigValue("decoration:shadow:render_power", Hyprlang::INT{3});
m_pConfig->addConfigValue("decoration:shadow_ignore_window", Hyprlang::INT{1}); m_pConfig->addConfigValue("decoration:shadow:ignore_window", Hyprlang::INT{1});
m_pConfig->addConfigValue("decoration:shadow_offset", Hyprlang::VEC2{0, 0}); m_pConfig->addConfigValue("decoration:shadow:offset", Hyprlang::VEC2{0, 0});
m_pConfig->addConfigValue("decoration:shadow_scale", {1.f}); m_pConfig->addConfigValue("decoration:shadow:scale", {1.f});
m_pConfig->addConfigValue("decoration:col.shadow", Hyprlang::INT{0xee1a1a1a}); m_pConfig->addConfigValue("decoration:shadow:sharp", Hyprlang::INT{0});
m_pConfig->addConfigValue("decoration:col.shadow_inactive", {(Hyprlang::INT)INT_MAX}); m_pConfig->addConfigValue("decoration:shadow:color", Hyprlang::INT{0xee1a1a1a});
m_pConfig->addConfigValue("decoration:shadow:color_inactive", {(Hyprlang::INT)INT64_MAX});
m_pConfig->addConfigValue("decoration:dim_inactive", Hyprlang::INT{0}); m_pConfig->addConfigValue("decoration:dim_inactive", Hyprlang::INT{0});
m_pConfig->addConfigValue("decoration:dim_strength", {0.5f}); m_pConfig->addConfigValue("decoration:dim_strength", {0.5f});
m_pConfig->addConfigValue("decoration:dim_special", {0.2f}); m_pConfig->addConfigValue("decoration:dim_special", {0.2f});

View file

@ -64,7 +64,7 @@ void CAnimationManager::tick() {
if (!*PANIMENABLED) if (!*PANIMENABLED)
animGlobalDisabled = true; animGlobalDisabled = true;
static auto* const PSHADOWSENABLED = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("decoration:drop_shadow"); static auto* const PSHADOWSENABLED = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("decoration:shadow:enabled");
const auto DEFAULTBEZIER = m_mBezierCurves.find("default"); const auto DEFAULTBEZIER = m_mBezierCurves.find("default");

View file

@ -2465,7 +2465,7 @@ void CHyprOpenGLImpl::renderRoundedShadow(CBox* box, int round, int range, const
box = &newBox; box = &newBox;
static auto PSHADOWPOWER = CConfigValue<Hyprlang::INT>("decoration:shadow_render_power"); static auto PSHADOWPOWER = CConfigValue<Hyprlang::INT>("decoration:shadow:render_power");
const auto SHADOWPOWER = std::clamp((int)*PSHADOWPOWER, 1, 4); const auto SHADOWPOWER = std::clamp((int)*PSHADOWPOWER, 1, 4);
@ -2475,7 +2475,7 @@ void CHyprOpenGLImpl::renderRoundedShadow(CBox* box, int round, int range, const
newBox, wlTransformToHyprutils(invertTransform(!m_bEndFrame ? WL_OUTPUT_TRANSFORM_NORMAL : m_RenderData.pMonitor->transform)), newBox.rot); newBox, wlTransformToHyprutils(invertTransform(!m_bEndFrame ? WL_OUTPUT_TRANSFORM_NORMAL : m_RenderData.pMonitor->transform)), newBox.rot);
Mat3x3 glMatrix = m_RenderData.projection.copy().multiply(matrix); Mat3x3 glMatrix = m_RenderData.projection.copy().multiply(matrix);
glEnable(GL_BLEND); blend(true);
glUseProgram(m_RenderData.pCurrentMonData->m_shSHADOW.program); glUseProgram(m_RenderData.pCurrentMonData->m_shSHADOW.program);
@ -2485,7 +2485,7 @@ void CHyprOpenGLImpl::renderRoundedShadow(CBox* box, int round, int range, const
glMatrix.transpose(); glMatrix.transpose();
glUniformMatrix3fv(m_RenderData.pCurrentMonData->m_shSHADOW.proj, 1, GL_FALSE, glMatrix.getMatrix().data()); glUniformMatrix3fv(m_RenderData.pCurrentMonData->m_shSHADOW.proj, 1, GL_FALSE, glMatrix.getMatrix().data());
#endif #endif
glUniform4f(m_RenderData.pCurrentMonData->m_shSHADOW.color, col.r, col.g, col.b, col.a * a); glUniform4f(m_RenderData.pCurrentMonData->m_shSHADOW.color, col.r * col.a * a, col.g * col.a * a, col.b * col.a * a, col.a * a);
const auto TOPLEFT = Vector2D(range + round, range + round); const auto TOPLEFT = Vector2D(range + round, range + round);
const auto BOTTOMRIGHT = Vector2D(box->width - (range + round), box->height - (range + round)); const auto BOTTOMRIGHT = Vector2D(box->width - (range + round), box->height - (range + round));

View file

@ -36,7 +36,7 @@ std::string CHyprDropShadowDecoration::getDisplayName() {
} }
void CHyprDropShadowDecoration::damageEntire() { void CHyprDropShadowDecoration::damageEntire() {
static auto PSHADOWS = CConfigValue<Hyprlang::INT>("decoration:drop_shadow"); static auto PSHADOWS = CConfigValue<Hyprlang::INT>("decoration:shadow:enabled");
if (*PSHADOWS != 1) if (*PSHADOWS != 1)
return; // disabled return; // disabled
@ -52,7 +52,7 @@ void CHyprDropShadowDecoration::damageEntire() {
shadowBox.translate(PWORKSPACE->m_vRenderOffset.value()); shadowBox.translate(PWORKSPACE->m_vRenderOffset.value());
shadowBox.translate(PWINDOW->m_vFloatingOffset); shadowBox.translate(PWINDOW->m_vFloatingOffset);
static auto PSHADOWIGNOREWINDOW = CConfigValue<Hyprlang::INT>("decoration:shadow_ignore_window"); static auto PSHADOWIGNOREWINDOW = CConfigValue<Hyprlang::INT>("decoration:shadow:ignore_window");
const auto ROUNDING = PWINDOW->rounding(); const auto ROUNDING = PWINDOW->rounding();
const auto ROUNDINGSIZE = ROUNDING - M_SQRT1_2 * ROUNDING + 1; const auto ROUNDINGSIZE = ROUNDING - M_SQRT1_2 * ROUNDING + 1;
@ -102,11 +102,11 @@ void CHyprDropShadowDecoration::draw(PHLMONITOR pMonitor, float const& a) {
if (PWINDOW->m_sWindowData.noShadow.valueOrDefault()) if (PWINDOW->m_sWindowData.noShadow.valueOrDefault())
return; return;
static auto PSHADOWS = CConfigValue<Hyprlang::INT>("decoration:drop_shadow"); static auto PSHADOWS = CConfigValue<Hyprlang::INT>("decoration:shadow:enabled");
static auto PSHADOWSIZE = CConfigValue<Hyprlang::INT>("decoration:shadow_range"); static auto PSHADOWSIZE = CConfigValue<Hyprlang::INT>("decoration:shadow:range");
static auto PSHADOWIGNOREWINDOW = CConfigValue<Hyprlang::INT>("decoration:shadow_ignore_window"); static auto PSHADOWIGNOREWINDOW = CConfigValue<Hyprlang::INT>("decoration:shadow:ignore_window");
static auto PSHADOWSCALE = CConfigValue<Hyprlang::FLOAT>("decoration:shadow_scale"); static auto PSHADOWSCALE = CConfigValue<Hyprlang::FLOAT>("decoration:shadow:scale");
static auto PSHADOWOFFSET = CConfigValue<Hyprlang::VEC2>("decoration:shadow_offset"); static auto PSHADOWOFFSET = CConfigValue<Hyprlang::VEC2>("decoration:shadow:offset");
if (*PSHADOWS != 1) if (*PSHADOWS != 1)
return; // disabled return; // disabled
@ -184,7 +184,7 @@ void CHyprDropShadowDecoration::draw(PHLMONITOR pMonitor, float const& a) {
g_pHyprOpenGL->renderRect(&fullBox, CColor(0, 0, 0, 1), 0); g_pHyprOpenGL->renderRect(&fullBox, CColor(0, 0, 0, 1), 0);
// render white shadow with the alpha of the shadow color (otherwise we clear with alpha later and shit it to 2 bit) // render white shadow with the alpha of the shadow color (otherwise we clear with alpha later and shit it to 2 bit)
g_pHyprOpenGL->renderRoundedShadow(&fullBox, ROUNDING * pMonitor->scale, *PSHADOWSIZE * pMonitor->scale, CColor(1, 1, 1, PWINDOW->m_cRealShadowColor.value().a), a); drawShadowInternal(&fullBox, ROUNDING * pMonitor->scale, *PSHADOWSIZE * pMonitor->scale, CColor(1, 1, 1, PWINDOW->m_cRealShadowColor.value().a), a);
// render black window box ("clip") // render black window box ("clip")
g_pHyprOpenGL->renderRect(&windowBox, CColor(0, 0, 0, 1.0), (ROUNDING + 1 /* This fixes small pixel gaps. */) * pMonitor->scale); g_pHyprOpenGL->renderRect(&windowBox, CColor(0, 0, 0, 1.0), (ROUNDING + 1 /* This fixes small pixel gaps. */) * pMonitor->scale);
@ -204,9 +204,8 @@ void CHyprDropShadowDecoration::draw(PHLMONITOR pMonitor, float const& a) {
g_pHyprOpenGL->setMonitorTransformEnabled(false); g_pHyprOpenGL->setMonitorTransformEnabled(false);
g_pHyprOpenGL->m_RenderData.damage = saveDamage; g_pHyprOpenGL->m_RenderData.damage = saveDamage;
} else { } else
g_pHyprOpenGL->renderRoundedShadow(&fullBox, ROUNDING * pMonitor->scale, *PSHADOWSIZE * pMonitor->scale, PWINDOW->m_cRealShadowColor.value(), a); drawShadowInternal(&fullBox, ROUNDING * pMonitor->scale, *PSHADOWSIZE * pMonitor->scale, PWINDOW->m_cRealShadowColor.value(), a);
}
if (m_seExtents != m_seReportedExtents) if (m_seExtents != m_seReportedExtents)
g_pDecorationPositioner->repositionDeco(this); g_pDecorationPositioner->repositionDeco(this);
@ -215,3 +214,16 @@ void CHyprDropShadowDecoration::draw(PHLMONITOR pMonitor, float const& a) {
eDecorationLayer CHyprDropShadowDecoration::getDecorationLayer() { eDecorationLayer CHyprDropShadowDecoration::getDecorationLayer() {
return DECORATION_LAYER_BOTTOM; return DECORATION_LAYER_BOTTOM;
} }
void CHyprDropShadowDecoration::drawShadowInternal(CBox* box, int round, int range, CColor color, float a) {
static auto PSHADOWSHARP = CConfigValue<Hyprlang::INT>("decoration:shadow:sharp");
g_pHyprOpenGL->blend(true);
color.a *= a;
if (*PSHADOWSHARP)
g_pHyprOpenGL->renderRect(box, color, round);
else
g_pHyprOpenGL->renderRoundedShadow(box, round, range, color, 1.F);
}

View file

@ -34,6 +34,8 @@ class CHyprDropShadowDecoration : public IHyprWindowDecoration {
Vector2D m_vLastWindowPos; Vector2D m_vLastWindowPos;
Vector2D m_vLastWindowSize; Vector2D m_vLastWindowSize;
void drawShadowInternal(CBox* box, int round, int range, CColor color, float a);
CBox m_bLastWindowBox = {0}; CBox m_bLastWindowBox = {0};
CBox m_bLastWindowBoxWithDecos = {0}; CBox m_bLastWindowBoxWithDecos = {0};
}; };