Skip to content

Fall back when the XDG portal reports an unset accent color - #706

Open
049er wants to merge 4 commits into
material-foundation:mainfrom
049er:fix/linux-unset-accent-color
Open

049er wants to merge 4 commits into
material-foundation:mainfrom
049er:fix/linux-unset-accent-color

Conversation

@049er

@049er 049er commented Nov 6, 2026 •

Copy link
Copy Markdown

Description

Three fixes to getAccentColor on Linux.

The XDG settings portal reports an unset accent color with values outside 0 to 1. getAccentColor converted them anyway, so (-1, -1, -1) became 0xFFFFFF01, almost pure yellow. It now falls back to the GTK theme color when any channel is out of range or not a number.

The portal was read synchronously with the default D-Bus timeout, so a portal that did not answer held the platform thread for 25 seconds. The read is now asynchronous with a 2 second timeout, then falls back to the GTK theme color. A value wrapped in one variant is accepted as well as two.

getAccentColor returns null when neither the portal nor the GTK theme provides a color. It used to return an undefined value when the theme has no theme_selected_bg_color, and logged GTK critical messages when the window closed during a read.

A portal that is already not answering when the app starts is not covered. Flutter's own settings code reads it with no timeout before Dart runs, so the app does not start.

#705 routes its SettingChanged handler through the same conversion, so that path needs the same range check.

Tests

Native code and doc comments only, so no unit test. flutter test passes.

Checked with Flutter 3.44.1 stable against a fake portal on a private session bus, with GTK theme color 0xFFE95420. (-1, -1, -1), (2, 0.5, 0.5) and (NaN, 0, 0) now return the theme color. In-range values and a missing setting are unchanged. A value in one variant returns that value instead of the theme color. A missing setting with a theme that lacks the color returns null instead of 0x00000000.

With the real portal frozen with SIGSTOP, getAccentColor returns the theme color after 2 seconds instead of 25, and a clipboard call made at the same time is answered in 11 ms instead of 25 seconds. The GTK critical messages no longer appear when the window is destroyed during a read.

The Analyze Dart code check already fails on main because of deprecation warnings. This change adds none.

Not tested against a real desktop that reports an unset accent color.

Issues

No linked issue.

Checklist

Contributed by Werner Scholtz, with thanks to KDAB.

Added a range check on the portal's accent-color channels.
Bumped the version to 2.1.1.
@google-cla

google-cla Bot commented Nov 6, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@049er 049er mentioned this pull request Nov 6, 2026
2 tasks done
@049er
049er marked this pull request as ready for review November 6, 2026 06:36
049er added 3 commits November 6, 2026 09:02
Read the accent color asynchronously, with a two second timeout.
Unwrapped the portal value however many variants wrap it.
getAccentColor now returns null when the GTK theme has no accent color or the view is gone.
Updated the plugin's doc comments.

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant