Skip to content

Linux: follow the desktop's light or dark preference through the XDG portal - #40

Merged
thdxr merged 1 commit into
anomalyco:devfrom
salemsayed:linux-portal-appearance
Oct 29, 2026
Merged

thdxr merged 1 commit into
anomalyco:devfrom
salemsayed:linux-portal-appearance

Conversation

@salemsayed

Copy link
Copy Markdown
Contributor

On Linux, winit reports no theme unless the app set one, and layer surfaces have no winit window at all, so window.theme().is_none_or(..) makes every Rune window and overlay draw dark whatever the desktop prefers. Hokum shows it: on Hyprland with a light desktop, its notification cards are light (Hokum reads the portal itself in bus.rs), but the settings window and its preview are dark with Appearance set to System.

What changes

  • portal_appearance.rs (Linux only): a worker thread on a current-thread tokio runtime, like the file-dialog and shortcut portals, reads org.freedesktop.appearance color-scheme from org.freedesktop.portal.Settings (ReadOne, falling back to Read for older portals) and follows SettingChanged. A change asks every window that registered to redraw, as a new accent does on macOS.
  • preferences::window_dark resolves a new window's appearance: --theme, then winit's theme, then the portal, then dark. preferences::desktop_dark is the portal's answer for a window winit gives no theme; RedrawRequested rereads it next to the accent.
  • Overlays read it each time they show (show_fading), and in their winit-window path.
  • The first window waits at most 100 ms for the portal's first answer (sctk-adwaita uses the same timeout for its frame). A later answer redraws the windows.

What stays the same: color-scheme 0 (no preference), no portal or no session bus keep dark. --theme and winit's own theme and ThemeChanged still win. On macOS, Windows and the web, preferences::dark() is None, so nothing there changes.

House rules: window.rs is 4 lines shorter than before (moving the theme match into preferences made room), and its ceiling in file-size-exceptions.txt is lowered to match. overlay.rs stays at its ceiling. The tests are in a sibling portal_appearance_tests.rs, and there is a changelog entry.

Testing

On Arch with Hyprland and xdg-desktop-portal-gtk:

  • Hokum 0.1.2 built against its pinned Rune with this patch applied. With Appearance set to System, the settings window and its preview are light on a light desktop. gsettings set org.gnome.desktop.interface color-scheme prefer-dark turns them dark within a second, with no focus change or click, and prefer-light turns them back. Its notification cards still work.
  • cargo test -p rune --lib portal_appearance: 2 new tests pass.
  • cargo test -p rune --lib: 1105 pass and 5 fail, the same 5 that fail on dev without this change on this machine (edit::tests::hidden_multiline_pristine_replace_and_delete, keycaps::tests::repeated_chords_count_and_named_keys_use_glyphs, runtime::on_key_tests::a_truncation_tooltip_shows_only_while_the_text_is_cut, and two in video::tests). Running the lib tests on Linux also needs the set_native_help test fixed, as Linux: build the native-help test; test presses in a scrolled viewport #32 does; I did that locally for the run, and it isn't part of this PR.
  • cargo check -p rune --lib --target wasm32-unknown-unknown: the new code compiles. The only errors are the existing web_time::Instant mismatches near cursor.reassert_at.
  • Not checked: macOS and Windows builds (no toolchains here). Their path is the same None and no-op that compiles for wasm.

🤖 Generated with Claude Code

…portal

winit reports no theme on Wayland unless the app set one, so every Rune window and
overlay on Linux drew dark whatever the desktop preferred. When winit has nothing,
read org.freedesktop.appearance color-scheme from the settings portal and follow
SettingChanged; a change redraws each window, which rereads it. No preference, no
portal or no session bus keep dark.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@thdxr
thdxr merged commit c1fd012 into anomalyco:dev Oct 29, 2026
thdxr added a commit to anomalyco/hokum that referenced this pull request Oct 29, 2026
Bump Rune to c1fd012, which reads the XDG portal's color-scheme when winit
reports no theme (anomalyco/rune#40 by @salemsayed), and adapt the tray to
Rune's TraySpec/TrayIcon constructors.

Fixes #20
thdxr added a commit to anomalyco/hokum that referenced this pull request Oct 29, 2026
…21)

Bump Rune to c1fd012, which reads the XDG portal's color-scheme when winit
reports no theme (anomalyco/rune#40 by @salemsayed), and adapt the tray to
Rune's TraySpec/TrayIcon constructors.

Fixes #20
@thdxr

thdxr commented Oct 29, 2026

Copy link
Copy Markdown
Member

Thanks a lot for this, really clean fix and a great writeup. Merged into dev as c1fd012, and Hokum now pins it (anomalyco/hokum#21).

— from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊

thdxr added a commit to uncomplexity/hokum that referenced this pull request Oct 29, 2026
…nomalyco#20)

Bump Rune to c1fd012, which reads the XDG portal's color-scheme when winit
reports no theme (anomalyco/rune#40 by @salemsayed). Ported from anomalyco#21.

Fixes anomalyco#20
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