From 3dc121e8b373e658a5d68f0a9e55092abc04ab8c Mon Sep 17 00:00:00 2001 From: Ken Sanislo Date: Mon, 11 May 2026 01:13:55 -0700 Subject: [PATCH] PerKey gradient swatch: align gradient endpoints to visible corners MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cairo linear-gradient endpoints were placed at the rounded rect's geometric corners (3,3) and (21,21), but the *visible* corner pixel of a rounded rect with radius 2 is the outermost point of the arc, inset along the diagonal by r * (1 - 1/sqrt(2)) ≈ 0.586 units. That meant t=0 and t=1 of the gradient landed in the cut-off corner regions, and the rendered corners sampled at t≈0.033 / 0.967 — about 3.3% in from each endpoint, ~8 RGB units short of the true previous / active colors (visible on saturated pairs like pure red → pure blue: the "pure red" corner rendered as ~rgb(194, 10, 0)). Shift the gradient endpoints inward by the arc inset so t=0 maps to the visible TL corner pixel and t=1 to the visible BR pixel. The gradient now spans the visually rendered area exactly; saturated endpoints render flush. --- lib/solaar/ui/perkey/palette.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/solaar/ui/perkey/palette.py b/lib/solaar/ui/perkey/palette.py index 95953c12..2f99ae37 100644 --- a/lib/solaar/ui/perkey/palette.py +++ b/lib/solaar/ui/perkey/palette.py @@ -211,7 +211,13 @@ class GradientSwatch(Gtk.DrawingArea): cr.clip() # Top-left (previous, gradient start) → bottom-right (active, end). # Matches the directional behavior of dragging the line tool TL → BR. - pat = cairo.LinearGradient(3, 3, 21, 21) + # Endpoints are shifted inward by the arc inset (corner radius * (1 + # - 1/sqrt(2)), ~0.586 for r=2) so t=0 lands on the actual visible + # TL corner pixel of the rounded rect — without this, the rendered + # corners sample at t≈0.033/0.967 and the displayed colors are + # ~8 RGB units short of the true endpoint colors. + inset = 2 * (1 - 1 / (2**0.5)) + pat = cairo.LinearGradient(3 + inset, 3 + inset, 21 - inset, 21 - inset) pat.add_color_stop_rgb(0.0, *rgb(self._previous)) pat.add_color_stop_rgb(1.0, *rgb(self._active)) cr.set_source(pat)