Skip to content

fix(linux): keep the sidebar selection tint out of row popovers - #38

Merged
melonamin merged 2 commits into
melonamin:linux-portfrom
n2tr2:pr-selection-tint-row-popovers
Sep 1, 2026
Merged

melonamin merged 2 commits into
melonamin:linux-portfrom
n2tr2:pr-selection-tint-row-popovers

Conversation

@n2tr2

@n2tr2 n2tr2 commented Aug 31, 2026 •

Copy link
Copy Markdown

Right-clicking a session row opened a context menu whose items were invisible under any theme whose
selection-foreground equals the terminal background. Kanagawa Dragon is the clearest case — both are
#181616 — and only the hovered item stayed faintly readable.

Before After
before after

Same view, same window geometry, Kanagawa Dragon, first session row selected. On the left the popover is
a bare rectangle — all seven labels are painted #181616 on the #181616 popover background.

Root cause

showRowContextMenu parents the popover to the right-clicked row, and the right-click also selects
that row, so the row carries .agterm-selected. The tint rule

.agterm-selected label { color: <selFg>; }

is a descendant match, so it reached row > popover > contents > box > button > label and painted
every menu label in the selection foreground — while @define-color popover_bg_color <themeBg> painted
the popover in the matching background. .agterm-sidebar label has equal specificity and loses on order.

Present since the popover was reparented from the list box to the row (#26). The recent
GTK_THEME=Adwaita-dark removal fixed an unrelated libadwaita fault and never touched this one.

Fix

The rule becomes .agterm-selected > label, .agterm-selected > image, scoping the tint to the row's
own content. setSidebarSelectionStyle tags both the row and its content box, and makeRow appends
every label and icon directly to that box, so the child combinator still reaches them all — name label,
breadcrumb, terminal icon, star. The status glyph and unseen badge keep their pango markup colors,
which CSS never touched.

The image half fixes a second symptom of the same collision: symbolic icons take their color from
CSS color, and the old rule matched only label, so the leading terminal icon and the flagged star
kept the sidebar foreground on selected rows — invisible under the same themes, where the selection
background is the foreground.

The sibling .agterm-sidebar label/button rules stay descendant matches deliberately: they keep
cascading into the popover, and popover_fg_color resolves to the same value.

Rejected alternatives: a second class on the content box (one more thing to keep in sync), resetting the
color inside popovers (keeps the leaky rule and adds another), and reverting the popover parent
(undoes #26).

Why the refactor rides along

The rule lived in a 30-line inline interpolation inside applyWindowThemeColors, which needs a
GdkDisplay — so nothing host-free could pin what the provider actually loads, and the CSS was only ever
exercised by eye. ThemeColorResolver.windowThemeCSS(...) now owns the string, taking the five values the
caller already resolves. The move is byte-identical apart from the one rule, and AppController.swift
drops from 992 to 963 lines, off the 1000-line lint ceiling it was sitting against.

This follows the existing precedent of LinuxSidebarPolicy.sidebarCSS and App.swift's appCSS: a pure
builder in a Foundation-only type, string-pinned in tests.

Tests

GhosttyConfigThemeTests gains one case pinning the whole emitted string. It uses five distinct
sentinel colors (#111111…#555555) rather than a real palette on purpose: Kanagawa Dragon collapses
five parameters into three values, so a transposed substitution would have emitted a byte-identical string
and passed. Plus a negative assertion against reintroducing the descendant form.

agterm-linux/docs/sidebar.md now owns the resulting contract — row labels must stay direct children of
the content box, or the tint drops silently.

Verification

  • swift test — the new case and the rest of the suite pass.
  • make lint — zero findings.
  • Manual, captured above: isolated instance under Kanagawa Dragon, right-click on a selected row.
    Both builds were confirmed by strings before capture (descendant selector in the before binary,
    child combinator in the after).

Right-clicking a session row opened a context menu whose items were
invisible under any theme whose selection-foreground equals the terminal
background (Kanagawa Dragon: both #181616). Only the hovered item stayed
faintly readable.

`showRowContextMenu` parents the popover to the right-clicked ROW, and the
right-click also selects that row, so the row carries `.agterm-selected`.
The tint rule `.agterm-selected label { color: <selFg>; }` is a DESCENDANT
match, so it reached `row > popover > contents > box > button > label` and
painted every menu label in the selection foreground, while
`@define-color popover_bg_color <themeBg>` painted the popover in the
matching background. `.agterm-sidebar label` has equal specificity and
loses on order. Present since the popover was reparented from the list box
to the row (melonamin#26); the recent `GTK_THEME=Adwaita-dark` removal fixed an
unrelated libadwaita fault and never touched this one.

The rule becomes `.agterm-selected > label`, scoping the tint to the row's
own labels. `setSidebarSelectionStyle` tags both the row and its content
box, and `makeRow` appends every label directly to that box, so the child
combinator still reaches all of them. The sibling `.agterm-sidebar
label`/`button` rules stay descendant matches deliberately: they keep
cascading into the popover, and `popover_fg_color` is the same value.

Rejected: a second class on the content box (one more thing to keep in
sync), resetting the color inside popovers (keeps the leaky rule and adds
another), and reverting the popover parent (undoes melonamin#26).

To make the rule testable, `applyWindowThemeColors` no longer builds the
display-wide chrome stylesheet as a 30-line inline interpolation: nothing
host-free could pin what the provider loads, because the method needs a
`GdkDisplay`. `ThemeColorResolver.windowThemeCSS(background:foreground:
selectionBackground:selectionForeground:sidebarBackground:)` now owns the
string, taking the five values the caller already resolves. The move is
byte-identical apart from the one rule, and `AppController.swift` drops
from 992 to 963 lines, below the 1000-line lint ceiling it was sitting
against. This follows `LinuxSidebarPolicy.sidebarCSS` and `App.swift`'s
`appCSS`: a pure builder in a Foundation-only type, string-pinned in
tests. The new `GhosttyConfigThemeTests` case asserts full string equality
against a hand-transcribed literal using five distinct sentinel colors, so
a transposed parameter cannot emit the expected string, plus a negative
assertion against reintroducing the descendant form.

`docs/sidebar.md` now owns the resulting contract: row labels must stay
direct children of the content box, or the tint drops silently.
@n2tr2
n2tr2 requested a review from melonamin as a code owner August 31, 2026 11:52
Symbolic icons take their color from CSS `color`, but the selection
tint rule matched only `label` — so the leading terminal icon and the
flagged star kept the sidebar foreground on selected rows and vanished
under any theme whose selection background equals its foreground
(Kanagawa Dragon: both #c5c9c5). The rule gains
`.agterm-selected > image`, same child combinator so row popovers stay
untinted. The status glyph and unseen badge keep their pango markup
colors by design.

Co-Authored-By: Claude Fable 5 <[email protected]>
@n2tr2

n2tr2 commented Aug 31, 2026

Copy link
Copy Markdown
Author

The second commit (11d8028) extends the same fix to the row's symbolic icons.

Symbolic icons take their color from CSS color, and the tint rule matched only label — so the leading terminal icon and the flagged star kept the sidebar foreground on selected rows. Under the same themes that motivated this PR, where the selection background is the foreground, both icons disappeared into the highlight. The rule is now .agterm-selected > label, .agterm-selected > image, same child combinator, so row-parented popovers still inherit nothing. The status glyph and unseen badge keep their pango markup colors, which CSS never touched.

Before After
before after

Same view, Kanagawa Dragon, selected flagged session row. On the left the row shows only its label — the terminal icon and star are painted foreground-on-foreground; on the right both icons take the selection foreground with the label.

The pinned CSS test literal, its selector assertion, and the docs/sidebar.md direct-child contract are updated in the same commit.

@melonamin
melonamin merged commit ec517b6 into melonamin:linux-port Sep 1, 2026
5 checks passed
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