Render border gradients instead of a flat first stop

The frame collapsed Hyprland's border gradient to m_colors.front(), so a
gradient col.active_border showed up as a single flat color.

Snapshot the gradient (stops + angle) into a new header-only ChromeGradient
and fill the cairo path with a linear gradient built from it:

- AxisFor() reproduces the border shader's quadrant-folding progress
  function (y*sin(a) + x*(1-sin(a)), not a true rotation) as a cairo axis,
  so the frame's sweep stays in step with the window border it wraps.
  Checked against a port of the shader across all 360 degrees: cardinal
  angles exact, worst case 0.003 of the sweep (the shader folds on literal
  1.57/3.14/4.71 where this uses pi).
- SampleAt() interpolates in OkLab, where the shader interpolates, with
  each segment subdivided into sampled cairo stops so cairo's own sRGB lerp
  tracks that curve.

active_color/inactive_color become gradient config values, taking the same
syntax as general:col.active_border. Single-color configs are unaffected.

The cross-focus fade (m_realBorderColorPrevious + fade progress, lerped
between two gradients in-shader) is still not reproduced.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-29 20:36:24 +02:00
co-authored by Claude Opus 5
parent 73ce9ddbdf
commit b9dafe2ce1
9 changed files with 215 additions and 43 deletions
+11 -10
View File
@@ -34,15 +34,16 @@ std::vector<UP<IPassElement>> ChromePassElement::draw() {
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) - gradients are collapsed
// to their first stop, since the ring is a flat fill, not a shader.
// 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.
const auto& borderGradient = window->m_realBorderColor;
const bool followHyprlandColor = PluginState->config.followHyprlandBorderColor->value() && !borderGradient.m_colors.empty();
const uint64_t colorValue = followHyprlandColor
? static_cast<uint64_t>(borderGradient.m_colors.front().getAsHex())
: static_cast<uint64_t>(isActive ? PluginState->config.activeColor->value() : PluginState->config.inactiveColor->value());
// 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<float>(PluginState->config.titlebarHeight->value()) * monitor->m_scale;
const float textSizePx = static_cast<float>(PluginState->config.titlebarTextSize->value()) * monitor->m_scale;
const std::string fontFamily = PluginState->config.titlebarFont->value();
@@ -58,7 +59,7 @@ std::vector<UP<IPassElement>> ChromePassElement::draw() {
const int measureMaxWidthPx = static_cast<int>(baseGeo.MaxTitleBarWidth() - baseGeo.barX0 - titlePadding * 2.F);
const auto titleTex = measureMaxWidthPx > 0
? data.decoration->GetTitleTexture(window->m_title, textSizePx, colorValue, fontFamily, measureMaxWidthPx, isActive)
? data.decoration->GetTitleTexture(window->m_title, textSizePx, borderAlpha, fontFamily, measureMaxWidthPx, isActive)
: nullptr;
const float texW = (titleTex && titleTex->ok()) ? static_cast<float>(titleTex->m_size.x) : 0.F;
@@ -72,7 +73,7 @@ std::vector<UP<IPassElement>> ChromePassElement::draw() {
// 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, colorValue, titleBarHeightPx, borderTitleBarWidthPx);
const auto tex = data.decoration->GetBorderTexture({box.w, box.h}, extentPx, chamferPx, gradient, titleBarHeightPx, borderTitleBarWidthPx);
if (!tex || !tex->ok())
return {};