Skip to content

st: Allow a step in the middle of background gradients - #14176

Open
xlcheese wants to merge 2 commits into
linuxmint:masterfrom
xlcheese:st-gradient-middle-stops
Open

xlcheese wants to merge 2 commits into
linuxmint:masterfrom
xlcheese:st-gradient-middle-stops

Conversation

@xlcheese

@xlcheese xlcheese commented Nov 25, 2026 •

Copy link
Copy Markdown

St's background gradients currently take two colors, which only allow Cinnamon themes to have smooth gradients. In the interest of creating Cinnamon themes with a glass style panel a multi-stop linear-gradient() is desired. This adds CSS linear-gradient() to St backgrounds:

/* a glossy "glass" button: darker to the middle, a step, lighter again below */
background-image: linear-gradient(to bottom, #c8d8f0, #9ab4dc 50%, #5a7cb0 50%, #88a4d0);

It follows the CSS linear-gradient() syntax, so a gradient copied from a GTK theme works as it is:

  • Direction (optional, default to bottom): to top, to right, a corner such as to bottom right, or an angle such as 90deg.
  • Colors: two or more, in any form St already reads (including rgba()), each with an optional percentage. Two colors at the same percentage make a hard step.
  • It's read from background-image and the background shorthand.

A linear-gradient() St can't read is ignored with a warning.

Compatibility

  • Existing themes are unchanged. The background-gradient-* properties work as they previously did, and radial gradients still use them. Neither Cinnamon's own theme nor Mint-Y uses linear-gradient() today.
  • linear-gradient() takes precedence over background-gradient-*, so a theme can write both. Cinnamon versions without this patch ignore linear-gradient() without a warning and draw the two-color gradient. I checked this on stock Cinnamon (screenshot below).
  • The first and last stops fill in the gradient start and end, so st_theme_node_get_background_gradient() and other code that only knows two-color gradients keep working.
  • The stops are included in the translucency and visible-outline checks and in st_theme_node_paint_equal(), so a change to any stop repaints. background-image: url() or none, or the background shorthand, clears them.

The first commit used separate background-gradient-middle-* properties. The second replaces them with linear-gradient(), as suggested in review. Also included: background_image is set to NULL after it's freed when a background-image: url() doesn't resolve, rather than left pointing at freed memory.

tests/interactive/background-gradient.js has each case.

Testing

Built from this branch and run on the Linux Mint 27 beta (Cinnamon 6.8), Wayland session.

Before (stock Cinnamon: linear-gradient() is ignored; "both given" falls back to the red background-gradient-*):

image-1795837205486

After:

image-1795837258497

A real theme with a glass style on the panel and its buttons (Gradients were exaggerated for demonstration):

xl-GummyDark xl-Gummy-Light

Why

I'm working on a tool called Theme Roller so users can generate fully custom themes for Cinnamon. A couple of the themes I've included were derived from the old Clearlooks style. One is the older smooth gradient version and another was the slightly reworked Clearlooks Gummy which contained the glass effect on the panel and widgets. I have a light and dark version of the glossy theme and they are both updated to use linear-gradient() and the two-color properties, so it works on Cinnamon with and without this patch.

It's also a small, fun thing for anyone making Cinnamon themes by hand: a glossy panel or button takes one line of standard CSS, with nothing to draw in an image editor, and the same linear-gradient() they already write for GTK.

🤖 Generated with Claude Code

Add optional middle color stops to St background gradients, so themes
can draw Clearlooks-style glossy faces (a fade, a hard step across the
middle, then another fade), as GTK themes do with a four-stop CSS
linear-gradient():

  background-gradient-middle-start: <color>;   arriving at the middle
  background-gradient-middle-end: <color>;     leaving the middle
  background-gradient-middle-position: <percentage>;   default 50%

The two middle colors are added as cairo stops at the same offset,
which gives a hard step. If only one of them is set, it is used for
both, giving a three-stop gradient with no step. This works for
vertical, horizontal and radial gradients (for radial, the position
is a fraction of the radius).

Themes that don't set the new properties draw exactly as before.
The middle colors are taken into account by the translucency and
visible-outline checks, and by st_theme_node_paint_equal(), so a
change to only the middle repaints.

Add an interactive test, tests/interactive/background-gradient.js.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@JosephMcc

Copy link
Copy Markdown
Contributor

Seems like implementing a linear-gradient function would be better than this mess of properties. Of course, I'm also not a huge fan of all the AI code that you may or may not even understand.

Replace the background-gradient-middle-* properties from the previous
commit with CSS linear-gradient(), as suggested in review:

  background-image: linear-gradient(to bottom, #c8d8f0,
                                    #9ab4dc 50%, #5a7cb0 50%, #88a4d0);

It takes an optional direction, either an angle (deg, rad, grad) or
"to" with one or two sides, then two or more colors, each with
optional percentages. As in CSS, stops without a position are spread
evenly, a position before an earlier one is moved up to it, and two
stops at the same position draw a hard step. "to <corner>" and angles
use the CSS gradient line, so the corners get the first and last
colors. It is also read from the background shorthand. A
linear-gradient() that can't be read is ignored with a warning.

linear-gradient() takes precedence over the background-gradient-*
properties, so a theme can give both and Cinnamon versions without
linear-gradient() draw the two-color gradient: they ignore the
function term without a warning. Its first and last stops fill in the
gradient start and end, so st_theme_node_get_background_gradient() and
other code that only knows two-color gradients keep working. Radial
gradients still use the background-gradient-* properties.

The stops are included in the translucency and visible-outline checks
and in st_theme_node_paint_equal(). A background-image url() or none,
or the background shorthand, clears them.

Also set background_image to NULL after freeing it when a
background-image url() doesn't resolve, rather than leaving it
pointing at freed memory.

Update tests/interactive/background-gradient.js for linear-gradient().

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@xlcheese

Copy link
Copy Markdown
Author

Reworked it as linear-gradient() as you suggested. Testing it on the Mint 27 beta tonight or possibly tomorrow, screenshots to follow.

@xlcheese

Copy link
Copy Markdown
Author

Thanks for the quick response and suggesting linear-gradient(). It's a cleaner solution for those writing themes and allows for any number of stops. The first properties solution was suggested only because it made a smaller patch. It's reworked and updated in the description above. It reads linear-gradient() into a list of color stops and hands them to cairo. So two stops at the same position draw the hard step, and the old two-color properties still work. I built and tested it on the Mint 27 beta (Cinnamon 6.8, Wayland); screenshots are in the description.

I understand your concern about ai driven code. My intention is to not throw around AI code loosely. I genuinely want to contribute to Mint in a positive way. I spent a decade as a hardware design and validation engineer. Owning my own business and building a few ecommerce websites I picked up on writing CSS and UI/UX design. I have also written a suite of python scripts over the years for my needs within my business. I'm not a professional software developer.

Theming my own computer has always been a hobby, going back to the Clearlooks GTK 2 days. I even forked the Clearlooks engine and changed its C code to make things draw the way I liked.

My recent project, Theme Roller, I could not have made without using the Robot as a tool. And, at least not yet, the robot couldn't have made it on it's own. What I bring is attention to detail and thorough testing. I have spent way more hours on that tool than I care to admit.

It's the least I can do for Mint. I've used it for free ever since Ubuntu introduced Unity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants