#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(); 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 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 auto tex = data.decoration->GetBorderTexture({box.w, box.h}, extentPx, chamferPx, gradient, titleBarHeightPx, borderTitleBarWidthPx); if (!tex || !tex->ok()) return {}; CTexPassElement::SRenderData texData; texData.tex = tex; texData.box = box; texData.a = data.alpha; std::vector> children; 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); }