Files
hypr-chrome/src/ChromeDecoration.hpp
T
darmanandClaude Opus 5 b9dafe2ce1 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>
2026-07-29 20:36:24 +02:00

89 lines
3.6 KiB
C++

#pragma once
#define WLR_USE_UNSTABLE
#include "Globals.hpp"
#include "ChromeGradient.hpp"
#include <hyprland/src/desktop/DesktopTypes.hpp>
#include <hyprland/src/render/decorations/IHyprWindowDecoration.hpp>
#include <hyprutils/math/Box.hpp>
#include <hyprutils/math/Vector2D.hpp>
#include <string>
namespace Render {
class ITexture;
}
// A decoration that draws a chamfered HUD-style border frame behind each
// window, expanding past the window's edges by `plugin:hyprchrome:extent`
// pixels on every side. The frame's corners are chamfered by an amount
// inferred from the window's own border rounding, so the border peeking out
// around a rounded window's corners reads as a matching diagonal cut rather
// than a hard rectangular corner.
class ChromeDecoration : public IHyprWindowDecoration {
public:
ChromeDecoration(PHLWINDOW window);
virtual ~ChromeDecoration();
virtual SDecorationPositioningInfo getPositioningInfo();
virtual void onPositioningReply(const SDecorationPositioningReply& reply);
virtual void draw(PHLMONITOR monitor, float const& alpha);
virtual eDecorationType getDecorationType();
virtual void updateWindow(PHLWINDOW window);
virtual void damageEntire();
virtual eDecorationLayer getDecorationLayer();
virtual uint64_t getDecorationFlags();
virtual std::string getDisplayName();
PHLWINDOW GetOwner();
// Returns a cairo-rendered texture of the chamfered border frame sized to
// `sizePx` (device pixels): a hollow ring `extentPx` thick inset from the
// outer edge, with both the outer and inner boundaries corner-chamfered
// by `chamferPx`, plus a title bar of height `titleBarHeightPx` and width
// `titleBarWidthPx` (already measured/clamped by the caller - see
// ChromeDecorationGeometry) hanging off the floating top-border
// cutout. Filled with `gradient` swept across the whole texture along that
// gradient's own axis (a single-stop gradient is just a flat fill). Cached
// and only regenerated when any of these change from the last call.
SP<Render::ITexture> GetBorderTexture(const Vector2D& sizePx, float extentPx, float chamferPx, const ChromeGradient& gradient, float titleBarHeightPx, float titleBarWidthPx);
// Returns a texture of `title` rendered via Hyprland's own text renderer
// (Pango, through IHyprRenderer::renderText) at `textSizePx` using
// `fontFamily`, truncated with a trailing "…" if it doesn't fit within
// `maxWidthPx` - black while `isActive`, 0xEEEEEE otherwise, both at
// `alpha` (the border's own alpha, so translucent borders keep translucent
// text). Cached and only regenerated when any of these change from the last
// call. Returns nullptr if `title` is empty.
SP<Render::ITexture> GetTitleTexture(const std::string& title, float textSizePx, float alpha, const std::string& fontFamily, int maxWidthPx, bool isActive);
WP<ChromeDecoration> self;
private:
PHLWINDOWREF windowRef;
CBox assignedBox;
SP<Render::ITexture> cachedTexture;
Vector2D cachedTexSize = {-1, -1};
float cachedExtent = -1.F;
float cachedChamfer = -1.F;
ChromeGradient cachedGradient;
float cachedTitleBarHeight = -1.F;
float cachedTitleBarWidth = -1.F;
SP<Render::ITexture> cachedTitleTex;
std::string cachedTitleTexTitle;
float cachedTitleTexSize = -1.F;
float cachedTitleTexAlpha = -1.F;
std::string cachedTitleTexFont;
int cachedTitleTexMaxWidth = -1;
bool cachedTitleTexActive = false;
// The border frame's box in global (monitor-independent) logical
// coordinates: the window's own box, expanded by `extent` and offset by
// the window's workspace/floating animation offsets.
CBox FullDecorationExtentGlobal();
friend class ChromePassElement;
};