Skip to content

feat(x11): Support OS accent color via the Settings portal - #24424

Merged
MartinZikmund merged 2 commits into
unoplatform:dev/mazi/accentcolorfrom
ajpinedam:dev/anpi/accentcolor-linux
Nov 21, 2026
Merged

MartinZikmund merged 2 commits into
unoplatform:dev/mazi/accentcolorfrom
ajpinedam:dev/anpi/accentcolor-linux

Conversation

@ajpinedam

Copy link
Copy Markdown
Contributor

GitHub Issue: related to #4444 (Linux part; closed by the parent PR #22851)

Stacked on #22851 (dev/mazi/accentcolor). Only the commits on top of that branch belong to this PR; it should be rebased onto master (or the base switched) once #22851 merges.

PR Type:

✨ Feature

What changed? 🚀

#22851 introduces IAccentColorExtension for Skia hosts and implements it for Win32 (registry) and macOS (NSColor.controlAccentColor). On Linux the X11 host had no implementation, so UISettings.GetColorValue(UIColorType.Accent*) and the SystemAccentColor* resources stayed on the default blue palette.

This PR adds LinuxAccentColorExtension to Uno.UI.Runtime.Skia.X11, reading the accent from the XDG Settings portal (org.freedesktop.portal.Settings, version 2, org.freedesktop.appearance / accent-color), the same portal the existing LinuxSystemThemeHelper already uses for color-scheme and contrast:

  • Initial read via ReadOne; the value is a (ddd) struct of sRGB components in [0,1], converted to a Color and expanded with AccentColorPalette.FromAccentColor (Linux exposes a single accent color, like macOS).
  • Live updates via the SettingChanged signal; the change is marshalled to the UI thread and raised through AccentColorChanged, so the shared AccentColorHelper → Application.OnAccentColorChanged path refreshes the resources and raises UISettings.ColorValuesChanged.
  • Graceful fallbacks (default palette, no crash): no session bus, portal older than version 2, backend without the optional accent-color key (DBusErrorReplyException), and out-of-range components, which the portal spec defines as "no accent color set".
  • Registered in X11ApplicationHost next to ISystemThemeHelperExtension. The framebuffer host is not covered (no session bus / portal in that scenario).
  • SystemAccentColorSample description now mentions Linux (GNOME Settings → Appearance, KDE System Settings → Colors & Themes).

Supported desktops are those whose portal backend implements accent-color: GNOME 47+ (xdg-desktop-portal-gnome), KDE Plasma 6 (xdg-desktop-portal-kde), and others following the version 2 spec. Older backends fall back to the default palette.

Validation

  • Compile: Uno.UI.Runtime.Skia.X11 and SamplesApp.Skia.Generic (net10.0, Release) build clean on Windows.

  • Runtime (WSL2 Ubuntu 24.04 / WSLg, .NET 10): SamplesApp.Skia.Generic run against a mock org.freedesktop.portal.Settings v2 service on a private session bus, with a temporary runtime test (not committed) asserting UISettings.GetColorValue(Accent), the resolved SystemColorControlAccentBrush, and UISettings.ColorValuesChanged:

    • initial (1, 0, 0) → GetColorValue(Accent) = #FFFF0000, brush red
    • live SettingChanged → green on both, ColorValuesChanged raised
    • (-1, -1, -1) (out of range) → default #FF0078D7, brush follows
    • (0.5, 0.25, 0.75) → (128, 64, 191) rounding
    • a color-scheme change leaves the accent untouched
    • portal without the accent-color key → debug log, default palette, no crash

    Not verified on a real GNOME/KDE portal backend or under Wayland: I do not have a Linux desktop at hand, so a manual pass with SystemAccentColorSample on GNOME 47+ / Plasma 6 would be welcome.

Behaviour worth knowing

  • The portal is read asynchronously: the first frames use the default palette and the OS accent arrives through AccentColorChanged a few dispatcher turns later, exactly like the system theme on X11 today. {ThemeResource} consumers update; {StaticResource SystemAccentColor} consumers resolved during OnLaunched keep the default (WinUI parity: static resources never re-resolve). A bounded synchronous first read (Task.Run + short Wait) would remove the flash at the cost of blocking startup on DBus; I kept the async design to match the theme helper and avoid a UI-thread wait. Happy to switch if reviewers prefer no flash.
  • The watch is installed before the initial read, so a change racing the read, or a malformed initial value, can never leave the accent stale for the app's lifetime.
  • Degraded environments log at Warning (no session bus, Settings portal older than v2) and Debug (backend without the accent-color key); only unexpected exceptions log at Error.

Follow-ups (not in this PR)

  • The X11 host now opens three independent portal connections (LinuxSystemThemeHelper, X11TextScaleFactorExtension, this one). A shared Settings-portal client fanning out one SettingChanged watch would remove the duplication and the duplicated "no session bus" logs; also align the siblings' version != 2 gate with the forward-compatible version < 2 used here.
  • The (ddd) → palette conversion is pure and could be exposed internal static with an InternalsVisibleTo for a unit test; today the X11 runtime has no test project reference.

PR Checklist ✅

  • 🧪 Added Runtime tests, UI tests, or a manual test sample (for bug fixes / features, if applicable) — covered by the existing manual SystemAccentColorSample; the portal cannot be driven from CI, see Validation above.
  • 📚 Docs have been added/updated following the documentation template (for bug fixes / features) — to follow the parent PR's documentation.
  • 🖼️ Validated PR Screenshots Compare Test Run results.
  • ❗ Contains NO breaking changes
  • 👀 Reviewed 2 other open pull requests (optional but appreciated!)

@github-actions github-actions Bot added area/automation Categorizes an issue or PR as relevant to project automation platform/x11 🐧 Categorizes an issue or PR as relevant to X11 labels Sep 6, 2026
@ajpinedam
ajpinedam marked this pull request as ready for review September 9, 2026 11:51
@mergify

mergify Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

This pull request is merged.

@morning4coffe-dev morning4coffe-dev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed only the Linux delta over the declared #22851 parent (7933da57fc32), without rebasing or retargeting the stack.

The portal namespace/signature, version >= 2 handling and finite RGB range checks match the Settings specification. The exact conversion also produced (128,64,191) for (0.5,0.25,0.75), and rejected out-of-range, NaN and infinity inputs in the controlled probe.

The startup ordering still has a stale-read race. Installing the watch before ReadOne prevents a missed-subscription window, but an older pending ReadOne response can arrive after a newer accent SettingChanged signal. The initializer publishes both unconditionally, so the older snapshot overwrites the newer live value and remains until another signal arrives.

I executed the source initializer, conversion and dispatcher-publication logic with controlled DBus/dispatcher stand-ins: a pending red read followed by a green signal and then the red reply yielded notifications green -> red and a final red palette. A diagnostic generation check when applying the initial snapshot on the dispatcher kept green.

Please prevent the initial snapshot from superseding a newer signal and add a deterministic overlapping-read/signal regression case. Evidence is from exact source with stand-ins, not a live GNOME/KDE session or a new full SamplesApp runtime run.

try
{
var result = await settings.ReadOneAsync(AppearanceNamespace, AccentColorKey).ConfigureAwait(false);
CurrentPalette = ToPalette(result);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Do not let the initial read overwrite a newer accent signal

The watch is already active while this read is pending. If it reports a new green accent and the older ReadOne request then completes with red, both updates are queued and this assignment restores red after green. The UISettings value and theme resources can therefore stay stale until the user changes the accent again, despite the watch-before-read ordering.

The exact initializer/publication logic reproduces green -> red with controlled DBus and dispatcher stand-ins; a version check at dispatcher application time keeps green. Track whether an accent signal superseded the initial snapshot (including changes while its UI callback is queued), and add an overlapping-read/signal test.

@MartinZikmund
MartinZikmund force-pushed the dev/anpi/accentcolor-linux branch from bf3298d to 23bc5ad Compare September 24, 2026 09:46
@MartinZikmund MartinZikmund mentioned this pull request Sep 24, 2026
3 of 5 tasks
@ajpinedam
ajpinedam force-pushed the dev/anpi/accentcolor-linux branch from 23bc5ad to d479e59 Compare October 19, 2026 16:42
@github-actions github-actions Bot added platform/wasm 🌐 Categorizes an issue or PR as relevant to the WebAssembly platform platform/android 🤖 Categorizes an issue or PR as relevant to the Android platform platform/macos 🍏 Categorizes an issue or PR as relevant to the macOS platform platform/ios 🍎 Categorizes an issue or PR as relevant to the iOS platform area/solution-templates Categorizes an issue or PR as relevant to the solution template area/skia ✏️ Categorizes an issue or PR as relevant to Skia area/code-generation Categorizes an issue or PR as relevant to code generation area/build Categorizes an issue or PR as relevant to build infrastructure kind/documentation area/sdk Categorizes an issue or PR as relevant to the Uno.Sdk labels Oct 19, 2026
@MartinZikmund
MartinZikmund force-pushed the dev/anpi/accentcolor-linux branch from d479e59 to 8bb9dbb Compare November 21, 2026 07:32
@MartinZikmund
MartinZikmund merged commit 8bb9dbb into unoplatform:dev/mazi/accentcolor Nov 21, 2026
11 checks passed
@ajpinedam
ajpinedam deleted the dev/anpi/accentcolor-linux branch November 25, 2026 03:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/automation Categorizes an issue or PR as relevant to project automation area/build Categorizes an issue or PR as relevant to build infrastructure area/code-generation Categorizes an issue or PR as relevant to code generation area/sdk Categorizes an issue or PR as relevant to the Uno.Sdk area/skia ✏️ Categorizes an issue or PR as relevant to Skia area/solution-templates Categorizes an issue or PR as relevant to the solution template kind/documentation platform/android 🤖 Categorizes an issue or PR as relevant to the Android platform platform/ios 🍎 Categorizes an issue or PR as relevant to the iOS platform platform/macos 🍏 Categorizes an issue or PR as relevant to the macOS platform platform/wasm 🌐 Categorizes an issue or PR as relevant to the WebAssembly platform platform/x11 🐧 Categorizes an issue or PR as relevant to X11

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants