#include "ChromePassElement.hpp" #include "Globals.hpp" #include "ChromeDecoration.hpp" #include "ChromeDecorationGeometry.hpp" #include #include #include #include #include ChromePassElement::ChromePassElement(const SData& data_) : data(data_) {} std::vector> ChromePassElement::draw() { const auto monitor = g_pHyprRenderer->m_renderData.pMonitor.lock(); if (!monitor) return {}; const auto window = data.decoration->GetOwner(); if (!window) return {}; auto box = data.decoration->FullDecorationExtentGlobal(); box.translate(-monitor->m_position).scale(monitor->m_scale); // Round the position and the size independently, rather than via // CBox::round(). That derives the size from the two *rounded corners* // (round(x + w) - round(x)), which makes it a function of the position's // fractional part - so a box that is merely sliding, at a perfectly // constant size, has its rounded w/h flip by a pixel every few frames. // Every one of those flips misses the caches in GetBorderTexture / // GetShadowTexture / GetTitleTexture, each miss being a full cairo // re-render plus a GPU re-upload of a texture that didn't actually change // appearance - which is precisely what a workspace switch, a window move, // or any other position-only animation does, every frame, for every window // on screen. Rounded on its own, the size stays a pure function of the // window's own size and can't be perturbed by translation at all. // // What round()'s coupling buys is a far edge that lands on the same device // pixel as an adjacent box's near edge. Nothing abuts this box - it's a // free-floating decoration drawn over everything - so there is no seam here // to keep closed. box = CBox{box.pos().round(), box.size().round()}; if (box.w < 1 || box.h < 1) return {}; // Chamfer amount is inferred from the window's own border rounding, in // device pixels, so the frame's cut corners track the window's rounding // live (config reload, per-window rules, animations). const float chamferPx = window->rounding() * monitor->m_scale; const float extentPx = static_cast(PluginState->config.extent->value()) * monitor->m_scale; const bool isActive = g_pCompositor->isWindowActive(window); // When follow_hyprland_border_color is set, track Hyprland's own // general:col.active_border / col.inactive_border (already resolved per // focus state and animated by the compositor), stops and angle included. // Otherwise (or if Hyprland reports no border color at all) fall back to // our own active_color/inactive_color config, which take the same // gradient syntax. const auto& hyprlandBorder = window->m_realBorderColor; const bool followHyprlandColor = PluginState->config.followHyprlandBorderColor->value() && !hyprlandBorder.m_colors.empty(); const auto gradient = ChromeGradient::From(followHyprlandColor ? hyprlandBorder : (isActive ? PluginState->config.activeColor->value() : PluginState->config.inactiveColor->value())); const float borderAlpha = gradient.FirstAlpha(); const float glowPx = static_cast(PluginState->config.glowSize->value()) * monitor->m_scale; const float glowStrength = static_cast(PluginState->config.glowStrength->value()); const float titleBarHeightPx = static_cast(PluginState->config.titlebarHeight->value()) * monitor->m_scale; const float textSizePx = static_cast(PluginState->config.titlebarTextSize->value()) * monitor->m_scale; const std::string fontFamily = PluginState->config.titlebarFont->value(); // Base geometry (everything but the title bar plateau's own width - that // depends on the rendered title text, which can only be measured by // actually rendering it). MaxTitleBarWidth() bounds that render so a long // title gets ellipsized rather than growing the plateau into the // self-intersection GetBorderTexture's cairo path would otherwise risk. const auto baseGeo = ChromeDecorationGeometry::ComputeBase({box.w, box.h}, extentPx, chamferPx, titleBarHeightPx); // Padding around the title text, inside the plateau. const float titlePadding = textSizePx * 1.2F; const int measureMaxWidthPx = static_cast(baseGeo.MaxTitleBarWidth() - baseGeo.barX0 - titlePadding * 2.F); const auto titleTex = measureMaxWidthPx > 0 ? data.decoration->GetTitleTexture(window->m_title, textSizePx, borderAlpha, fontFamily, measureMaxWidthPx, isActive) : nullptr; const float texW = (titleTex && titleTex->ok()) ? static_cast(titleTex->m_size.x) : 0.F; // Plateau grows to fit the measured text + padding, floored at 20% of the // total width regardless of how short (or absent) the title is. const float desiredTitleBarWidthPx = baseGeo.barX0 + texW + titlePadding * 2.F; const auto geo = baseGeo.WithTitleBarWidth(desiredTitleBarWidthPx); // In fullSpan mode the outer path's shape is fixed regardless of text // width (see GetBorderTexture), so pass a value that doesn't fluctuate // with title length - otherwise every title change would needlessly // regenerate an identical border texture. const float borderTitleBarWidthPx = geo.fullSpan ? geo.MaxTitleBarWidth() : geo.titleBarWidth; const float outlinePx = static_cast(PluginState->config.outlineSize->value()) * monitor->m_scale; const CHyprColor outlineColor{static_cast(PluginState->config.outlineColor->value())}; const auto tex = data.decoration->GetBorderTexture({box.w, box.h}, extentPx, chamferPx, gradient, titleBarHeightPx, borderTitleBarWidthPx, glowPx, glowStrength, outlinePx, outlineColor); if (!tex || !tex->ok()) return {}; std::vector> children; // Emitted first so it lands under the frame - which matters, because the // shadow does run under the frame's own outline (only the window's interior // is cleared out of it), and the frame is what hides that cut. const float shadowSizePx = static_cast(PluginState->config.shadowSize->value()) * monitor->m_scale; const auto configOffset = PluginState->config.shadowOffset->value(); const Vector2D shadowOffsetPx = {configOffset.x * monitor->m_scale, configOffset.y * monitor->m_scale}; const CHyprColor shadowColor{static_cast(PluginState->config.shadowColor->value())}; if (const auto shadowTex = data.decoration->GetShadowTexture({box.w, box.h}, extentPx, chamferPx, titleBarHeightPx, borderTitleBarWidthPx, shadowSizePx, shadowColor, shadowOffsetPx); shadowTex && shadowTex->ok()) { const float margin = ChromeDecoration::ShadowMarginPx(shadowSizePx, shadowOffsetPx); CTexPassElement::SRenderData shadowData; shadowData.tex = shadowTex; shadowData.box = CBox{ box.x - margin + shadowOffsetPx.x, box.y - margin + shadowOffsetPx.y, box.w + 2.0 * margin, box.h + 2.0 * margin, }; shadowData.a = data.alpha; children.emplace_back(makeUnique(shadowData)); } CTexPassElement::SRenderData texData; texData.tex = tex; texData.box = box; texData.a = data.alpha; children.emplace_back(makeUnique(texData)); if (titleTex && titleTex->ok() && titleTex->m_size.x > 0 && titleTex->m_size.y > 0) { const float texH = static_cast(titleTex->m_size.y); const float localX = geo.barX0 + titlePadding; const float localY = (geo.barBottom - texH) / 2.F; CTexPassElement::SRenderData titleData; titleData.tex = titleTex; titleData.box = CBox{box.x + localX, box.y + localY, texW, texH}; titleData.a = data.alpha; children.emplace_back(makeUnique(titleData)); } return children; } bool ChromePassElement::needsLiveBlur() { return false; } bool ChromePassElement::needsPrecomputeBlur() { return false; } std::optional ChromePassElement::boundingBox() { const auto monitor = g_pHyprRenderer->m_renderData.pMonitor.lock(); if (!monitor) return std::nullopt; return data.decoration->FullDecorationExtentGlobal() .translate(-monitor->m_position) .expand(4 + ChromeDecoration::ShadowMarginLogical()); }